👌 replaced static_cast to CharType by conversion function #1286

This commit is contained in:
Niels Lohmann 2018-10-23 17:49:04 +02:00
parent 9294e25c98
commit b49f76931f
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
3 changed files with 212 additions and 162 deletions

View file

@ -193,13 +193,13 @@ struct is_constructible_object_type_impl <
static constexpr bool value = static constexpr bool value =
std::is_constructible<typename ConstructibleObjectType::key_type, std::is_constructible<typename ConstructibleObjectType::key_type,
typename object_t::key_type>::value and typename object_t::key_type>::value and
std::is_same<typename object_t::mapped_type, (std::is_same<typename object_t::mapped_type,
typename ConstructibleObjectType::mapped_type>::value or typename ConstructibleObjectType::mapped_type>::value or
(has_from_json<BasicJsonType, (has_from_json<BasicJsonType,
typename ConstructibleObjectType::mapped_type>::value or typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json < has_non_default_from_json <
BasicJsonType, BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value); typename ConstructibleObjectType::mapped_type >::value));
}; };
template <typename BasicJsonType, typename ConstructibleObjectType> template <typename BasicJsonType, typename ConstructibleObjectType>

View file

@ -43,15 +43,15 @@ class binary_writer
{ {
case value_t::null: case value_t::null:
{ {
oa->write_character(static_cast<CharType>(0xF6)); oa->write_character(to_char_type(0xF6));
break; break;
} }
case value_t::boolean: case value_t::boolean:
{ {
oa->write_character(j.m_value.boolean oa->write_character(j.m_value.boolean
? static_cast<CharType>(0xF5) ? to_char_type(0xF5)
: static_cast<CharType>(0xF4)); : to_char_type(0xF4));
break; break;
} }
@ -68,22 +68,22 @@ class binary_writer
} }
else if (j.m_value.number_integer <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_integer <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x18)); oa->write_character(to_char_type(0x18));
write_number(static_cast<uint8_t>(j.m_value.number_integer)); write_number(static_cast<uint8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_integer <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x19)); oa->write_character(to_char_type(0x19));
write_number(static_cast<uint16_t>(j.m_value.number_integer)); write_number(static_cast<uint16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_integer <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x1A)); oa->write_character(to_char_type(0x1A));
write_number(static_cast<uint32_t>(j.m_value.number_integer)); write_number(static_cast<uint32_t>(j.m_value.number_integer));
} }
else else
{ {
oa->write_character(static_cast<CharType>(0x1B)); oa->write_character(to_char_type(0x1B));
write_number(static_cast<uint64_t>(j.m_value.number_integer)); write_number(static_cast<uint64_t>(j.m_value.number_integer));
} }
} }
@ -98,22 +98,22 @@ class binary_writer
} }
else if (positive_number <= (std::numeric_limits<uint8_t>::max)()) else if (positive_number <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x38)); oa->write_character(to_char_type(0x38));
write_number(static_cast<uint8_t>(positive_number)); write_number(static_cast<uint8_t>(positive_number));
} }
else if (positive_number <= (std::numeric_limits<uint16_t>::max)()) else if (positive_number <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x39)); oa->write_character(to_char_type(0x39));
write_number(static_cast<uint16_t>(positive_number)); write_number(static_cast<uint16_t>(positive_number));
} }
else if (positive_number <= (std::numeric_limits<uint32_t>::max)()) else if (positive_number <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x3A)); oa->write_character(to_char_type(0x3A));
write_number(static_cast<uint32_t>(positive_number)); write_number(static_cast<uint32_t>(positive_number));
} }
else else
{ {
oa->write_character(static_cast<CharType>(0x3B)); oa->write_character(to_char_type(0x3B));
write_number(static_cast<uint64_t>(positive_number)); write_number(static_cast<uint64_t>(positive_number));
} }
} }
@ -128,22 +128,22 @@ class binary_writer
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x18)); oa->write_character(to_char_type(0x18));
write_number(static_cast<uint8_t>(j.m_value.number_unsigned)); write_number(static_cast<uint8_t>(j.m_value.number_unsigned));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x19)); oa->write_character(to_char_type(0x19));
write_number(static_cast<uint16_t>(j.m_value.number_unsigned)); write_number(static_cast<uint16_t>(j.m_value.number_unsigned));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x1A)); oa->write_character(to_char_type(0x1A));
write_number(static_cast<uint32_t>(j.m_value.number_unsigned)); write_number(static_cast<uint32_t>(j.m_value.number_unsigned));
} }
else else
{ {
oa->write_character(static_cast<CharType>(0x1B)); oa->write_character(to_char_type(0x1B));
write_number(static_cast<uint64_t>(j.m_value.number_unsigned)); write_number(static_cast<uint64_t>(j.m_value.number_unsigned));
} }
break; break;
@ -166,23 +166,23 @@ class binary_writer
} }
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x78)); oa->write_character(to_char_type(0x78));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x79)); oa->write_character(to_char_type(0x79));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x7A)); oa->write_character(to_char_type(0x7A));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else if (N <= (std::numeric_limits<uint64_t>::max)()) else if (N <= (std::numeric_limits<uint64_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x7B)); oa->write_character(to_char_type(0x7B));
write_number(static_cast<uint64_t>(N)); write_number(static_cast<uint64_t>(N));
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
@ -204,23 +204,23 @@ class binary_writer
} }
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x98)); oa->write_character(to_char_type(0x98));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x99)); oa->write_character(to_char_type(0x99));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x9A)); oa->write_character(to_char_type(0x9A));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else if (N <= (std::numeric_limits<uint64_t>::max)()) else if (N <= (std::numeric_limits<uint64_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x9B)); oa->write_character(to_char_type(0x9B));
write_number(static_cast<uint64_t>(N)); write_number(static_cast<uint64_t>(N));
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
@ -243,23 +243,23 @@ class binary_writer
} }
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xB8)); oa->write_character(to_char_type(0xB8));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xB9)); oa->write_character(to_char_type(0xB9));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xBA)); oa->write_character(to_char_type(0xBA));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else if (N <= (std::numeric_limits<uint64_t>::max)()) else if (N <= (std::numeric_limits<uint64_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xBB)); oa->write_character(to_char_type(0xBB));
write_number(static_cast<uint64_t>(N)); write_number(static_cast<uint64_t>(N));
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
@ -287,15 +287,15 @@ class binary_writer
{ {
case value_t::null: // nil case value_t::null: // nil
{ {
oa->write_character(static_cast<CharType>(0xC0)); oa->write_character(to_char_type(0xC0));
break; break;
} }
case value_t::boolean: // true and false case value_t::boolean: // true and false
{ {
oa->write_character(j.m_value.boolean oa->write_character(j.m_value.boolean
? static_cast<CharType>(0xC3) ? to_char_type(0xC3)
: static_cast<CharType>(0xC2)); : to_char_type(0xC2));
break; break;
} }
@ -314,25 +314,25 @@ class binary_writer
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
{ {
// uint 8 // uint 8
oa->write_character(static_cast<CharType>(0xCC)); oa->write_character(to_char_type(0xCC));
write_number(static_cast<uint8_t>(j.m_value.number_integer)); write_number(static_cast<uint8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)())
{ {
// uint 16 // uint 16
oa->write_character(static_cast<CharType>(0xCD)); oa->write_character(to_char_type(0xCD));
write_number(static_cast<uint16_t>(j.m_value.number_integer)); write_number(static_cast<uint16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)())
{ {
// uint 32 // uint 32
oa->write_character(static_cast<CharType>(0xCE)); oa->write_character(to_char_type(0xCE));
write_number(static_cast<uint32_t>(j.m_value.number_integer)); write_number(static_cast<uint32_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)())
{ {
// uint 64 // uint 64
oa->write_character(static_cast<CharType>(0xCF)); oa->write_character(to_char_type(0xCF));
write_number(static_cast<uint64_t>(j.m_value.number_integer)); write_number(static_cast<uint64_t>(j.m_value.number_integer));
} }
} }
@ -347,28 +347,28 @@ class binary_writer
j.m_value.number_integer <= (std::numeric_limits<int8_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int8_t>::max)())
{ {
// int 8 // int 8
oa->write_character(static_cast<CharType>(0xD0)); oa->write_character(to_char_type(0xD0));
write_number(static_cast<int8_t>(j.m_value.number_integer)); write_number(static_cast<int8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer >= (std::numeric_limits<int16_t>::min)() and else if (j.m_value.number_integer >= (std::numeric_limits<int16_t>::min)() and
j.m_value.number_integer <= (std::numeric_limits<int16_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int16_t>::max)())
{ {
// int 16 // int 16
oa->write_character(static_cast<CharType>(0xD1)); oa->write_character(to_char_type(0xD1));
write_number(static_cast<int16_t>(j.m_value.number_integer)); write_number(static_cast<int16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer >= (std::numeric_limits<int32_t>::min)() and else if (j.m_value.number_integer >= (std::numeric_limits<int32_t>::min)() and
j.m_value.number_integer <= (std::numeric_limits<int32_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int32_t>::max)())
{ {
// int 32 // int 32
oa->write_character(static_cast<CharType>(0xD2)); oa->write_character(to_char_type(0xD2));
write_number(static_cast<int32_t>(j.m_value.number_integer)); write_number(static_cast<int32_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer >= (std::numeric_limits<int64_t>::min)() and else if (j.m_value.number_integer >= (std::numeric_limits<int64_t>::min)() and
j.m_value.number_integer <= (std::numeric_limits<int64_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int64_t>::max)())
{ {
// int 64 // int 64
oa->write_character(static_cast<CharType>(0xD3)); oa->write_character(to_char_type(0xD3));
write_number(static_cast<int64_t>(j.m_value.number_integer)); write_number(static_cast<int64_t>(j.m_value.number_integer));
} }
} }
@ -385,25 +385,25 @@ class binary_writer
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
{ {
// uint 8 // uint 8
oa->write_character(static_cast<CharType>(0xCC)); oa->write_character(to_char_type(0xCC));
write_number(static_cast<uint8_t>(j.m_value.number_integer)); write_number(static_cast<uint8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)())
{ {
// uint 16 // uint 16
oa->write_character(static_cast<CharType>(0xCD)); oa->write_character(to_char_type(0xCD));
write_number(static_cast<uint16_t>(j.m_value.number_integer)); write_number(static_cast<uint16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)())
{ {
// uint 32 // uint 32
oa->write_character(static_cast<CharType>(0xCE)); oa->write_character(to_char_type(0xCE));
write_number(static_cast<uint32_t>(j.m_value.number_integer)); write_number(static_cast<uint32_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)())
{ {
// uint 64 // uint 64
oa->write_character(static_cast<CharType>(0xCF)); oa->write_character(to_char_type(0xCF));
write_number(static_cast<uint64_t>(j.m_value.number_integer)); write_number(static_cast<uint64_t>(j.m_value.number_integer));
} }
break; break;
@ -428,19 +428,19 @@ class binary_writer
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
// str 8 // str 8
oa->write_character(static_cast<CharType>(0xD9)); oa->write_character(to_char_type(0xD9));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
// str 16 // str 16
oa->write_character(static_cast<CharType>(0xDA)); oa->write_character(to_char_type(0xDA));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
// str 32 // str 32
oa->write_character(static_cast<CharType>(0xDB)); oa->write_character(to_char_type(0xDB));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
@ -463,13 +463,13 @@ class binary_writer
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
// array 16 // array 16
oa->write_character(static_cast<CharType>(0xDC)); oa->write_character(to_char_type(0xDC));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
// array 32 // array 32
oa->write_character(static_cast<CharType>(0xDD)); oa->write_character(to_char_type(0xDD));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
@ -493,13 +493,13 @@ class binary_writer
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
// map 16 // map 16
oa->write_character(static_cast<CharType>(0xDE)); oa->write_character(to_char_type(0xDE));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
// map 32 // map 32
oa->write_character(static_cast<CharType>(0xDF)); oa->write_character(to_char_type(0xDF));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
@ -532,7 +532,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('Z')); oa->write_character(to_char_type('Z'));
} }
break; break;
} }
@ -542,8 +542,8 @@ class binary_writer
if (add_prefix) if (add_prefix)
{ {
oa->write_character(j.m_value.boolean oa->write_character(j.m_value.boolean
? static_cast<CharType>('T') ? to_char_type('T')
: static_cast<CharType>('F')); : to_char_type('F'));
} }
break; break;
} }
@ -570,7 +570,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('S')); oa->write_character(to_char_type('S'));
} }
write_number_with_ubjson_prefix(j.m_value.string->size(), true); write_number_with_ubjson_prefix(j.m_value.string->size(), true);
oa->write_characters( oa->write_characters(
@ -583,7 +583,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('[')); oa->write_character(to_char_type('['));
} }
bool prefix_required = true; bool prefix_required = true;
@ -600,14 +600,14 @@ class binary_writer
if (same_prefix) if (same_prefix)
{ {
prefix_required = false; prefix_required = false;
oa->write_character(static_cast<CharType>('$')); oa->write_character(to_char_type('$'));
oa->write_character(first_prefix); oa->write_character(first_prefix);
} }
} }
if (use_count) if (use_count)
{ {
oa->write_character(static_cast<CharType>('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.array->size(), true); write_number_with_ubjson_prefix(j.m_value.array->size(), true);
} }
@ -618,7 +618,7 @@ class binary_writer
if (not use_count) if (not use_count)
{ {
oa->write_character(static_cast<CharType>(']')); oa->write_character(to_char_type(']'));
} }
break; break;
@ -628,7 +628,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('{')); oa->write_character(to_char_type('{'));
} }
bool prefix_required = true; bool prefix_required = true;
@ -645,14 +645,14 @@ class binary_writer
if (same_prefix) if (same_prefix)
{ {
prefix_required = false; prefix_required = false;
oa->write_character(static_cast<CharType>('$')); oa->write_character(to_char_type('$'));
oa->write_character(first_prefix); oa->write_character(first_prefix);
} }
} }
if (use_count) if (use_count)
{ {
oa->write_character(static_cast<CharType>('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.object->size(), true); write_number_with_ubjson_prefix(j.m_value.object->size(), true);
} }
@ -667,7 +667,7 @@ class binary_writer
if (not use_count) if (not use_count)
{ {
oa->write_character(static_cast<CharType>('}')); oa->write_character(to_char_type('}'));
} }
break; break;
@ -729,7 +729,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('i')); // int8 oa->write_character(to_char_type('i')); // int8
} }
write_number(static_cast<uint8_t>(n)); write_number(static_cast<uint8_t>(n));
} }
@ -737,7 +737,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('U')); // uint8 oa->write_character(to_char_type('U')); // uint8
} }
write_number(static_cast<uint8_t>(n)); write_number(static_cast<uint8_t>(n));
} }
@ -745,7 +745,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('I')); // int16 oa->write_character(to_char_type('I')); // int16
} }
write_number(static_cast<int16_t>(n)); write_number(static_cast<int16_t>(n));
} }
@ -753,7 +753,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('l')); // int32 oa->write_character(to_char_type('l')); // int32
} }
write_number(static_cast<int32_t>(n)); write_number(static_cast<int32_t>(n));
} }
@ -761,7 +761,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('L')); // int64 oa->write_character(to_char_type('L')); // int64
} }
write_number(static_cast<int64_t>(n)); write_number(static_cast<int64_t>(n));
} }
@ -782,7 +782,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('i')); // int8 oa->write_character(to_char_type('i')); // int8
} }
write_number(static_cast<int8_t>(n)); write_number(static_cast<int8_t>(n));
} }
@ -790,7 +790,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('U')); // uint8 oa->write_character(to_char_type('U')); // uint8
} }
write_number(static_cast<uint8_t>(n)); write_number(static_cast<uint8_t>(n));
} }
@ -798,7 +798,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('I')); // int16 oa->write_character(to_char_type('I')); // int16
} }
write_number(static_cast<int16_t>(n)); write_number(static_cast<int16_t>(n));
} }
@ -806,7 +806,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('l')); // int32 oa->write_character(to_char_type('l')); // int32
} }
write_number(static_cast<int32_t>(n)); write_number(static_cast<int32_t>(n));
} }
@ -814,7 +814,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('L')); // int64 oa->write_character(to_char_type('L')); // int64
} }
write_number(static_cast<int64_t>(n)); write_number(static_cast<int64_t>(n));
} }
@ -908,22 +908,22 @@ class binary_writer
static constexpr CharType get_cbor_float_prefix(float /*unused*/) static constexpr CharType get_cbor_float_prefix(float /*unused*/)
{ {
return static_cast<CharType>(0xFA); // Single-Precision Float return to_char_type(0xFA); // Single-Precision Float
} }
static constexpr CharType get_cbor_float_prefix(double /*unused*/) static constexpr CharType get_cbor_float_prefix(double /*unused*/)
{ {
return static_cast<CharType>(0xFB); // Double-Precision Float return to_char_type(0xFB); // Double-Precision Float
} }
static constexpr CharType get_msgpack_float_prefix(float /*unused*/) static constexpr CharType get_msgpack_float_prefix(float /*unused*/)
{ {
return static_cast<CharType>(0xCA); // float 32 return to_char_type(0xCA); // float 32
} }
static constexpr CharType get_msgpack_float_prefix(double /*unused*/) static constexpr CharType get_msgpack_float_prefix(double /*unused*/)
{ {
return static_cast<CharType>(0xCB); // float 64 return to_char_type(0xCB); // float 64
} }
static constexpr CharType get_ubjson_float_prefix(float /*unused*/) static constexpr CharType get_ubjson_float_prefix(float /*unused*/)
@ -936,6 +936,31 @@ class binary_writer
return 'D'; // float 64 return 'D'; // float 64
} }
template < typename C = CharType,
enable_if_t < std::is_signed<C>::value and std::is_signed<char>::value > * = nullptr >
static constexpr CharType to_char_type(std::uint8_t x) noexcept
{
return *reinterpret_cast<char*>(&x);
}
template < typename C = CharType,
enable_if_t < std::is_signed<C>::value and std::is_unsigned<char>::value > * = nullptr >
static CharType to_char_type(std::uint8_t x) noexcept
{
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
static_assert(std::is_pod<CharType>::value, "CharType must be POD");
CharType result;
std::memcpy(&result, &x, sizeof(x));
return result;
}
template<typename C = CharType,
enable_if_t<std::is_unsigned<C>::value>* = nullptr>
static constexpr CharType to_char_type(std::uint8_t x) noexcept
{
return x;
}
private: private:
/// whether we can assume little endianess /// whether we can assume little endianess
const bool is_little_endian = binary_reader<BasicJsonType>::little_endianess(); const bool is_little_endian = binary_reader<BasicJsonType>::little_endianess();

