write some tests

This commit is contained in:
nora 2022-02-14 22:56:07 +01:00
parent 5a99ae4cd2
commit b63b2dee2a
7 changed files with 172 additions and 17 deletions

View file

@ -74,14 +74,17 @@ pub fn timestamp<W: Write>(value: Timestamp, writer: &mut W) -> Result<(), Trans
}
pub fn table<W: Write>(table: Table, writer: &mut W) -> Result<(), TransError> {
let len = u32::try_from(table.len()).context("table too big")?;
writer.write_all(&len.to_be_bytes())?;
let mut table_buf = Vec::new();
for (field_name, value) in table {
shortstr(field_name, writer)?;
field_value(value, writer)?;
shortstr(field_name, &mut table_buf)?;
field_value(value, &mut table_buf)?;
}
let len = u32::try_from(table_buf.len()).context("table too big")?;
writer.write_all(&len.to_be_bytes())?;
writer.write_all(&table_buf)?;
Ok(())
}