Thanks to visit codestin.com
Credit goes to lib.rs

#serialization #macro #generate

tampon

Specialized crate that contains SAFE Rust functions, macros and trait to serialize / deserialize data structure and/or object in packed bytes

7 stable releases

1.2.0 Mar 27, 2026
1.1.4 Feb 18, 2026
1.1.3 Feb 16, 2026
1.1.0 Feb 6, 2026
1.0.0 Jul 16, 2022

#672 in Encoding

MIT license

200KB
709 lines

tampon[^1]

Specialized crate that contains SAFE Rust functions, macros and trait to serialize / deserialize data structure and/or object in packed bytes.

Version

1.2.0

  • Removed optional max_size from [deserialize_size!(...)] since exploit not possible anymore.
  • Modified Trait to remove optional max size.

1.1.4.

  • All macros works without tokens.

1.1.3.

  • Updated [deserialize_size!(...)] to include optional max_size to prevent exploit.
  • Updated [deserialize_size!(...)] and [deserialize!(...)] to accept no tokens.

1.1.0.

  • Refactored faster macro code.
  • Remove Tampon<T> from Trait implementation.
  • Added function deserialize_size() to trait Tampon.
  • Added deserialize_size!(...) to get the real size of a buffer.
  • Added optional argument optional_len_type for maximum array size.
  • Updated rand crate.

1.0.0.

  • Base version

Macros

  1. buffer!(...) -> Vec<u8> - Variadic macro used to create a buffer and serialize compatible variables.
  2. serialize!(...) - Variadic macro used to serialize compatible variables into a buffer.
  3. deserialize!(...) - Variadic macro used to deserialize compatible variables from a buffer.
  4. bytes_size!(...) -> usize - Variadic macro used to get the size in bytes of compatible variables to serialize.
  5. deserialize_size!(...) Variadic macro used to get the size in bytes of compatible variables from buffer that return an error if buffer is too small.

Functions

  1. generate_buffer(...) -> Vec<u8> - Generate a random buffer with specific size and charset.
  2. wipe_buffer(...) - Wipe a sensible buffer to prevent cold boot attack for greater security.
  3. compare_buffer(...) - Compare 2 buffers and return the absolute difference.

Trait

  1. Tampon - Trait used to serialize / deserialize object.

[^1]: Tampon means buffer in french.

Dependencies

~370KB