/// Deserialize statements from binary format.
///
/// TODO: Document the protocol properly somewhere.
Deserialize statements from binary format.
TODO: Document the protocol properly somewhere.
Deserialize statements from binary format . TODO : Document the protocol properly somewhere .
fn parse_statements(
    cursor: &mut Cursor,
    temporaries: &mut Temporaries
) -> Result<Vec<Statement>> {
    let num_statements = cursor.take_u16_le()?;
    let mut statements = Vec::with_capacity(num_statements as usize);
    for _ in 0..num_statements {
        let entity_var = cursor.take_u16_le()?;
        let attribute_len = cursor.take_u16_le()?;
        let attribute = cursor.take_utf8(attribute_len as usize)?;
        let value_type = cursor.take_u8()?;
        let value = match value_type {
            0 => {
                let value_var = cursor.take_u16_le()?;
                QueryValue::Var(Var(value_var))
            }
            1 => {
                let value_u64 = cursor.take_u64_le()?;
                let value = Value::from_u64(value_u64, temporaries);
                QueryValue::Const(value)
            }
            2 => {
                let value_len = cursor.take_u16_le()?;
                let value_str = cursor.take_utf8(value_len as usize)?;
                let value = Value::from_string(value_str, temporaries);
                QueryValue::Const(value)
            }
            _ => unimplemented!("Unsupported value. TODO: Proper error handling."),
        };
        let attribute_name_cid = temporaries.push_string(attribute.to_string());
        let statement = Statement {
            entity: Var(entity_var),
            attribute: QueryAttribute::Named(attribute_name_cid),
            value: value,
        };
        statements.push(statement);
    }
    Ok(statements)
}
fn parse_statements ( cursor : & mut Cursor , temporaries : & mut Temporaries ) -> Result < Vec < Statement > > { let num_statements = cursor . take_u16_le ( ) ? ; let mut statements = Vec :: with_capacity ( num_statements as usize ) ; for _ in 0 .. num_statements { let entity_var = cursor . take_u16_le ( ) ? ; let attribute_len = cursor . take_u16_le ( ) ? ; let attribute = cursor . take_utf8 ( attribute_len as usize ) ? ; let value_type = cursor . take_u8 ( ) ? ; let value = match value_type { 0 => { let value_var = cursor . take_u16_le ( ) ? ; QueryValue :: Var ( Var ( value_var ) ) } 1 => { let value_u64 = cursor . take_u64_le ( ) ? ; let value = Value :: from_u64 ( value_u64 , temporaries ) ; QueryValue :: Const ( value ) } 2 => { let value_len = cursor . take_u16_le ( ) ? ; let value_str = cursor . take_utf8 ( value_len as usize ) ? ; let value = Value :: from_string ( value_str , temporaries ) ; QueryValue :: Const ( value ) } _ => unimplemented ! ( " " ) , } ; let attribute_name_cid = temporaries . push_string ( attribute . to_string ( ) ) ; let statement = Statement { entity : Var ( entity_var ) , attribute : QueryAttribute :: Named ( attribute_name_cid ) , value : value , } ; statements . push ( statement ) ; } Ok ( statements ) }
Deserialize statements from binary format.
Deserialize statements from binary format .
cursor
&mut Cursor
temporaries
&mut Temporaries