0

Is it possible to write a binary chunk, serialized as "(uint32 numbytes) (chunk)" via stream operators, to json via a boost property tree?

To be more specific, lets say the binary chunk is a std::vector of floats, and my iostream serializer parses the number of bytes as an int, followed the actual data.

Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
  • For an discussion of using binary data in JSON, see this question: http://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64 – Dale Wilson Mar 17 '15 at 15:07

1 Answers1

1

Just encode it into a string (e.g. using base64) and store that.

You can automate this for your custom types by specializing boost::property_tree::translator_between.

However, this customization point does /not/ facilitate streaming operation, so it will not be efficient for (very) large vectors.

Consider using a Bson/Json library for the purpose instead.

sehe
  • 374,641
  • 47
  • 450
  • 633