Replies: 3 comments 5 replies
-
|
Hi @hwiesmann, Thank you for your interest in the library. Serializing the underlying quantity value should not be a problem. Just call If you want to serialize a unit or a quantity type, please note that the majority of such libraries on the market require this information to be known at compile-time. This means that you can't dynamically create any quantity with any unit from the stream. So, there is probably no sense in serializing a unit and a quantity type at all. If this was your use case, then you might be interested in #483. Please share your use case there so we will have more motivation for this feature if we try to implement it and then possibly "sell" to the ISO C++ Committee. |
Beta Was this translation helpful? Give feedback.
-
|
Hi,
Sorry, I was a bit confused. Just forget my last message.
… Am 27.12.2024 um 13:09 schrieb Mateusz Pusz ***@***.***>:
I am afraid that I do not follow. A unit is a part of a type. If you know the type you also know a unit. In such a case the only thing you need to serialize is the numerical value of the quantity.
—
Reply to this email directly, view it on GitHub <#661 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAD6V3GAONNWK332REBWX632HU7QXAVCNFSM6AAAAABUF5RTU6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNRXG4YTCNQ>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
|
@hwiesmann I hope you have found your answer since then, but I just wanted to add: As the class vehicle {
mp::quantity<mp::si::metre, float> length;
mp::quantity<mp::si::metre, float> width;
mp::quantity<mp::si::metre / mp::si::second, float> top_speed;
}
static_assert(sizeof(vehicle) == 12);
vehicle v = { ... };
std::span<const std::byte> bytes = std::as_bytes(std::span { &v, 1 });
// Write bytes ... read bytes ... convert back
std::bit_cast<std::array<std::byte, 12>>(v); // Also an optionThis is just a unit-safe annotated version of this, with no overhead! class vehicle {
float length_m;
float width_m;
float top_speed_mps;
}@mpusz I believe the above is well known but I can't actually find a place in the documentation where this is truly emphasized (aside from the comparisons to With the library being so extensive there are a lot of deep technical details to get through in the documentation but I think beginners would benefit hugely from a super simplified page on why If you would be open to it I'd love to contribute a documentation page or a blog post on the topic, perhaps with some first hand application experience. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
What is the recommended way to do quantity serialization?
I have to admit that I am currently not deeply familiar with the library as I am currently evaluating which "units" library to use. One requirement is to easily being able to serialize the quantity using cereal, protobuf or others.
Best regards,
Hardy
Beta Was this translation helpful? Give feedback.
All reactions