template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary |
( |
typename binary_t::container_type && |
init, |
|
|
typename binary_t::subtype_type |
subtype |
|
) |
| |
|
inlinestatic |
explicitly create a binary array (with subtype)
Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.
- Note
- Note, this function exists because of the difficulty in correctly specifying the correct template overload in the standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a
std::vector
. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
- Parameters
-
[in] | init | container containing bytes to use as binary type |
[in] | subtype | subtype to use in MessagePack and BSON |
- Returns
- JSON binary array value
@complexity Linear in the size of init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
- Since
- version 3.8.0
Definition at line 19572 of file json.hpp.
19573 {
19576 res.m_value =
binary_t(std::move(init), subtype);
19577 return res;
19578 }
basic_json(const value_t v)
create an empty value with a given type
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
@ binary
binary array (ordered collection of bytes)