Merge pull request #2125 from nlohmann/binary_type
Clean up implementation of binary type
This commit is contained in:
commit
a82c80e9af
75 changed files with 1425 additions and 780 deletions
|
|
@ -27,7 +27,7 @@ template<typename BasicJsonType, typename CharType>
|
|||
class binary_writer
|
||||
{
|
||||
using string_t = typename BasicJsonType::string_t;
|
||||
using internal_binary_t = typename BasicJsonType::internal_binary_t;
|
||||
using binary_t = typename BasicJsonType::binary_t;
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
@ -578,7 +578,7 @@ class binary_writer
|
|||
{
|
||||
// step 0: determine if the binary type has a set subtype to
|
||||
// determine whether or not to use the ext or fixext types
|
||||
const bool use_ext = j.m_value.binary->has_subtype;
|
||||
const bool use_ext = j.m_value.binary->has_subtype();
|
||||
|
||||
// step 1: write control byte and the byte string length
|
||||
const auto N = j.m_value.binary->size();
|
||||
|
|
@ -658,7 +658,7 @@ class binary_writer
|
|||
// step 1.5: if this is an ext type, write the subtype
|
||||
if (use_ext)
|
||||
{
|
||||
write_number(j.m_value.binary->subtype);
|
||||
write_number(static_cast<std::int8_t>(j.m_value.binary->subtype()));
|
||||
}
|
||||
|
||||
// step 2: write the byte string
|
||||
|
|
@ -1080,7 +1080,7 @@ class binary_writer
|
|||
/*!
|
||||
@return The size of the BSON-encoded binary array @a value
|
||||
*/
|
||||
static std::size_t calc_bson_binary_size(const typename BasicJsonType::internal_binary_t& value)
|
||||
static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value)
|
||||
{
|
||||
return sizeof(std::int32_t) + value.size() + 1ul;
|
||||
}
|
||||
|
|
@ -1108,17 +1108,12 @@ class binary_writer
|
|||
@brief Writes a BSON element with key @a name and binary value @a value
|
||||
*/
|
||||
void write_bson_binary(const string_t& name,
|
||||
const internal_binary_t& value)
|
||||
const binary_t& value)
|
||||
{
|
||||
write_bson_entry_header(name, 0x05);
|
||||
|
||||
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
|
||||
std::uint8_t subtype = 0x00; // Generic Binary Subtype
|
||||
if (value.has_subtype)
|
||||
{
|
||||
subtype = value.subtype;
|
||||
}
|
||||
write_number(subtype);
|
||||
write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
|
||||
|
||||
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue