Cannot wrap the buffer to access the messageHeader
Closed this issue · 1 comments
ujos commented
There is following code inside the examples.md
:
auto header = sbepp::make_const_view<>(buf.data(), buf.size());
I cannot make this code to compile. Is there another nice way to read the SBE header?
OleksandrKvl commented
That's a typo in documentation, obviously there's no way to create a header without specifying its type. If you check other usages of make_const_view
on that same page or the make_const_view documentation, you'll see that template parameter is required.
There are couple of ways you can access SBE header:
- Pass hard-coded header type (
messageHeader
in this example) tomake_const_view
:
auto header = sbepp::make_view<your_schema::types::messageHeader>(buf.data(), buf.size());
- Similar to the above but get the header type using
schema_traits
:
auto header = sbepp::make_const_view<sbepp::schema_traits<your_schema::schema>::header_type>(buf.data(), buf.size());
- If you know for sure what schema you're working with and just want to get the header from a message:
// create message somehow
your_schema::messages::msg_1<std::byte> msg;
auto header = sbepp::get_header(msg);
Note that at the moment it's not an error to create a wrong message view from a valid buffer, e.g., if you have a buffer with msg_1
but created msg_2
just to get the header from it.
P.S. Please don't close it even you got the answer, I'll fix that typo and close it afterwards.