-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BJData optimized binary array type #4513
base: develop
Are you sure you want to change the base?
Conversation
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @nebkat |
Please run |
Introduces a dedicated `B` marker for bytes. This is used as the strong type marker in optimized array format to encode binary data such that it can also be decoded back to binary data (instead of decoding as an integer array). See NeuroJSON/bjdata#6 for further information.
516cf0b
to
d9b1035
Compare
Would it make sense to introduce a |
Thanks a lot! Feels much better without a breaking change! Regarding the draft version - would it make sense to add an int parameter Regarding deprecation - adding a new function to the API just for the sake of deprecating another feels odd. I think we should rather deprecate the default parameter for the mentioned What do you think? |
I like it, didn't think of that, much better solution! So perhaps something like this? /// how to encode BJData
enum class bjdata_version_t
{
draft2 JSON_HEDLEY_DEPRECATED_FOR(3.12.0, draft3),
draft3,
};
...
static std::vector<std::uint8_t> to_bjdata(const basic_json& j,
const bool use_size = false,
const bool use_type = false,
const bjdata_version_t version = bjdata_version_t::draft2)
{
std::vector<std::uint8_t> result;
to_bjdata(j, result, use_size, use_type, version);
return result;
}
// warning: 'nlohmann::json_abi_v3_11_3::detail::bjdata_version_t::draft2' is deprecated: Since 3.12.0; use draft3 [-Wdeprecated-declarations]
// 4315 | const bjdata_version_t version = bjdata_version_t::draft2) Could technically even put |
You mean using BJData as parameter for UBJSON output/input? |
Yes, internally.
// json/include/nlohmann/detail/output/binary_writer.hpp
void write_ubjson(const BasicJsonType& j, const bool use_count,
const bool use_type, const bool add_prefix = true,
- const bool use_bjdata = false)
+ const bjdata_version_t version = bjdata_version_t::ubjson) // or "draft0", which could be argued is equivalent
{ Then we can do:
/// @brief create a UBJSON serialization of a given JSON value
/// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/
static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
const bool use_size = false, const bool use_type = false)
{
- binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
+ binary_writer<std::uint8_t>(o).write_bjdata(j, use_size, use_type, bjdata_version_t::ubjson); // Or defaulted as above
}
/// @brief create a BJData serialization of a given JSON value
/// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/
static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o,
- const bool use_size = false, const bool use_type = false)
+ const bool use_size = false, const bool use_type = false, const bjdata_version_t version = bjdata_version_t::draft2)
{
- binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type, true, true);
+ binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type, true, version);
} Would cut down on the amount of |
Yes, what I meant: would this be something that could - in the long run - be exposed to the customer? As in: deprecating |
Ah right - yes, but if anything I would deprecate |
Well, I thought of BJData to be a dialect of UBJSON, so I don't think replacing the UBJSON with those of BJData is a good idea. |
See NeuroJSON/bjdata#6 for further information.
Introduces a dedicated
B
marker for bytes.This is used as the strong type marker in optimized array format to encode binary data such that it can also be decoded back to binary data (instead of wrongly decoding as an integer array).
Draft while awaiting the release of BJData draft 3.
Would a
legacy_binary
flag be desirable to continue supporting draft 2 expectations of uint8 typed arrays for binary?Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filessingle_include/nlohmann/json.hpp
andsingle_include/nlohmann/json_fwd.hpp
. The whole process is described here.