diff --git a/Cargo.toml b/Cargo.toml index 8454aac..a0844c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ description = "Serde implementation of OMG Common Data Representation (CDR) enco readme = "README.md" keywords = ["network","protocol","dds","rtps"] license = "Apache-2.0" -homepage = "https://atostek.com/en/products/rustdds/" +homepage = "https://atostek.com/en/products/rustdds/" repository = "https://github.com/jhelovuo/cdr-encoding" [workspace] @@ -19,7 +19,7 @@ members = [ ] -# Although cdr-encoding, cdr-encoding-size, and cdr-encoding-size-derive +# Although cdr-encoding, cdr-encoding-size, and cdr-encoding-size-derive # are relaed semantically, # the main crate cdr-encoding does not technically depend on the two others. # diff --git a/src/cdr_deserializer.rs b/src/cdr_deserializer.rs index d5fb55b..4b6aafa 100644 --- a/src/cdr_deserializer.rs +++ b/src/cdr_deserializer.rs @@ -267,7 +267,15 @@ where where V: Visitor<'de>, { - self.deserialize_seq(visitor) + // Align to 4 bytes + self.calculate_padding_count_from_written_bytes_and_remove(4)?; + // Length prefix + let len = self.next_bytes(4)?.read_u32::().unwrap() as usize; + // Read the entire buffer at once + let buf = self.next_bytes(len)?.to_vec(); + + visitor.visit_byte_buf(buf) + } fn deserialize_option(self, visitor: V) -> Result diff --git a/src/cdr_serializer.rs b/src/cdr_serializer.rs index 0e78038..dd6b8c1 100644 --- a/src/cdr_serializer.rs +++ b/src/cdr_serializer.rs @@ -321,6 +321,9 @@ where } fn serialize_bytes(self, v: &[u8]) -> Result<()> { + // Write length prefix + self.serialize_u32(v.len() as u32)?; + // Write raw bytes self.writer.write_all(v)?; Ok(()) }