#serialization #size #data #dds #helper #key-hash #maximum

cdr-encoding-size

Helper crate for RustDDS: Trait to compute the maximum CDR-serialized size of data

2 releases

0.5.1 Apr 24, 2024
0.5.0 Nov 4, 2021

#1848 in Encoding

Download history 874/week @ 2024-07-21 419/week @ 2024-07-28 785/week @ 2024-08-04 760/week @ 2024-08-11 855/week @ 2024-08-18 1609/week @ 2024-08-25 563/week @ 2024-09-01 1249/week @ 2024-09-08 914/week @ 2024-09-15 923/week @ 2024-09-22 601/week @ 2024-09-29 1395/week @ 2024-10-06 603/week @ 2024-10-13 615/week @ 2024-10-20 629/week @ 2024-10-27 982/week @ 2024-11-03

2,914 downloads per month
Used in 3 crates (2 directly)

Apache-2.0

7KB
88 lines

This crate specifies the CdrEncodingSize trait. It is a helper to the RustDDS library.

The trait is in a separate crate, because it has a derive-macro, and (the Rust Programming Language, Section "19.5 Macros")https://doc.rust-lang.org/book/ch19-06-macros.html advises that "At the time of this writing, procedural macros need to be in their own crate. Eventually, this restriction might be lifted."

The RTPS specification version 2.5 Section "9.6.4.8 KeyHash (PID_KEY_HASH)" defines an algorithm for computing a 16-byte hash of a DDS Key of a data sample.

The algorithm summary:

  • Define a "holder" type corresponding to the data sample type.
  • The holder type consists of all the fields that form the Key of the data sample type.
  • The holder type is serialized according to PLAIN_CDR2 Big Endian rules.
  • If the holder type has maximum serialized size of at most 16 bytes, the serialized representation produced in the previous step, padded with zero bytes to be exactly 16 bytes, is the "key hash".
  • If the holder type has maximum serialized size of more than 16 bytes, then the MD5 hash of the serialized representation above is computed, and this is the "key hash"
  • This always results in a "key hash" of exactly 16 bytes.

This trait is an automated mechanism for deciding if the 16-byte limit is exceeded, i.e. if MD5 hashing should be used or not.

TODO

  • Derive macro supports primitive types and structs, but not enum types. It will fail if a Key type is, or contains, an enum.

Dependencies

~1.5MB
~36K SLoC