View file

@ -553,13 +553,13 @@ struct is_constructible_object_type_impl <
static constexpr bool value = static constexpr bool value =
std::is_constructible<typename ConstructibleObjectType::key_type, std::is_constructible<typename ConstructibleObjectType::key_type,
typename object_t::key_type>::value and typename object_t::key_type>::value and
std::is_same<typename object_t::mapped_type, (std::is_same<typename object_t::mapped_type,
typename ConstructibleObjectType::mapped_type>::value or typename ConstructibleObjectType::mapped_type>::value or
(has_from_json<BasicJsonType, (has_from_json<BasicJsonType,
typename ConstructibleObjectType::mapped_type>::value or typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json < has_non_default_from_json <
BasicJsonType, BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value); typename ConstructibleObjectType::mapped_type >::value));
}; };
template <typename BasicJsonType, typename ConstructibleObjectType> template <typename BasicJsonType, typename ConstructibleObjectType>
@ -8088,15 +8088,15 @@ class binary_writer
{ {
case value_t::null: case value_t::null:
{ {
oa->write_character(static_cast<CharType>(0xF6)); oa->write_character(to_char_type(0xF6));
break; break;
} }
case value_t::boolean: case value_t::boolean:
{ {
oa->write_character(j.m_value.boolean oa->write_character(j.m_value.boolean
? static_cast<CharType>(0xF5) ? to_char_type(0xF5)
: static_cast<CharType>(0xF4)); : to_char_type(0xF4));
break; break;
} }
@ -8113,22 +8113,22 @@ class binary_writer
} }
else if (j.m_value.number_integer <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_integer <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x18)); oa->write_character(to_char_type(0x18));
write_number(static_cast<uint8_t>(j.m_value.number_integer)); write_number(static_cast<uint8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_integer <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x19)); oa->write_character(to_char_type(0x19));
write_number(static_cast<uint16_t>(j.m_value.number_integer)); write_number(static_cast<uint16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_integer <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x1A)); oa->write_character(to_char_type(0x1A));
write_number(static_cast<uint32_t>(j.m_value.number_integer)); write_number(static_cast<uint32_t>(j.m_value.number_integer));
} }
else else
{ {
oa->write_character(static_cast<CharType>(0x1B)); oa->write_character(to_char_type(0x1B));
write_number(static_cast<uint64_t>(j.m_value.number_integer)); write_number(static_cast<uint64_t>(j.m_value.number_integer));
} }
} }
@ -8143,22 +8143,22 @@ class binary_writer
} }
else if (positive_number <= (std::numeric_limits<uint8_t>::max)()) else if (positive_number <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x38)); oa->write_character(to_char_type(0x38));
write_number(static_cast<uint8_t>(positive_number)); write_number(static_cast<uint8_t>(positive_number));
} }
else if (positive_number <= (std::numeric_limits<uint16_t>::max)()) else if (positive_number <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x39)); oa->write_character(to_char_type(0x39));
write_number(static_cast<uint16_t>(positive_number)); write_number(static_cast<uint16_t>(positive_number));
} }
else if (positive_number <= (std::numeric_limits<uint32_t>::max)()) else if (positive_number <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x3A)); oa->write_character(to_char_type(0x3A));
write_number(static_cast<uint32_t>(positive_number)); write_number(static_cast<uint32_t>(positive_number));
} }
else else
{ {
oa->write_character(static_cast<CharType>(0x3B)); oa->write_character(to_char_type(0x3B));
write_number(static_cast<uint64_t>(positive_number)); write_number(static_cast<uint64_t>(positive_number));
} }
} }
@ -8173,22 +8173,22 @@ class binary_writer
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x18)); oa->write_character(to_char_type(0x18));
write_number(static_cast<uint8_t>(j.m_value.number_unsigned)); write_number(static_cast<uint8_t>(j.m_value.number_unsigned));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x19)); oa->write_character(to_char_type(0x19));
write_number(static_cast<uint16_t>(j.m_value.number_unsigned)); write_number(static_cast<uint16_t>(j.m_value.number_unsigned));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x1A)); oa->write_character(to_char_type(0x1A));
write_number(static_cast<uint32_t>(j.m_value.number_unsigned)); write_number(static_cast<uint32_t>(j.m_value.number_unsigned));
} }
else else
{ {
oa->write_character(static_cast<CharType>(0x1B)); oa->write_character(to_char_type(0x1B));
write_number(static_cast<uint64_t>(j.m_value.number_unsigned)); write_number(static_cast<uint64_t>(j.m_value.number_unsigned));
} }
break; break;
@ -8211,23 +8211,23 @@ class binary_writer
} }
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x78)); oa->write_character(to_char_type(0x78));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x79)); oa->write_character(to_char_type(0x79));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x7A)); oa->write_character(to_char_type(0x7A));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else if (N <= (std::numeric_limits<uint64_t>::max)()) else if (N <= (std::numeric_limits<uint64_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x7B)); oa->write_character(to_char_type(0x7B));
write_number(static_cast<uint64_t>(N)); write_number(static_cast<uint64_t>(N));
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
@ -8249,23 +8249,23 @@ class binary_writer
} }
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x98)); oa->write_character(to_char_type(0x98));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x99)); oa->write_character(to_char_type(0x99));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x9A)); oa->write_character(to_char_type(0x9A));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else if (N <= (std::numeric_limits<uint64_t>::max)()) else if (N <= (std::numeric_limits<uint64_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0x9B)); oa->write_character(to_char_type(0x9B));
write_number(static_cast<uint64_t>(N)); write_number(static_cast<uint64_t>(N));
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
@ -8288,23 +8288,23 @@ class binary_writer
} }
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xB8)); oa->write_character(to_char_type(0xB8));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xB9)); oa->write_character(to_char_type(0xB9));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xBA)); oa->write_character(to_char_type(0xBA));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
// LCOV_EXCL_START // LCOV_EXCL_START
else if (N <= (std::numeric_limits<uint64_t>::max)()) else if (N <= (std::numeric_limits<uint64_t>::max)())
{ {
oa->write_character(static_cast<CharType>(0xBB)); oa->write_character(to_char_type(0xBB));
write_number(static_cast<uint64_t>(N)); write_number(static_cast<uint64_t>(N));
} }
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
@ -8332,15 +8332,15 @@ class binary_writer
{ {
case value_t::null: // nil case value_t::null: // nil
{ {
oa->write_character(static_cast<CharType>(0xC0)); oa->write_character(to_char_type(0xC0));
break; break;
} }
case value_t::boolean: // true and false case value_t::boolean: // true and false
{ {
oa->write_character(j.m_value.boolean oa->write_character(j.m_value.boolean
? static_cast<CharType>(0xC3) ? to_char_type(0xC3)
: static_cast<CharType>(0xC2)); : to_char_type(0xC2));
break; break;
} }
@ -8359,25 +8359,25 @@ class binary_writer
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
{ {
// uint 8 // uint 8
oa->write_character(static_cast<CharType>(0xCC)); oa->write_character(to_char_type(0xCC));
write_number(static_cast<uint8_t>(j.m_value.number_integer)); write_number(static_cast<uint8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)())
{ {
// uint 16 // uint 16
oa->write_character(static_cast<CharType>(0xCD)); oa->write_character(to_char_type(0xCD));
write_number(static_cast<uint16_t>(j.m_value.number_integer)); write_number(static_cast<uint16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)())
{ {
// uint 32 // uint 32
oa->write_character(static_cast<CharType>(0xCE)); oa->write_character(to_char_type(0xCE));
write_number(static_cast<uint32_t>(j.m_value.number_integer)); write_number(static_cast<uint32_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)())
{ {
// uint 64 // uint 64
oa->write_character(static_cast<CharType>(0xCF)); oa->write_character(to_char_type(0xCF));
write_number(static_cast<uint64_t>(j.m_value.number_integer)); write_number(static_cast<uint64_t>(j.m_value.number_integer));
} }
} }
@ -8392,28 +8392,28 @@ class binary_writer
j.m_value.number_integer <= (std::numeric_limits<int8_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int8_t>::max)())
{ {
// int 8 // int 8
oa->write_character(static_cast<CharType>(0xD0)); oa->write_character(to_char_type(0xD0));
write_number(static_cast<int8_t>(j.m_value.number_integer)); write_number(static_cast<int8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer >= (std::numeric_limits<int16_t>::min)() and else if (j.m_value.number_integer >= (std::numeric_limits<int16_t>::min)() and
j.m_value.number_integer <= (std::numeric_limits<int16_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int16_t>::max)())
{ {
// int 16 // int 16
oa->write_character(static_cast<CharType>(0xD1)); oa->write_character(to_char_type(0xD1));
write_number(static_cast<int16_t>(j.m_value.number_integer)); write_number(static_cast<int16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer >= (std::numeric_limits<int32_t>::min)() and else if (j.m_value.number_integer >= (std::numeric_limits<int32_t>::min)() and
j.m_value.number_integer <= (std::numeric_limits<int32_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int32_t>::max)())
{ {
// int 32 // int 32
oa->write_character(static_cast<CharType>(0xD2)); oa->write_character(to_char_type(0xD2));
write_number(static_cast<int32_t>(j.m_value.number_integer)); write_number(static_cast<int32_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_integer >= (std::numeric_limits<int64_t>::min)() and else if (j.m_value.number_integer >= (std::numeric_limits<int64_t>::min)() and
j.m_value.number_integer <= (std::numeric_limits<int64_t>::max)()) j.m_value.number_integer <= (std::numeric_limits<int64_t>::max)())
{ {
// int 64 // int 64
oa->write_character(static_cast<CharType>(0xD3)); oa->write_character(to_char_type(0xD3));
write_number(static_cast<int64_t>(j.m_value.number_integer)); write_number(static_cast<int64_t>(j.m_value.number_integer));
} }
} }
@ -8430,25 +8430,25 @@ class binary_writer
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
{ {
// uint 8 // uint 8
oa->write_character(static_cast<CharType>(0xCC)); oa->write_character(to_char_type(0xCC));
write_number(static_cast<uint8_t>(j.m_value.number_integer)); write_number(static_cast<uint8_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint16_t>::max)())
{ {
// uint 16 // uint 16
oa->write_character(static_cast<CharType>(0xCD)); oa->write_character(to_char_type(0xCD));
write_number(static_cast<uint16_t>(j.m_value.number_integer)); write_number(static_cast<uint16_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint32_t>::max)())
{ {
// uint 32 // uint 32
oa->write_character(static_cast<CharType>(0xCE)); oa->write_character(to_char_type(0xCE));
write_number(static_cast<uint32_t>(j.m_value.number_integer)); write_number(static_cast<uint32_t>(j.m_value.number_integer));
} }
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)()) else if (j.m_value.number_unsigned <= (std::numeric_limits<uint64_t>::max)())
{ {
// uint 64 // uint 64
oa->write_character(static_cast<CharType>(0xCF)); oa->write_character(to_char_type(0xCF));
write_number(static_cast<uint64_t>(j.m_value.number_integer)); write_number(static_cast<uint64_t>(j.m_value.number_integer));
} }
break; break;
@ -8473,19 +8473,19 @@ class binary_writer
else if (N <= (std::numeric_limits<uint8_t>::max)()) else if (N <= (std::numeric_limits<uint8_t>::max)())
{ {
// str 8 // str 8
oa->write_character(static_cast<CharType>(0xD9)); oa->write_character(to_char_type(0xD9));
write_number(static_cast<uint8_t>(N)); write_number(static_cast<uint8_t>(N));
} }
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
// str 16 // str 16
oa->write_character(static_cast<CharType>(0xDA)); oa->write_character(to_char_type(0xDA));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
// str 32 // str 32
oa->write_character(static_cast<CharType>(0xDB)); oa->write_character(to_char_type(0xDB));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
@ -8508,13 +8508,13 @@ class binary_writer
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
// array 16 // array 16
oa->write_character(static_cast<CharType>(0xDC)); oa->write_character(to_char_type(0xDC));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
// array 32 // array 32
oa->write_character(static_cast<CharType>(0xDD)); oa->write_character(to_char_type(0xDD));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
@ -8538,13 +8538,13 @@ class binary_writer
else if (N <= (std::numeric_limits<uint16_t>::max)()) else if (N <= (std::numeric_limits<uint16_t>::max)())
{ {
// map 16 // map 16
oa->write_character(static_cast<CharType>(0xDE)); oa->write_character(to_char_type(0xDE));
write_number(static_cast<uint16_t>(N)); write_number(static_cast<uint16_t>(N));
} }
else if (N <= (std::numeric_limits<uint32_t>::max)()) else if (N <= (std::numeric_limits<uint32_t>::max)())
{ {
// map 32 // map 32
oa->write_character(static_cast<CharType>(0xDF)); oa->write_character(to_char_type(0xDF));
write_number(static_cast<uint32_t>(N)); write_number(static_cast<uint32_t>(N));
} }
@ -8577,7 +8577,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('Z')); oa->write_character(to_char_type('Z'));
} }
break; break;
} }
@ -8587,8 +8587,8 @@ class binary_writer
if (add_prefix) if (add_prefix)
{ {
oa->write_character(j.m_value.boolean oa->write_character(j.m_value.boolean
? static_cast<CharType>('T') ? to_char_type('T')
: static_cast<CharType>('F')); : to_char_type('F'));
} }
break; break;
} }
@ -8615,7 +8615,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('S')); oa->write_character(to_char_type('S'));
} }
write_number_with_ubjson_prefix(j.m_value.string->size(), true); write_number_with_ubjson_prefix(j.m_value.string->size(), true);
oa->write_characters( oa->write_characters(
@ -8628,7 +8628,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('[')); oa->write_character(to_char_type('['));
} }
bool prefix_required = true; bool prefix_required = true;
@ -8645,14 +8645,14 @@ class binary_writer
if (same_prefix) if (same_prefix)
{ {
prefix_required = false; prefix_required = false;
oa->write_character(static_cast<CharType>('$')); oa->write_character(to_char_type('$'));
oa->write_character(first_prefix); oa->write_character(first_prefix);
} }
} }
if (use_count) if (use_count)
{ {
oa->write_character(static_cast<CharType>('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.array->size(), true); write_number_with_ubjson_prefix(j.m_value.array->size(), true);
} }
@ -8663,7 +8663,7 @@ class binary_writer
if (not use_count) if (not use_count)
{ {
oa->write_character(static_cast<CharType>(']')); oa->write_character(to_char_type(']'));
} }
break; break;
@ -8673,7 +8673,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('{')); oa->write_character(to_char_type('{'));
} }
bool prefix_required = true; bool prefix_required = true;
@ -8690,14 +8690,14 @@ class binary_writer
if (same_prefix) if (same_prefix)
{ {
prefix_required = false; prefix_required = false;
oa->write_character(static_cast<CharType>('$')); oa->write_character(to_char_type('$'));
oa->write_character(first_prefix); oa->write_character(first_prefix);
} }
} }
if (use_count) if (use_count)
{ {
oa->write_character(static_cast<CharType>('#')); oa->write_character(to_char_type('#'));
write_number_with_ubjson_prefix(j.m_value.object->size(), true); write_number_with_ubjson_prefix(j.m_value.object->size(), true);
} }
@ -8712,7 +8712,7 @@ class binary_writer
if (not use_count) if (not use_count)
{ {
oa->write_character(static_cast<CharType>('}')); oa->write_character(to_char_type('}'));
} }
break; break;
@ -8774,7 +8774,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('i')); // int8 oa->write_character(to_char_type('i')); // int8
} }
write_number(static_cast<uint8_t>(n)); write_number(static_cast<uint8_t>(n));
} }
@ -8782,7 +8782,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('U')); // uint8 oa->write_character(to_char_type('U')); // uint8
} }
write_number(static_cast<uint8_t>(n)); write_number(static_cast<uint8_t>(n));
} }
@ -8790,7 +8790,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('I')); // int16 oa->write_character(to_char_type('I')); // int16
} }
write_number(static_cast<int16_t>(n)); write_number(static_cast<int16_t>(n));
} }
@ -8798,7 +8798,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('l')); // int32 oa->write_character(to_char_type('l')); // int32
} }
write_number(static_cast<int32_t>(n)); write_number(static_cast<int32_t>(n));
} }
@ -8806,7 +8806,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('L')); // int64 oa->write_character(to_char_type('L')); // int64
} }
write_number(static_cast<int64_t>(n)); write_number(static_cast<int64_t>(n));
} }
@ -8827,7 +8827,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('i')); // int8 oa->write_character(to_char_type('i')); // int8
} }
write_number(static_cast<int8_t>(n)); write_number(static_cast<int8_t>(n));
} }
@ -8835,7 +8835,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('U')); // uint8 oa->write_character(to_char_type('U')); // uint8
} }
write_number(static_cast<uint8_t>(n)); write_number(static_cast<uint8_t>(n));
} }
@ -8843,7 +8843,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('I')); // int16 oa->write_character(to_char_type('I')); // int16
} }
write_number(static_cast<int16_t>(n)); write_number(static_cast<int16_t>(n));
} }
@ -8851,7 +8851,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('l')); // int32 oa->write_character(to_char_type('l')); // int32
} }
write_number(static_cast<int32_t>(n)); write_number(static_cast<int32_t>(n));
} }
@ -8859,7 +8859,7 @@ class binary_writer
{ {
if (add_prefix) if (add_prefix)
{ {
oa->write_character(static_cast<CharType>('L')); // int64 oa->write_character(to_char_type('L')); // int64
} }
write_number(static_cast<int64_t>(n)); write_number(static_cast<int64_t>(n));
} }
@ -8953,22 +8953,22 @@ class binary_writer
static constexpr CharType get_cbor_float_prefix(float /*unused*/) static constexpr CharType get_cbor_float_prefix(float /*unused*/)
{ {
return static_cast<CharType>(0xFA); // Single-Precision Float return to_char_type(0xFA); // Single-Precision Float
} }
static constexpr CharType get_cbor_float_prefix(double /*unused*/) static constexpr CharType get_cbor_float_prefix(double /*unused*/)
{ {
return static_cast<CharType>(0xFB); // Double-Precision Float return to_char_type(0xFB); // Double-Precision Float
} }
static constexpr CharType get_msgpack_float_prefix(float /*unused*/) static constexpr CharType get_msgpack_float_prefix(float /*unused*/)
{ {
return static_cast<CharType>(0xCA); // float 32 return to_char_type(0xCA); // float 32
} }
static constexpr CharType get_msgpack_float_prefix(double /*unused*/) static constexpr CharType get_msgpack_float_prefix(double /*unused*/)
{ {
return static_cast<CharType>(0xCB); // float 64 return to_char_type(0xCB); // float 64
} }
static constexpr CharType get_ubjson_float_prefix(float /*unused*/) static constexpr CharType get_ubjson_float_prefix(float /*unused*/)
@ -8981,6 +8981,31 @@ class binary_writer
return 'D'; // float 64 return 'D'; // float 64
} }
template < typename C = CharType,
enable_if_t < std::is_signed<C>::value and std::is_signed<char>::value > * = nullptr >
static constexpr CharType to_char_type(std::uint8_t x) noexcept
{
return *reinterpret_cast<char*>(&x);
}
template < typename C = CharType,
enable_if_t < std::is_signed<C>::value and std::is_unsigned<char>::value > * = nullptr >
static CharType to_char_type(std::uint8_t x) noexcept
{
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
static_assert(std::is_pod<CharType>::value, "CharType must be POD");
CharType result;
std::memcpy(&result, &x, sizeof(x));
return result;
}
template<typename C = CharType,
enable_if_t<std::is_unsigned<C>::value>* = nullptr>
static constexpr CharType to_char_type(std::uint8_t x) noexcept
{
return x;
}
private: private:
/// whether we can assume little endianess /// whether we can assume little endianess
const bool is_little_endian = binary_reader<BasicJsonType>::little_endianess(); const bool is_little_endian = binary_reader<BasicJsonType>::little_endianess();