3

Is it possible to serialize a string with TLV encoding using boost? Or I should encode first and then just serialize the binary data using boost? If yes then how to encode to TLV?

sehe
  • 374,641
  • 47
  • 450
  • 633
Narek
  • 38,779
  • 79
  • 233
  • 389

1 Answers1

2

Boost's binary serialization archives already use something akin to TLV. The simplest thing to do, clearly, would be to just stick with the default serialization for strings.

However, you can define custom serialization for your custom types.

Using BOOST_STRONG_TYPEDEF you can make a strong "custom" typedef around your TLV string values and this way you can decide how to serialize the strings (e.g. for this situation, it might be enough to serialize the raw data as an array of bytes. You can have a look at boost::serialization::make_array<T>() for a starting point

sehe
  • 374,641
  • 47
  • 450
  • 633