♻️ rename internal_binary_t with binary_t
This commit is contained in:
		
							parent
							
								
									dead99eb0e
								
							
						
					
					
						commit
						904642f261
					
				
					 59 changed files with 536 additions and 457 deletions
				
			
		
							
								
								
									
										30
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1047,6 +1047,36 @@ std::vector<std::uint8_t> v_ubjson = json::to_ubjson(j);
 | 
			
		|||
json j_from_ubjson = json::from_ubjson(v_ubjson);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
The library also supports binary types from BSON, CBOR (byte strings), and MessagePack (bin, ext, fixext). They are stored by default as `std::vector<std::uint8_t>` to be processed outside of the library.
 | 
			
		||||
 | 
			
		||||
```cpp
 | 
			
		||||
// CBOR byte string with payload 0xCAFE
 | 
			
		||||
std::vector<std::uint8_t> v = {0x42, 0xCA, 0xFE};
 | 
			
		||||
 | 
			
		||||
// read value
 | 
			
		||||
json j = json::from_cbor(v);
 | 
			
		||||
 | 
			
		||||
// the JSON value has type binary
 | 
			
		||||
j.is_binary(); // true
 | 
			
		||||
 | 
			
		||||
// get reference to stored binary value
 | 
			
		||||
auto& binary = j.get_binary();
 | 
			
		||||
 | 
			
		||||
// the binary value has no subtype (CBOR has no binary subtypes)
 | 
			
		||||
binary.has_subtype(); // false
 | 
			
		||||
 | 
			
		||||
// access std::vector<std::uint8_t> member functions
 | 
			
		||||
binary.size(); // 2
 | 
			
		||||
binary[0]; // 0xCA
 | 
			
		||||
binary[1]; // 0xFE
 | 
			
		||||
 | 
			
		||||
// set subtype to 0x10
 | 
			
		||||
binary.set_subtype(0x10);
 | 
			
		||||
 | 
			
		||||
// serialize to MessagePack
 | 
			
		||||
auto cbor = json::to_msgpack(j); // 0xD5 (fixext2), 0x10, 0xCA, 0xFE
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Supported compilers
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_array()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_array() << '\n';
 | 
			
		||||
    std::cout << j_array.is_array() << '\n';
 | 
			
		||||
    std::cout << j_string.is_array() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_array() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/EXdpfHah1530TPIE"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/qO60NqUznleA1S7v"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
true
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										30
									
								
								doc/examples/is_binary.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								doc/examples/is_binary.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
#include <iostream>
 | 
			
		||||
#include <nlohmann/json.hpp>
 | 
			
		||||
 | 
			
		||||
using json = nlohmann::json;
 | 
			
		||||
 | 
			
		||||
int main()
 | 
			
		||||
{
 | 
			
		||||
    // create JSON values
 | 
			
		||||
    json j_null;
 | 
			
		||||
    json j_boolean = true;
 | 
			
		||||
    json j_number_integer = 17;
 | 
			
		||||
    json j_number_unsigned_integer = 12345678987654321u;
 | 
			
		||||
    json j_number_float = 23.42;
 | 
			
		||||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_binary()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
    std::cout << j_null.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_boolean.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_number_integer.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_number_unsigned_integer.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_number_float.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_object.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_array.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_string.is_binary() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_binary() << '\n';
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								doc/examples/is_binary.link
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								doc/examples/is_binary.link
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/xR6eTQqSySLjtpn6"><b>online</b></a>
 | 
			
		||||
							
								
								
									
										9
									
								
								doc/examples/is_binary.output
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								doc/examples/is_binary.output
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
true
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_boolean()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_boolean() << '\n';
 | 
			
		||||
    std::cout << j_array.is_boolean() << '\n';
 | 
			
		||||
    std::cout << j_string.is_boolean() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_boolean() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/7sniyNPobbQQdBHJ"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/QVbXnPfNZdvuDHwy"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_discarded()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_discarded() << '\n';
 | 
			
		||||
    std::cout << j_array.is_discarded() << '\n';
 | 
			
		||||
    std::cout << j_string.is_discarded() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_discarded() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/hWqzRJtSjY0cSoQV"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/jg033y5pdOFOst14"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_null()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_null() << '\n';
 | 
			
		||||
    std::cout << j_array.is_null() << '\n';
 | 
			
		||||
    std::cout << j_string.is_null() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_null() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/r0Z6mhqY20XowAPj"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/uDLxYO1TseoNS5Iu"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_number()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_number() << '\n';
 | 
			
		||||
    std::cout << j_array.is_number() << '\n';
 | 
			
		||||
    std::cout << j_string.is_number() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_number() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/e0RMOkVT4QrwhPV9"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/a7j4EG9Hvjbby3x0"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ true
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_number_float()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_number_float() << '\n';
 | 
			
		||||
    std::cout << j_array.is_number_float() << '\n';
 | 
			
		||||
    std::cout << j_string.is_number_float() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_number_float() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/Thh18DVuOoaiYidD"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/cT9J60hwwflg88M9"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ true
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_number_integer()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_number_integer() << '\n';
 | 
			
		||||
    std::cout << j_array.is_number_integer() << '\n';
 | 
			
		||||
    std::cout << j_string.is_number_integer() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_number_integer() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/wFZSC6RswWXwSncb"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/j0TgXy0oyXxKkhLN"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_number_unsigned()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_number_unsigned() << '\n';
 | 
			
		||||
    std::cout << j_array.is_number_unsigned() << '\n';
 | 
			
		||||
    std::cout << j_string.is_number_unsigned() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_number_unsigned() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/ajo1F1VJwoszcD7Y"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/u5wlpVX9Za6lEC2f"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_object()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_object() << '\n';
 | 
			
		||||
    std::cout << j_array.is_object() << '\n';
 | 
			
		||||
    std::cout << j_string.is_object() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_object() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/ojKk5AMVK9xF9bmQ"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/QJQ2avqtJEd4uI23"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
true
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_primitive()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_primitive() << '\n';
 | 
			
		||||
    std::cout << j_array.is_primitive() << '\n';
 | 
			
		||||
    std::cout << j_string.is_primitive() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_primitive() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/B7F0eMkW0EKdZGcC"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/a4WQ1RXZbD1YQELx"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ true
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
true
 | 
			
		||||
true
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_string()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_string() << '\n';
 | 
			
		||||
    std::cout << j_array.is_string() << '\n';
 | 
			
		||||
    std::cout << j_string.is_string() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_string() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/2Iq9wtaxEvrb5B68"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/vj3Wo1roaNjE3fPo"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
false
 | 
			
		||||
false
 | 
			
		||||
true
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ int main()
 | 
			
		|||
    json j_object = {{"one", 1}, {"two", 2}};
 | 
			
		||||
    json j_array = {1, 2, 4, 8, 16};
 | 
			
		||||
    json j_string = "Hello, world";
 | 
			
		||||
    json j_binary = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
    // call is_structured()
 | 
			
		||||
    std::cout << std::boolalpha;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,4 +26,5 @@ int main()
 | 
			
		|||
    std::cout << j_object.is_structured() << '\n';
 | 
			
		||||
    std::cout << j_array.is_structured() << '\n';
 | 
			
		||||
    std::cout << j_string.is_structured() << '\n';
 | 
			
		||||
    std::cout << j_binary.is_structured() << '\n';
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/44jkAs0G7D0XB24j"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/BoS03RLCyI6oDMbc"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,3 +6,4 @@ false
 | 
			
		|||
true
 | 
			
		||||
true
 | 
			
		||||
false
 | 
			
		||||
false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ class sax_event_consumer : public json::json_sax_t
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(binary_t& val) override
 | 
			
		||||
    bool binary(json::binary_t& val) override
 | 
			
		||||
    {
 | 
			
		||||
        events.push_back("binary");
 | 
			
		||||
        return true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/AoOilNQQoDbzgBYz"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/SbFNpOHK4By29meM"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -22,12 +22,14 @@ These pages contain the API documentation of JSON for Modern C++, a C++11 header
 | 
			
		|||
      @link nlohmann::basic_json::is_object is_object @endlink,
 | 
			
		||||
      @link nlohmann::basic_json::is_array is_array @endlink,
 | 
			
		||||
      @link nlohmann::basic_json::is_string is_string @endlink,
 | 
			
		||||
      @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
 | 
			
		||||
      @link nlohmann::basic_json::is_discarded is_discarded @endlink,
 | 
			
		||||
      @link nlohmann::basic_json::is_binary is_binary @endlink -- check for value type
 | 
			
		||||
    - @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
 | 
			
		||||
  - value access
 | 
			
		||||
    - @link nlohmann::basic_json::get get @endlink -- get a value
 | 
			
		||||
    - @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
 | 
			
		||||
    - @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
 | 
			
		||||
    - @link nlohmann::basic_json::get_binary get_binary @endlink -- get a binary value
 | 
			
		||||
    - @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
 | 
			
		||||
    - @link nlohmann::basic_json::value value @endlink -- get a value from an object and return default value if key is not present
 | 
			
		||||
  - exceptions
 | 
			
		||||
| 
						 | 
				
			
			@ -67,8 +69,9 @@ These pages contain the API documentation of JSON for Modern C++, a C++11 header
 | 
			
		|||
    - @link nlohmann::basic_json::number_integer_t signed integers @endlink
 | 
			
		||||
    - @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
 | 
			
		||||
    - @link nlohmann::basic_json::number_float_t floating-point @endlink
 | 
			
		||||
  - @link nlohmann::basic_json::binary_t binary values @endlink
 | 
			
		||||
- further JSON standards
 | 
			
		||||
  - @link nlohmann::json_pointer JSON Pointer @endlink (REF 6901)
 | 
			
		||||
  - @link nlohmann::json_pointer JSON Pointer @endlink (RFC 6901)
 | 
			
		||||
  - @link nlohmann::basic_json::patch JSON Patch @endlink (RFC 6902)
 | 
			
		||||
  - @link nlohmann::basic_json::merge_patch JSON Merge Patch @endlink (RFC 7396)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -324,7 +327,7 @@ Note that this table only lists those exceptions thrown due to the type. For ins
 | 
			
		|||
  </tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
@copyright Copyright © 2013-2019 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
 | 
			
		||||
@copyright Copyright © 2013-2020 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
 | 
			
		||||
 | 
			
		||||
@author [Niels Lohmann](http://nlohmann.me)
 | 
			
		||||
@see https://github.com/nlohmann/json to download the source code
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -228,7 +228,7 @@ template <typename BasicJsonType, typename ConstructibleArrayType,
 | 
			
		|||
              is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value and
 | 
			
		||||
              not is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value and
 | 
			
		||||
              not is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value and
 | 
			
		||||
              not std::is_same<ConstructibleArrayType, typename BasicJsonType::internal_binary_t>::value and
 | 
			
		||||
              not std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value and
 | 
			
		||||
              not is_basic_json<ConstructibleArrayType>::value,
 | 
			
		||||
              int > = 0 >
 | 
			
		||||
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
 | 
			
		||||
| 
						 | 
				
			
			@ -246,14 +246,14 @@ void())
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
template <typename BasicJsonType>
 | 
			
		||||
void from_json(const BasicJsonType& j, typename BasicJsonType::internal_binary_t& bin)
 | 
			
		||||
void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
 | 
			
		||||
{
 | 
			
		||||
    if (JSON_HEDLEY_UNLIKELY(not j.is_binary()))
 | 
			
		||||
    {
 | 
			
		||||
        JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name())));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bin = *j.template get_ptr<const typename BasicJsonType::internal_binary_t*>();
 | 
			
		||||
    bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template<typename BasicJsonType, typename ConstructibleObjectType,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,19 +71,19 @@ template<>
 | 
			
		|||
struct external_constructor<value_t::binary>
 | 
			
		||||
{
 | 
			
		||||
    template<typename BasicJsonType>
 | 
			
		||||
    static void construct(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& b)
 | 
			
		||||
    static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
 | 
			
		||||
    {
 | 
			
		||||
        j.m_type = value_t::binary;
 | 
			
		||||
        typename BasicJsonType::internal_binary_t value{b};
 | 
			
		||||
        typename BasicJsonType::binary_t value{b};
 | 
			
		||||
        j.m_value = value;
 | 
			
		||||
        j.assert_invariant();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template<typename BasicJsonType>
 | 
			
		||||
    static void construct(BasicJsonType& j, typename BasicJsonType::internal_binary_t&& b)
 | 
			
		||||
    static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
 | 
			
		||||
    {
 | 
			
		||||
        j.m_type = value_t::binary;
 | 
			
		||||
        typename BasicJsonType::internal_binary_t value{std::move(b)};
 | 
			
		||||
        typename BasicJsonType::binary_t value{std::move(b)};
 | 
			
		||||
        j.m_value = value;
 | 
			
		||||
        j.assert_invariant();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -280,7 +280,7 @@ template <typename BasicJsonType, typename CompatibleArrayType,
 | 
			
		|||
                      CompatibleArrayType>::value and
 | 
			
		||||
                      not is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value and
 | 
			
		||||
                      not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and
 | 
			
		||||
                      not std::is_same<typename BasicJsonType::internal_binary_t, CompatibleArrayType>::value and
 | 
			
		||||
                      not std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value and
 | 
			
		||||
                      not is_basic_json<CompatibleArrayType>::value,
 | 
			
		||||
                      int> = 0>
 | 
			
		||||
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
 | 
			
		||||
| 
						 | 
				
			
			@ -289,7 +289,7 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
template <typename BasicJsonType>
 | 
			
		||||
void to_json(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& bin)
 | 
			
		||||
void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
 | 
			
		||||
{
 | 
			
		||||
    external_constructor<value_t::binary>::construct(j, bin);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,7 +52,7 @@ class binary_reader
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
    using json_sax_t = SAX;
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
| 
						 | 
				
			
			@ -219,7 +219,7 @@ class binary_reader
 | 
			
		|||
    @return `true` if the byte array was successfully parsed
 | 
			
		||||
    */
 | 
			
		||||
    template<typename NumberType>
 | 
			
		||||
    bool get_bson_binary(const NumberType len, internal_binary_t& result)
 | 
			
		||||
    bool get_bson_binary(const NumberType len, binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        if (JSON_HEDLEY_UNLIKELY(len < 0))
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -276,7 +276,7 @@ class binary_reader
 | 
			
		|||
            case 0x05: // binary
 | 
			
		||||
            {
 | 
			
		||||
                std::int32_t len;
 | 
			
		||||
                internal_binary_t value;
 | 
			
		||||
                binary_t value;
 | 
			
		||||
                return get_number<std::int32_t, true>(input_format_t::bson, len) and get_bson_binary(len, value) and sax->binary(value);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -532,7 +532,7 @@ class binary_reader
 | 
			
		|||
            case 0x5B: // Binary data (eight-byte uint64_t for n follow)
 | 
			
		||||
            case 0x5F: // Binary data (indefinite length)
 | 
			
		||||
            {
 | 
			
		||||
                internal_binary_t b;
 | 
			
		||||
                binary_t b;
 | 
			
		||||
                return get_cbor_binary(b) and sax->binary(b);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -862,7 +862,7 @@ class binary_reader
 | 
			
		|||
 | 
			
		||||
    @return whether byte array creation completed
 | 
			
		||||
    */
 | 
			
		||||
    bool get_cbor_binary(internal_binary_t& result)
 | 
			
		||||
    bool get_cbor_binary(binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "binary")))
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -932,7 +932,7 @@ class binary_reader
 | 
			
		|||
            {
 | 
			
		||||
                while (get() != 0xFF)
 | 
			
		||||
                {
 | 
			
		||||
                    internal_binary_t chunk;
 | 
			
		||||
                    binary_t chunk;
 | 
			
		||||
                    if (not get_cbor_binary(chunk))
 | 
			
		||||
                    {
 | 
			
		||||
                        return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -1282,7 +1282,7 @@ class binary_reader
 | 
			
		|||
            case 0xD7: // fixext 8
 | 
			
		||||
            case 0xD8: // fixext 16
 | 
			
		||||
            {
 | 
			
		||||
                internal_binary_t b;
 | 
			
		||||
                binary_t b;
 | 
			
		||||
                return get_msgpack_binary(b) and sax->binary(b);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1505,7 +1505,7 @@ class binary_reader
 | 
			
		|||
 | 
			
		||||
    @return whether byte array creation completed
 | 
			
		||||
    */
 | 
			
		||||
    bool get_msgpack_binary(internal_binary_t& result)
 | 
			
		||||
    bool get_msgpack_binary(binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        // helper function to set the subtype
 | 
			
		||||
        auto assign_and_return_true = [&result](std::int8_t subtype)
 | 
			
		||||
| 
						 | 
				
			
			@ -2223,7 +2223,7 @@ class binary_reader
 | 
			
		|||
    template<typename NumberType>
 | 
			
		||||
    bool get_binary(const input_format_t format,
 | 
			
		||||
                    const NumberType len,
 | 
			
		||||
                    internal_binary_t& result)
 | 
			
		||||
                    binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        bool success = true;
 | 
			
		||||
        std::generate_n(std::back_inserter(result), len, [this, &success, &format]()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ struct json_sax
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief a null value was read
 | 
			
		||||
| 
						 | 
				
			
			@ -78,7 +78,7 @@ struct json_sax
 | 
			
		|||
    @return whether parsing should proceed
 | 
			
		||||
    @note It is safe to move the passed binary.
 | 
			
		||||
    */
 | 
			
		||||
    virtual bool binary(internal_binary_t& val) = 0;
 | 
			
		||||
    virtual bool binary(binary_t& val) = 0;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief the beginning of an object was read
 | 
			
		||||
| 
						 | 
				
			
			@ -154,7 +154,7 @@ class json_sax_dom_parser
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @param[in, out] r  reference to a JSON value that is manipulated while
 | 
			
		||||
| 
						 | 
				
			
			@ -208,7 +208,7 @@ class json_sax_dom_parser
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(internal_binary_t& val)
 | 
			
		||||
    bool binary(binary_t& val)
 | 
			
		||||
    {
 | 
			
		||||
        handle_value(std::move(val));
 | 
			
		||||
        return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -343,7 +343,7 @@ class json_sax_dom_callback_parser
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
    using parser_callback_t = typename BasicJsonType::parser_callback_t;
 | 
			
		||||
    using parse_event_t = typename BasicJsonType::parse_event_t;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -398,7 +398,7 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(internal_binary_t& val)
 | 
			
		||||
    bool binary(binary_t& val)
 | 
			
		||||
    {
 | 
			
		||||
        handle_value(std::move(val));
 | 
			
		||||
        return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -654,7 +654,7 @@ class json_sax_acceptor
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
    bool null()
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -686,7 +686,7 @@ class json_sax_acceptor
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(internal_binary_t& /*unused*/)
 | 
			
		||||
    bool binary(binary_t& /*unused*/)
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ template<typename BasicJsonType> struct internal_iterator
 | 
			
		|||
    /// iterator for JSON arrays
 | 
			
		||||
    typename BasicJsonType::array_t::iterator array_iterator {};
 | 
			
		||||
    /// iterator for JSON binary arrays
 | 
			
		||||
    typename BasicJsonType::binary_t::iterator binary_iterator {};
 | 
			
		||||
    typename BasicJsonType::binary_t::container_type::iterator binary_iterator {};
 | 
			
		||||
    /// generic iterator for all other types
 | 
			
		||||
    primitive_iterator_t primitive_iterator {};
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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:
 | 
			
		||||
    /*!
 | 
			
		||||
| 
						 | 
				
			
			@ -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,7 +1108,7 @@ 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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ class serializer
 | 
			
		|||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using number_integer_t = typename BasicJsonType::number_integer_t;
 | 
			
		||||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
    using binary_char_t = typename BasicJsonType::binary_t::value_type;
 | 
			
		||||
    static constexpr std::uint8_t UTF8_ACCEPT = 0;
 | 
			
		||||
    static constexpr std::uint8_t UTF8_REJECT = 1;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -624,7 +624,7 @@ class serializer
 | 
			
		|||
    template<typename NumberType, detail::enable_if_t<
 | 
			
		||||
                 std::is_same<NumberType, number_unsigned_t>::value or
 | 
			
		||||
                 std::is_same<NumberType, number_integer_t>::value or
 | 
			
		||||
                 std::is_same<NumberType, typename binary_t::value_type>::value,
 | 
			
		||||
                 std::is_same<NumberType, binary_char_t>::value,
 | 
			
		||||
                 int> = 0>
 | 
			
		||||
    void dump_integer(NumberType x)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,36 +19,51 @@ template<typename BinaryType>
 | 
			
		|||
class wrapped_binary_t : public BinaryType
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    using binary_t = BinaryType;
 | 
			
		||||
    /// the type of the underlying container
 | 
			
		||||
    using container_type = BinaryType;
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t() noexcept(noexcept(binary_t()))
 | 
			
		||||
        : binary_t()
 | 
			
		||||
    wrapped_binary_t() noexcept(noexcept(container_type()))
 | 
			
		||||
        : container_type()
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(const binary_t& b) noexcept(noexcept(binary_t(b)))
 | 
			
		||||
        : binary_t(b)
 | 
			
		||||
    wrapped_binary_t(const container_type& b) noexcept(noexcept(container_type(b)))
 | 
			
		||||
        : container_type(b)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(binary_t&& b) noexcept(noexcept(binary_t(std::move(b))))
 | 
			
		||||
        : binary_t(std::move(b))
 | 
			
		||||
    wrapped_binary_t(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
 | 
			
		||||
        : container_type(std::move(b))
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(const binary_t& b,
 | 
			
		||||
                     std::uint8_t subtype) noexcept(noexcept(binary_t(b)))
 | 
			
		||||
        : binary_t(b)
 | 
			
		||||
    wrapped_binary_t(const container_type& b,
 | 
			
		||||
                     std::uint8_t subtype) noexcept(noexcept(container_type(b)))
 | 
			
		||||
        : container_type(b)
 | 
			
		||||
        , m_subtype(subtype)
 | 
			
		||||
        , m_has_subtype(true)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(binary_t&& b, std::uint8_t subtype) noexcept(noexcept(binary_t(std::move(b))))
 | 
			
		||||
        : binary_t(std::move(b))
 | 
			
		||||
    wrapped_binary_t(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b))))
 | 
			
		||||
        : container_type(std::move(b))
 | 
			
		||||
        , m_subtype(subtype)
 | 
			
		||||
        , m_has_subtype(true)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief set the subtype
 | 
			
		||||
    @param subtype subtype to set (implementation specific)
 | 
			
		||||
    @brief sets the binary subtype
 | 
			
		||||
 | 
			
		||||
    Sets the binary subtype of the value, also flags a binary JSON value as
 | 
			
		||||
    having a subtype, which has implications for serialization.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    void set_subtype(std::uint8_t subtype) noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -57,8 +72,25 @@ class wrapped_binary_t : public BinaryType
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief get the subtype
 | 
			
		||||
    @return subtype (implementation specific)
 | 
			
		||||
    @brief return the binary subtype
 | 
			
		||||
 | 
			
		||||
    Returns the numerical subtype of the value if it has a subtype. If it does
 | 
			
		||||
    not have a subtype, this function will return size_t(-1) as a sentinel
 | 
			
		||||
    value.
 | 
			
		||||
 | 
			
		||||
    @return the numerical subtype of the binary value
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    constexpr std::uint8_t subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,8 +98,20 @@ class wrapped_binary_t : public BinaryType
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief get whether a subtype was set
 | 
			
		||||
    @return whether a subtype was set
 | 
			
		||||
    @brief return whether the value has a subtype
 | 
			
		||||
 | 
			
		||||
    @return whether the value has a subtype
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    constexpr bool has_subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +119,23 @@ class wrapped_binary_t : public BinaryType
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief clear the subtype
 | 
			
		||||
    @brief clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    Clears the binary subtype and flags the value as not having a subtype, which
 | 
			
		||||
    has implications for serialization; for instance MessagePack will prefer the
 | 
			
		||||
    bin family over the ext family.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    void clear_subtype() noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -884,23 +884,7 @@ class basic_json
 | 
			
		|||
    for any access to array values, a pointer of the type `binary_t*` must be
 | 
			
		||||
    dereferenced.
 | 
			
		||||
 | 
			
		||||
    @sa @ref array_t -- type for an array value
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    using binary_t = BinaryType;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief binary array with a binary type
 | 
			
		||||
 | 
			
		||||
    This type is used to store binary types internally. It wrapps the template
 | 
			
		||||
    type `BinaryType` (@ref binary_t) and adds a subtype to allow to distinguish
 | 
			
		||||
    different binary types from different formats.
 | 
			
		||||
 | 
			
		||||
    While @ref binary_t is used to define how binary values are stored, this
 | 
			
		||||
    type is used to access binary values once they are parsed.
 | 
			
		||||
 | 
			
		||||
    Notes on subtypes:
 | 
			
		||||
    #### Notes on subtypes
 | 
			
		||||
 | 
			
		||||
    - CBOR
 | 
			
		||||
       - Binary values are represented as byte strings. No subtypes are
 | 
			
		||||
| 
						 | 
				
			
			@ -916,8 +900,10 @@ class basic_json
 | 
			
		|||
       - If no subtype is given, the generic binary subtype 0x00 is used.
 | 
			
		||||
 | 
			
		||||
    @sa @ref binary_array -- create a binary array
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    using internal_binary_t = nlohmann::detail::wrapped_binary_t<BinaryType>;
 | 
			
		||||
    using binary_t = nlohmann::detail::wrapped_binary_t<BinaryType>;
 | 
			
		||||
    /// @}
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
| 
						 | 
				
			
			@ -978,7 +964,7 @@ class basic_json
 | 
			
		|||
        /// string (stored with pointer to save storage)
 | 
			
		||||
        string_t* string;
 | 
			
		||||
        /// binary (stored with pointer to save storage)
 | 
			
		||||
        internal_binary_t* binary;
 | 
			
		||||
        binary_t* binary;
 | 
			
		||||
        /// boolean
 | 
			
		||||
        boolean_t boolean;
 | 
			
		||||
        /// number (integer)
 | 
			
		||||
| 
						 | 
				
			
			@ -1023,7 +1009,7 @@ class basic_json
 | 
			
		|||
 | 
			
		||||
                case value_t::binary:
 | 
			
		||||
                {
 | 
			
		||||
                    binary = create<internal_binary_t>();
 | 
			
		||||
                    binary = create<binary_t>();
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1106,27 +1092,27 @@ class basic_json
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for binary arrays
 | 
			
		||||
        json_value(const binary_t& value)
 | 
			
		||||
        json_value(const typename binary_t::container_type& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(value);
 | 
			
		||||
            binary = create<binary_t>(value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for rvalue binary arrays
 | 
			
		||||
        json_value(binary_t&& value)
 | 
			
		||||
        json_value(typename binary_t::container_type&& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(std::move(value));
 | 
			
		||||
            binary = create<binary_t>(std::move(value));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for binary arrays (internal type)
 | 
			
		||||
        json_value(const internal_binary_t& value)
 | 
			
		||||
        json_value(const binary_t& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(value);
 | 
			
		||||
            binary = create<binary_t>(value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for rvalue binary arrays (internal type)
 | 
			
		||||
        json_value(internal_binary_t&& value)
 | 
			
		||||
        json_value(binary_t&& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(std::move(value));
 | 
			
		||||
            binary = create<binary_t>(std::move(value));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void destroy(value_t t) noexcept
 | 
			
		||||
| 
						 | 
				
			
			@ -1206,7 +1192,7 @@ class basic_json
 | 
			
		|||
 | 
			
		||||
                case value_t::binary:
 | 
			
		||||
                {
 | 
			
		||||
                    AllocatorType<internal_binary_t> alloc;
 | 
			
		||||
                    AllocatorType<binary_t> alloc;
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
 | 
			
		||||
                    break;
 | 
			
		||||
| 
						 | 
				
			
			@ -1492,7 +1478,7 @@ class basic_json
 | 
			
		|||
        using other_string_t = typename BasicJsonType::string_t;
 | 
			
		||||
        using other_object_t = typename BasicJsonType::object_t;
 | 
			
		||||
        using other_array_t = typename BasicJsonType::array_t;
 | 
			
		||||
        using other_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
        using other_binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
        switch (val.type())
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -1686,7 +1672,7 @@ class basic_json
 | 
			
		|||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(const binary_t& init)
 | 
			
		||||
    static basic_json binary_array(const typename binary_t::container_type& init)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
| 
						 | 
				
			
			@ -1695,11 +1681,11 @@ class basic_json
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(const binary_t& init, std::uint8_t subtype)
 | 
			
		||||
    static basic_json binary_array(const typename binary_t::container_type& init, std::uint8_t subtype)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
        res.m_value = internal_binary_t(init, subtype);
 | 
			
		||||
        res.m_value = binary_t(init, subtype);
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1731,7 +1717,7 @@ class basic_json
 | 
			
		|||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(binary_t&& init)
 | 
			
		||||
    static basic_json binary_array(typename binary_t::container_type&& init)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
| 
						 | 
				
			
			@ -1740,11 +1726,11 @@ class basic_json
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(binary_t&& init, std::uint8_t subtype)
 | 
			
		||||
    static basic_json binary_array(typename binary_t::container_type&& init, std::uint8_t subtype)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
        res.m_value = internal_binary_t(std::move(init), subtype);
 | 
			
		||||
        res.m_value = binary_t(std::move(init), subtype);
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2794,13 +2780,13 @@ class basic_json
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /// get a pointer to the value (binary)
 | 
			
		||||
    internal_binary_t* get_impl_ptr(internal_binary_t* /*unused*/) noexcept
 | 
			
		||||
    binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return is_binary() ? m_value.binary : nullptr;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// get a pointer to the value (binary)
 | 
			
		||||
    constexpr const internal_binary_t* get_impl_ptr(const internal_binary_t* /*unused*/) const noexcept
 | 
			
		||||
    constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return is_binary() ? m_value.binary : nullptr;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -3230,6 +3216,36 @@ class basic_json
 | 
			
		|||
        return get<ValueType>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @return reference to the binary value
 | 
			
		||||
 | 
			
		||||
    @throw type_error.302 if the value is not binary
 | 
			
		||||
 | 
			
		||||
    @sa @ref is_binary() to check if the value is binary
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    binary_t& get_binary()
 | 
			
		||||
    {
 | 
			
		||||
        if (not is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name())));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return *get_ptr<binary_t*>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @copydoc get_binary()
 | 
			
		||||
    const binary_t& get_binary() const
 | 
			
		||||
    {
 | 
			
		||||
        if (not is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name())));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return *get_ptr<const binary_t*>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3852,118 +3868,6 @@ class basic_json
 | 
			
		|||
        return value(ptr, string_t(default_value));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief return the binary subtype
 | 
			
		||||
 | 
			
		||||
    Returns the numerical subtype of the JSON value, if the JSON value is of
 | 
			
		||||
    type "binary", and it has a subtype.  If it does not have a subtype (or the
 | 
			
		||||
    object is not of type binary) this function will return size_t(-1) as a
 | 
			
		||||
    sentinel value.
 | 
			
		||||
 | 
			
		||||
    @return the numerical subtype of the binary JSON value
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    std::size_t get_subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if (is_binary() and m_value.binary->has_subtype)
 | 
			
		||||
        {
 | 
			
		||||
            return m_value.binary->subtype;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return std::size_t(-1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief sets the binary subtype
 | 
			
		||||
 | 
			
		||||
    Sets the binary subtype of the JSON value, also flags a binary JSON value as
 | 
			
		||||
    having a subtype, which has implications for serialization to msgpack (will
 | 
			
		||||
    prefer ext file formats over bin).  If the JSON value is not a binary value,
 | 
			
		||||
    this function does nothing.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref get_subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    void set_subtype(std::uint8_t subtype) noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if (is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            m_value.binary->set_subtype(subtype);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    Clears the binary subtype of the JSON value, also flags a binary JSON value
 | 
			
		||||
    as not having a subtype, which has implications for serialization to msgpack
 | 
			
		||||
    (will prefer bin file formats over ext).  If the JSON value is not a binary
 | 
			
		||||
    value, this function does nothing.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref get_subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    void clear_subtype() noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if (is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            m_value.binary->clear_subtype();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief return whether or not the binary subtype has a value
 | 
			
		||||
 | 
			
		||||
    Returns whether or not the binary subtype has a value.
 | 
			
		||||
 | 
			
		||||
    @return whether or not the binary subtype has a value.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref get_subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    bool has_subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return is_binary() and m_value.binary->has_subtype();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief access the first element
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -4133,7 +4037,7 @@ class basic_json
 | 
			
		|||
                }
 | 
			
		||||
                else if (is_binary())
 | 
			
		||||
                {
 | 
			
		||||
                    AllocatorType<internal_binary_t> alloc;
 | 
			
		||||
                    AllocatorType<binary_t> alloc;
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
 | 
			
		||||
                    m_value.binary = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			@ -4247,7 +4151,7 @@ class basic_json
 | 
			
		|||
                }
 | 
			
		||||
                else if (is_binary())
 | 
			
		||||
                {
 | 
			
		||||
                    AllocatorType<internal_binary_t> alloc;
 | 
			
		||||
                    AllocatorType<binary_t> alloc;
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
 | 
			
		||||
                    m_value.binary = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			@ -6087,6 +5991,20 @@ class basic_json
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @copydoc swap(binary_t)
 | 
			
		||||
    void swap(typename binary_t::container_type& other)
 | 
			
		||||
    {
 | 
			
		||||
        // swap only works for strings
 | 
			
		||||
        if (JSON_HEDLEY_LIKELY(is_binary()))
 | 
			
		||||
        {
 | 
			
		||||
            std::swap(*(m_value.binary), other);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name())));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @}
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3448,7 +3448,7 @@ template <typename BasicJsonType, typename ConstructibleArrayType,
 | 
			
		|||
              is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value and
 | 
			
		||||
              not is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value and
 | 
			
		||||
              not is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value and
 | 
			
		||||
              not std::is_same<ConstructibleArrayType, typename BasicJsonType::internal_binary_t>::value and
 | 
			
		||||
              not std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value and
 | 
			
		||||
              not is_basic_json<ConstructibleArrayType>::value,
 | 
			
		||||
              int > = 0 >
 | 
			
		||||
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
 | 
			
		||||
| 
						 | 
				
			
			@ -3466,14 +3466,14 @@ void())
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
template <typename BasicJsonType>
 | 
			
		||||
void from_json(const BasicJsonType& j, typename BasicJsonType::internal_binary_t& bin)
 | 
			
		||||
void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
 | 
			
		||||
{
 | 
			
		||||
    if (JSON_HEDLEY_UNLIKELY(not j.is_binary()))
 | 
			
		||||
    {
 | 
			
		||||
        JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name())));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bin = *j.template get_ptr<const typename BasicJsonType::internal_binary_t*>();
 | 
			
		||||
    bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template<typename BasicJsonType, typename ConstructibleObjectType,
 | 
			
		||||
| 
						 | 
				
			
			@ -3876,19 +3876,19 @@ template<>
 | 
			
		|||
struct external_constructor<value_t::binary>
 | 
			
		||||
{
 | 
			
		||||
    template<typename BasicJsonType>
 | 
			
		||||
    static void construct(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& b)
 | 
			
		||||
    static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
 | 
			
		||||
    {
 | 
			
		||||
        j.m_type = value_t::binary;
 | 
			
		||||
        typename BasicJsonType::internal_binary_t value{b};
 | 
			
		||||
        typename BasicJsonType::binary_t value{b};
 | 
			
		||||
        j.m_value = value;
 | 
			
		||||
        j.assert_invariant();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template<typename BasicJsonType>
 | 
			
		||||
    static void construct(BasicJsonType& j, typename BasicJsonType::internal_binary_t&& b)
 | 
			
		||||
    static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
 | 
			
		||||
    {
 | 
			
		||||
        j.m_type = value_t::binary;
 | 
			
		||||
        typename BasicJsonType::internal_binary_t value{std::move(b)};
 | 
			
		||||
        typename BasicJsonType::binary_t value{std::move(b)};
 | 
			
		||||
        j.m_value = value;
 | 
			
		||||
        j.assert_invariant();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -4085,7 +4085,7 @@ template <typename BasicJsonType, typename CompatibleArrayType,
 | 
			
		|||
                      CompatibleArrayType>::value and
 | 
			
		||||
                      not is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value and
 | 
			
		||||
                      not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and
 | 
			
		||||
                      not std::is_same<typename BasicJsonType::internal_binary_t, CompatibleArrayType>::value and
 | 
			
		||||
                      not std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value and
 | 
			
		||||
                      not is_basic_json<CompatibleArrayType>::value,
 | 
			
		||||
                      int> = 0>
 | 
			
		||||
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
 | 
			
		||||
| 
						 | 
				
			
			@ -4094,7 +4094,7 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
template <typename BasicJsonType>
 | 
			
		||||
void to_json(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& bin)
 | 
			
		||||
void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
 | 
			
		||||
{
 | 
			
		||||
    external_constructor<value_t::binary>::construct(j, bin);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -4764,7 +4764,7 @@ struct json_sax
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief a null value was read
 | 
			
		||||
| 
						 | 
				
			
			@ -4815,7 +4815,7 @@ struct json_sax
 | 
			
		|||
    @return whether parsing should proceed
 | 
			
		||||
    @note It is safe to move the passed binary.
 | 
			
		||||
    */
 | 
			
		||||
    virtual bool binary(internal_binary_t& val) = 0;
 | 
			
		||||
    virtual bool binary(binary_t& val) = 0;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief the beginning of an object was read
 | 
			
		||||
| 
						 | 
				
			
			@ -4891,7 +4891,7 @@ class json_sax_dom_parser
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @param[in, out] r  reference to a JSON value that is manipulated while
 | 
			
		||||
| 
						 | 
				
			
			@ -4945,7 +4945,7 @@ class json_sax_dom_parser
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(internal_binary_t& val)
 | 
			
		||||
    bool binary(binary_t& val)
 | 
			
		||||
    {
 | 
			
		||||
        handle_value(std::move(val));
 | 
			
		||||
        return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -5080,7 +5080,7 @@ class json_sax_dom_callback_parser
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
    using parser_callback_t = typename BasicJsonType::parser_callback_t;
 | 
			
		||||
    using parse_event_t = typename BasicJsonType::parse_event_t;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -5135,7 +5135,7 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(internal_binary_t& val)
 | 
			
		||||
    bool binary(binary_t& val)
 | 
			
		||||
    {
 | 
			
		||||
        handle_value(std::move(val));
 | 
			
		||||
        return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -5391,7 +5391,7 @@ class json_sax_acceptor
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
    bool null()
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -5423,7 +5423,7 @@ class json_sax_acceptor
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(internal_binary_t& /*unused*/)
 | 
			
		||||
    bool binary(binary_t& /*unused*/)
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -5645,7 +5645,7 @@ class binary_reader
 | 
			
		|||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using string_t = typename BasicJsonType::string_t;
 | 
			
		||||
    using internal_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
    using json_sax_t = SAX;
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
| 
						 | 
				
			
			@ -5812,7 +5812,7 @@ class binary_reader
 | 
			
		|||
    @return `true` if the byte array was successfully parsed
 | 
			
		||||
    */
 | 
			
		||||
    template<typename NumberType>
 | 
			
		||||
    bool get_bson_binary(const NumberType len, internal_binary_t& result)
 | 
			
		||||
    bool get_bson_binary(const NumberType len, binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        if (JSON_HEDLEY_UNLIKELY(len < 0))
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -5869,7 +5869,7 @@ class binary_reader
 | 
			
		|||
            case 0x05: // binary
 | 
			
		||||
            {
 | 
			
		||||
                std::int32_t len;
 | 
			
		||||
                internal_binary_t value;
 | 
			
		||||
                binary_t value;
 | 
			
		||||
                return get_number<std::int32_t, true>(input_format_t::bson, len) and get_bson_binary(len, value) and sax->binary(value);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -6125,7 +6125,7 @@ class binary_reader
 | 
			
		|||
            case 0x5B: // Binary data (eight-byte uint64_t for n follow)
 | 
			
		||||
            case 0x5F: // Binary data (indefinite length)
 | 
			
		||||
            {
 | 
			
		||||
                internal_binary_t b;
 | 
			
		||||
                binary_t b;
 | 
			
		||||
                return get_cbor_binary(b) and sax->binary(b);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -6455,7 +6455,7 @@ class binary_reader
 | 
			
		|||
 | 
			
		||||
    @return whether byte array creation completed
 | 
			
		||||
    */
 | 
			
		||||
    bool get_cbor_binary(internal_binary_t& result)
 | 
			
		||||
    bool get_cbor_binary(binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "binary")))
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -6525,7 +6525,7 @@ class binary_reader
 | 
			
		|||
            {
 | 
			
		||||
                while (get() != 0xFF)
 | 
			
		||||
                {
 | 
			
		||||
                    internal_binary_t chunk;
 | 
			
		||||
                    binary_t chunk;
 | 
			
		||||
                    if (not get_cbor_binary(chunk))
 | 
			
		||||
                    {
 | 
			
		||||
                        return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -6875,7 +6875,7 @@ class binary_reader
 | 
			
		|||
            case 0xD7: // fixext 8
 | 
			
		||||
            case 0xD8: // fixext 16
 | 
			
		||||
            {
 | 
			
		||||
                internal_binary_t b;
 | 
			
		||||
                binary_t b;
 | 
			
		||||
                return get_msgpack_binary(b) and sax->binary(b);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -7098,7 +7098,7 @@ class binary_reader
 | 
			
		|||
 | 
			
		||||
    @return whether byte array creation completed
 | 
			
		||||
    */
 | 
			
		||||
    bool get_msgpack_binary(internal_binary_t& result)
 | 
			
		||||
    bool get_msgpack_binary(binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        // helper function to set the subtype
 | 
			
		||||
        auto assign_and_return_true = [&result](std::int8_t subtype)
 | 
			
		||||
| 
						 | 
				
			
			@ -7816,7 +7816,7 @@ class binary_reader
 | 
			
		|||
    template<typename NumberType>
 | 
			
		||||
    bool get_binary(const input_format_t format,
 | 
			
		||||
                    const NumberType len,
 | 
			
		||||
                    internal_binary_t& result)
 | 
			
		||||
                    binary_t& result)
 | 
			
		||||
    {
 | 
			
		||||
        bool success = true;
 | 
			
		||||
        std::generate_n(std::back_inserter(result), len, [this, &success, &format]()
 | 
			
		||||
| 
						 | 
				
			
			@ -10089,7 +10089,7 @@ template<typename BasicJsonType> struct internal_iterator
 | 
			
		|||
    /// iterator for JSON arrays
 | 
			
		||||
    typename BasicJsonType::array_t::iterator array_iterator {};
 | 
			
		||||
    /// iterator for JSON binary arrays
 | 
			
		||||
    typename BasicJsonType::binary_t::iterator binary_iterator {};
 | 
			
		||||
    typename BasicJsonType::binary_t::container_type::iterator binary_iterator {};
 | 
			
		||||
    /// generic iterator for all other types
 | 
			
		||||
    primitive_iterator_t primitive_iterator {};
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -12080,7 +12080,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:
 | 
			
		||||
    /*!
 | 
			
		||||
| 
						 | 
				
			
			@ -13133,7 +13133,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;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -13161,7 +13161,7 @@ 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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -14789,7 +14789,7 @@ class serializer
 | 
			
		|||
    using number_float_t = typename BasicJsonType::number_float_t;
 | 
			
		||||
    using number_integer_t = typename BasicJsonType::number_integer_t;
 | 
			
		||||
    using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 | 
			
		||||
    using binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
    using binary_char_t = typename BasicJsonType::binary_t::value_type;
 | 
			
		||||
    static constexpr std::uint8_t UTF8_ACCEPT = 0;
 | 
			
		||||
    static constexpr std::uint8_t UTF8_REJECT = 1;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15368,7 +15368,7 @@ class serializer
 | 
			
		|||
    template<typename NumberType, detail::enable_if_t<
 | 
			
		||||
                 std::is_same<NumberType, number_unsigned_t>::value or
 | 
			
		||||
                 std::is_same<NumberType, number_integer_t>::value or
 | 
			
		||||
                 std::is_same<NumberType, typename binary_t::value_type>::value,
 | 
			
		||||
                 std::is_same<NumberType, binary_char_t>::value,
 | 
			
		||||
                 int> = 0>
 | 
			
		||||
    void dump_integer(NumberType x)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -15667,36 +15667,51 @@ template<typename BinaryType>
 | 
			
		|||
class wrapped_binary_t : public BinaryType
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    using binary_t = BinaryType;
 | 
			
		||||
    /// the type of the underlying container
 | 
			
		||||
    using container_type = BinaryType;
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t() noexcept(noexcept(binary_t()))
 | 
			
		||||
        : binary_t()
 | 
			
		||||
    wrapped_binary_t() noexcept(noexcept(container_type()))
 | 
			
		||||
        : container_type()
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(const binary_t& b) noexcept(noexcept(binary_t(b)))
 | 
			
		||||
        : binary_t(b)
 | 
			
		||||
    wrapped_binary_t(const container_type& b) noexcept(noexcept(container_type(b)))
 | 
			
		||||
        : container_type(b)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(binary_t&& b) noexcept(noexcept(binary_t(std::move(b))))
 | 
			
		||||
        : binary_t(std::move(b))
 | 
			
		||||
    wrapped_binary_t(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
 | 
			
		||||
        : container_type(std::move(b))
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(const binary_t& b,
 | 
			
		||||
                     std::uint8_t subtype) noexcept(noexcept(binary_t(b)))
 | 
			
		||||
        : binary_t(b)
 | 
			
		||||
    wrapped_binary_t(const container_type& b,
 | 
			
		||||
                     std::uint8_t subtype) noexcept(noexcept(container_type(b)))
 | 
			
		||||
        : container_type(b)
 | 
			
		||||
        , m_subtype(subtype)
 | 
			
		||||
        , m_has_subtype(true)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    wrapped_binary_t(binary_t&& b, std::uint8_t subtype) noexcept(noexcept(binary_t(std::move(b))))
 | 
			
		||||
        : binary_t(std::move(b))
 | 
			
		||||
    wrapped_binary_t(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b))))
 | 
			
		||||
        : container_type(std::move(b))
 | 
			
		||||
        , m_subtype(subtype)
 | 
			
		||||
        , m_has_subtype(true)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief set the subtype
 | 
			
		||||
    @param subtype subtype to set (implementation specific)
 | 
			
		||||
    @brief sets the binary subtype
 | 
			
		||||
 | 
			
		||||
    Sets the binary subtype of the value, also flags a binary JSON value as
 | 
			
		||||
    having a subtype, which has implications for serialization.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    void set_subtype(std::uint8_t subtype) noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -15705,8 +15720,25 @@ class wrapped_binary_t : public BinaryType
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief get the subtype
 | 
			
		||||
    @return subtype (implementation specific)
 | 
			
		||||
    @brief return the binary subtype
 | 
			
		||||
 | 
			
		||||
    Returns the numerical subtype of the value if it has a subtype. If it does
 | 
			
		||||
    not have a subtype, this function will return size_t(-1) as a sentinel
 | 
			
		||||
    value.
 | 
			
		||||
 | 
			
		||||
    @return the numerical subtype of the binary value
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    constexpr std::uint8_t subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -15714,8 +15746,20 @@ class wrapped_binary_t : public BinaryType
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief get whether a subtype was set
 | 
			
		||||
    @return whether a subtype was set
 | 
			
		||||
    @brief return whether the value has a subtype
 | 
			
		||||
 | 
			
		||||
    @return whether the value has a subtype
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    constexpr bool has_subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -15723,7 +15767,23 @@ class wrapped_binary_t : public BinaryType
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief clear the subtype
 | 
			
		||||
    @brief clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    Clears the binary subtype and flags the value as not having a subtype, which
 | 
			
		||||
    has implications for serialization; for instance MessagePack will prefer the
 | 
			
		||||
    bin family over the ext family.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    void clear_subtype() noexcept
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -16553,23 +16613,7 @@ class basic_json
 | 
			
		|||
    for any access to array values, a pointer of the type `binary_t*` must be
 | 
			
		||||
    dereferenced.
 | 
			
		||||
 | 
			
		||||
    @sa @ref array_t -- type for an array value
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    using binary_t = BinaryType;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief binary array with a binary type
 | 
			
		||||
 | 
			
		||||
    This type is used to store binary types internally. It wrapps the template
 | 
			
		||||
    type `BinaryType` (@ref binary_t) and adds a subtype to allow to distinguish
 | 
			
		||||
    different binary types from different formats.
 | 
			
		||||
 | 
			
		||||
    While @ref binary_t is used to define how binary values are stored, this
 | 
			
		||||
    type is used to access binary values once they are parsed.
 | 
			
		||||
 | 
			
		||||
    Notes on subtypes:
 | 
			
		||||
    #### Notes on subtypes
 | 
			
		||||
 | 
			
		||||
    - CBOR
 | 
			
		||||
       - Binary values are represented as byte strings. No subtypes are
 | 
			
		||||
| 
						 | 
				
			
			@ -16585,8 +16629,10 @@ class basic_json
 | 
			
		|||
       - If no subtype is given, the generic binary subtype 0x00 is used.
 | 
			
		||||
 | 
			
		||||
    @sa @ref binary_array -- create a binary array
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    using internal_binary_t = nlohmann::detail::wrapped_binary_t<BinaryType>;
 | 
			
		||||
    using binary_t = nlohmann::detail::wrapped_binary_t<BinaryType>;
 | 
			
		||||
    /// @}
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
| 
						 | 
				
			
			@ -16647,7 +16693,7 @@ class basic_json
 | 
			
		|||
        /// string (stored with pointer to save storage)
 | 
			
		||||
        string_t* string;
 | 
			
		||||
        /// binary (stored with pointer to save storage)
 | 
			
		||||
        internal_binary_t* binary;
 | 
			
		||||
        binary_t* binary;
 | 
			
		||||
        /// boolean
 | 
			
		||||
        boolean_t boolean;
 | 
			
		||||
        /// number (integer)
 | 
			
		||||
| 
						 | 
				
			
			@ -16692,7 +16738,7 @@ class basic_json
 | 
			
		|||
 | 
			
		||||
                case value_t::binary:
 | 
			
		||||
                {
 | 
			
		||||
                    binary = create<internal_binary_t>();
 | 
			
		||||
                    binary = create<binary_t>();
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -16775,27 +16821,27 @@ class basic_json
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for binary arrays
 | 
			
		||||
        json_value(const binary_t& value)
 | 
			
		||||
        json_value(const typename binary_t::container_type& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(value);
 | 
			
		||||
            binary = create<binary_t>(value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for rvalue binary arrays
 | 
			
		||||
        json_value(binary_t&& value)
 | 
			
		||||
        json_value(typename binary_t::container_type&& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(std::move(value));
 | 
			
		||||
            binary = create<binary_t>(std::move(value));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for binary arrays (internal type)
 | 
			
		||||
        json_value(const internal_binary_t& value)
 | 
			
		||||
        json_value(const binary_t& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(value);
 | 
			
		||||
            binary = create<binary_t>(value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// constructor for rvalue binary arrays (internal type)
 | 
			
		||||
        json_value(internal_binary_t&& value)
 | 
			
		||||
        json_value(binary_t&& value)
 | 
			
		||||
        {
 | 
			
		||||
            binary = create<internal_binary_t>(std::move(value));
 | 
			
		||||
            binary = create<binary_t>(std::move(value));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void destroy(value_t t) noexcept
 | 
			
		||||
| 
						 | 
				
			
			@ -16875,7 +16921,7 @@ class basic_json
 | 
			
		|||
 | 
			
		||||
                case value_t::binary:
 | 
			
		||||
                {
 | 
			
		||||
                    AllocatorType<internal_binary_t> alloc;
 | 
			
		||||
                    AllocatorType<binary_t> alloc;
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
 | 
			
		||||
                    break;
 | 
			
		||||
| 
						 | 
				
			
			@ -17161,7 +17207,7 @@ class basic_json
 | 
			
		|||
        using other_string_t = typename BasicJsonType::string_t;
 | 
			
		||||
        using other_object_t = typename BasicJsonType::object_t;
 | 
			
		||||
        using other_array_t = typename BasicJsonType::array_t;
 | 
			
		||||
        using other_binary_t = typename BasicJsonType::internal_binary_t;
 | 
			
		||||
        using other_binary_t = typename BasicJsonType::binary_t;
 | 
			
		||||
 | 
			
		||||
        switch (val.type())
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -17355,7 +17401,7 @@ class basic_json
 | 
			
		|||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(const binary_t& init)
 | 
			
		||||
    static basic_json binary_array(const typename binary_t::container_type& init)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
| 
						 | 
				
			
			@ -17364,11 +17410,11 @@ class basic_json
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(const binary_t& init, std::uint8_t subtype)
 | 
			
		||||
    static basic_json binary_array(const typename binary_t::container_type& init, std::uint8_t subtype)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
        res.m_value = internal_binary_t(init, subtype);
 | 
			
		||||
        res.m_value = binary_t(init, subtype);
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -17400,7 +17446,7 @@ class basic_json
 | 
			
		|||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(binary_t&& init)
 | 
			
		||||
    static basic_json binary_array(typename binary_t::container_type&& init)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
| 
						 | 
				
			
			@ -17409,11 +17455,11 @@ class basic_json
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    JSON_HEDLEY_WARN_UNUSED_RESULT
 | 
			
		||||
    static basic_json binary_array(binary_t&& init, std::uint8_t subtype)
 | 
			
		||||
    static basic_json binary_array(typename binary_t::container_type&& init, std::uint8_t subtype)
 | 
			
		||||
    {
 | 
			
		||||
        auto res = basic_json();
 | 
			
		||||
        res.m_type = value_t::binary;
 | 
			
		||||
        res.m_value = internal_binary_t(std::move(init), subtype);
 | 
			
		||||
        res.m_value = binary_t(std::move(init), subtype);
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -18463,13 +18509,13 @@ class basic_json
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /// get a pointer to the value (binary)
 | 
			
		||||
    internal_binary_t* get_impl_ptr(internal_binary_t* /*unused*/) noexcept
 | 
			
		||||
    binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return is_binary() ? m_value.binary : nullptr;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// get a pointer to the value (binary)
 | 
			
		||||
    constexpr const internal_binary_t* get_impl_ptr(const internal_binary_t* /*unused*/) const noexcept
 | 
			
		||||
    constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return is_binary() ? m_value.binary : nullptr;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -18899,6 +18945,36 @@ class basic_json
 | 
			
		|||
        return get<ValueType>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @return reference to the binary value
 | 
			
		||||
 | 
			
		||||
    @throw type_error.302 if the value is not binary
 | 
			
		||||
 | 
			
		||||
    @sa @ref is_binary() to check if the value is binary
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    binary_t& get_binary()
 | 
			
		||||
    {
 | 
			
		||||
        if (not is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name())));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return *get_ptr<binary_t*>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @copydoc get_binary()
 | 
			
		||||
    const binary_t& get_binary() const
 | 
			
		||||
    {
 | 
			
		||||
        if (not is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name())));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return *get_ptr<const binary_t*>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -19521,118 +19597,6 @@ class basic_json
 | 
			
		|||
        return value(ptr, string_t(default_value));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief return the binary subtype
 | 
			
		||||
 | 
			
		||||
    Returns the numerical subtype of the JSON value, if the JSON value is of
 | 
			
		||||
    type "binary", and it has a subtype.  If it does not have a subtype (or the
 | 
			
		||||
    object is not of type binary) this function will return size_t(-1) as a
 | 
			
		||||
    sentinel value.
 | 
			
		||||
 | 
			
		||||
    @return the numerical subtype of the binary JSON value
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    std::size_t get_subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if (is_binary() and m_value.binary->has_subtype)
 | 
			
		||||
        {
 | 
			
		||||
            return m_value.binary->subtype;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return std::size_t(-1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief sets the binary subtype
 | 
			
		||||
 | 
			
		||||
    Sets the binary subtype of the JSON value, also flags a binary JSON value as
 | 
			
		||||
    having a subtype, which has implications for serialization to msgpack (will
 | 
			
		||||
    prefer ext file formats over bin).  If the JSON value is not a binary value,
 | 
			
		||||
    this function does nothing.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref get_subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    void set_subtype(std::uint8_t subtype) noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if (is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            m_value.binary->set_subtype(subtype);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    Clears the binary subtype of the JSON value, also flags a binary JSON value
 | 
			
		||||
    as not having a subtype, which has implications for serialization to msgpack
 | 
			
		||||
    (will prefer bin file formats over ext).  If the JSON value is not a binary
 | 
			
		||||
    value, this function does nothing.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref get_subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref has_subtype() -- returns whether or not the binary value has a
 | 
			
		||||
    subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    void clear_subtype() noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if (is_binary())
 | 
			
		||||
        {
 | 
			
		||||
            m_value.binary->clear_subtype();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief return whether or not the binary subtype has a value
 | 
			
		||||
 | 
			
		||||
    Returns whether or not the binary subtype has a value.
 | 
			
		||||
 | 
			
		||||
    @return whether or not the binary subtype has a value.
 | 
			
		||||
 | 
			
		||||
    @complexity Constant.
 | 
			
		||||
 | 
			
		||||
    @exceptionsafety No-throw guarantee: this member function never throws
 | 
			
		||||
    exceptions.
 | 
			
		||||
 | 
			
		||||
    @sa @ref get_subtype() -- return the binary subtype
 | 
			
		||||
    @sa @ref set_subtype() -- sets the binary subtype
 | 
			
		||||
    @sa @ref clear_subtype() -- clears the binary subtype
 | 
			
		||||
 | 
			
		||||
    @since version 3.8.0
 | 
			
		||||
    */
 | 
			
		||||
    bool has_subtype() const noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return is_binary() and m_value.binary->has_subtype();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
    @brief access the first element
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -19802,7 +19766,7 @@ class basic_json
 | 
			
		|||
                }
 | 
			
		||||
                else if (is_binary())
 | 
			
		||||
                {
 | 
			
		||||
                    AllocatorType<internal_binary_t> alloc;
 | 
			
		||||
                    AllocatorType<binary_t> alloc;
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
 | 
			
		||||
                    m_value.binary = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			@ -19916,7 +19880,7 @@ class basic_json
 | 
			
		|||
                }
 | 
			
		||||
                else if (is_binary())
 | 
			
		||||
                {
 | 
			
		||||
                    AllocatorType<internal_binary_t> alloc;
 | 
			
		||||
                    AllocatorType<binary_t> alloc;
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
 | 
			
		||||
                    std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
 | 
			
		||||
                    m_value.binary = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			@ -21756,6 +21720,20 @@ class basic_json
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @copydoc swap(binary_t)
 | 
			
		||||
    void swap(typename binary_t::container_type& other)
 | 
			
		||||
    {
 | 
			
		||||
        // swap only works for strings
 | 
			
		||||
        if (JSON_HEDLEY_LIKELY(is_binary()))
 | 
			
		||||
        {
 | 
			
		||||
            std::swap(*(m_value.binary), other);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name())));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @}
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,7 +77,7 @@ class SaxEventLogger
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(json::internal_binary_t& val)
 | 
			
		||||
    bool binary(json::binary_t& val)
 | 
			
		||||
    {
 | 
			
		||||
        std::string binary_contents = "binary(";
 | 
			
		||||
        std::string comma_space = "";
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +183,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
 | 
			
		|||
        return events_left-- > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(json::internal_binary_t&) override
 | 
			
		||||
    bool binary(json::binary_t&) override
 | 
			
		||||
    {
 | 
			
		||||
        return events_left-- > 0;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -485,14 +485,14 @@ TEST_CASE("constructors")
 | 
			
		|||
    {
 | 
			
		||||
        SECTION("empty binary")
 | 
			
		||||
        {
 | 
			
		||||
            json::internal_binary_t b{};
 | 
			
		||||
            json::binary_t b{};
 | 
			
		||||
            json j(b);
 | 
			
		||||
            CHECK(j.type() == json::value_t::binary);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        SECTION("filled binary")
 | 
			
		||||
        {
 | 
			
		||||
            json::internal_binary_t b({1, 2, 3});
 | 
			
		||||
            json::binary_t b({1, 2, 3});
 | 
			
		||||
            json j(b);
 | 
			
		||||
            CHECK(j.type() == json::value_t::binary);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool binary(json::internal_binary_t& val) override
 | 
			
		||||
    bool binary(json::binary_t& val) override
 | 
			
		||||
    {
 | 
			
		||||
        std::string binary_contents = "binary(";
 | 
			
		||||
        std::string comma_space = "";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -968,21 +968,35 @@ TEST_CASE("modifiers")
 | 
			
		|||
            SECTION("binary_t type")
 | 
			
		||||
            {
 | 
			
		||||
                json j = json::binary_array({1, 2, 3, 4});
 | 
			
		||||
                json::binary_t s = {1, 2, 3, 4};
 | 
			
		||||
                json::binary_t s = {{5, 6, 7, 8}};
 | 
			
		||||
 | 
			
		||||
                j.swap(s);
 | 
			
		||||
 | 
			
		||||
                CHECK(j == json::binary_array({1, 2, 3, 4}));
 | 
			
		||||
                CHECK(j == json::binary_array({5, 6, 7, 8}));
 | 
			
		||||
 | 
			
		||||
                j.swap(s);
 | 
			
		||||
 | 
			
		||||
                CHECK(j == json::binary_array({1, 2, 3, 4}));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            SECTION("non-string_t type")
 | 
			
		||||
            SECTION("binary_t::container_type type")
 | 
			
		||||
            {
 | 
			
		||||
                json j = json::binary_array({1, 2, 3, 4});
 | 
			
		||||
                std::vector<std::uint8_t> s = {{5, 6, 7, 8}};
 | 
			
		||||
 | 
			
		||||
                j.swap(s);
 | 
			
		||||
 | 
			
		||||
                CHECK(j == json::binary_array({5, 6, 7, 8}));
 | 
			
		||||
 | 
			
		||||
                j.swap(s);
 | 
			
		||||
 | 
			
		||||
                CHECK(j == json::binary_array({1, 2, 3, 4}));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            SECTION("non-binary_t type")
 | 
			
		||||
            {
 | 
			
		||||
                json j = 17;
 | 
			
		||||
                json::binary_t s = {1, 2, 3, 4};
 | 
			
		||||
                json::binary_t s = {{1, 2, 3, 4}};
 | 
			
		||||
 | 
			
		||||
                CHECK_THROWS_AS(j.swap(s), json::type_error&);
 | 
			
		||||
                CHECK_THROWS_WITH(j.swap(s), "[json.exception.type_error.310] cannot use swap() with number");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1134,7 +1134,7 @@ TEST_CASE("MessagePack")
 | 
			
		|||
                    const auto s = std::vector<uint8_t>(N, 'x');
 | 
			
		||||
                    json j = json::binary_array(s);
 | 
			
		||||
                    std::uint8_t subtype = 42;
 | 
			
		||||
                    j.set_subtype(subtype);
 | 
			
		||||
                    j.get_binary().set_subtype(subtype);
 | 
			
		||||
 | 
			
		||||
                    // create expected byte vector
 | 
			
		||||
                    std::vector<uint8_t> expected;
 | 
			
		||||
| 
						 | 
				
			
			@ -1209,7 +1209,7 @@ TEST_CASE("MessagePack")
 | 
			
		|||
                    const auto s = std::vector<uint8_t>(N, 'x');
 | 
			
		||||
                    json j = json::binary_array(s);
 | 
			
		||||
                    std::uint8_t subtype = 42;
 | 
			
		||||
                    j.set_subtype(subtype);
 | 
			
		||||
                    j.get_binary().set_subtype(subtype);
 | 
			
		||||
 | 
			
		||||
                    // create expected byte vector (hack: create string first)
 | 
			
		||||
                    std::vector<uint8_t> expected(N, 'x');
 | 
			
		||||
| 
						 | 
				
			
			@ -1245,7 +1245,7 @@ TEST_CASE("MessagePack")
 | 
			
		|||
                    const auto s = std::vector<uint8_t>(N, 'x');
 | 
			
		||||
                    json j = json::binary_array(s);
 | 
			
		||||
                    std::uint8_t subtype = 42;
 | 
			
		||||
                    j.set_subtype(subtype);
 | 
			
		||||
                    j.get_binary().set_subtype(subtype);
 | 
			
		||||
 | 
			
		||||
                    // create expected byte vector (hack: create string first)
 | 
			
		||||
                    std::vector<uint8_t> expected(N, 'x');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,7 +60,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const object_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +89,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to array_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -118,7 +118,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const array_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -147,7 +147,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to string_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +176,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const string_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -205,7 +205,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to boolean_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +234,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const boolean_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -263,7 +263,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to number_integer_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -292,7 +292,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const number_integer_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -321,7 +321,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to number_unsigned_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -350,7 +350,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const number_unsigned_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -379,7 +379,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to number_float_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -408,7 +408,7 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::number_float_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const number_float_t")
 | 
			
		||||
| 
						 | 
				
			
			@ -437,12 +437,12 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const internal_binary_t")
 | 
			
		||||
    SECTION("pointer access to const binary_t")
 | 
			
		||||
    {
 | 
			
		||||
        using test_type = const json::internal_binary_t;
 | 
			
		||||
        using test_type = const json::binary_t;
 | 
			
		||||
        const json value = json::binary_array({1, 2, 3});
 | 
			
		||||
 | 
			
		||||
        // check if pointers are returned correctly
 | 
			
		||||
| 
						 | 
				
			
			@ -466,12 +466,12 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("pointer access to const internal_binary_t")
 | 
			
		||||
    SECTION("pointer access to const binary_t")
 | 
			
		||||
    {
 | 
			
		||||
        using test_type = const json::internal_binary_t;
 | 
			
		||||
        using test_type = const json::binary_t;
 | 
			
		||||
        const json value = json::binary_array({});
 | 
			
		||||
 | 
			
		||||
        // check if pointers are returned correctly
 | 
			
		||||
| 
						 | 
				
			
			@ -495,6 +495,6 @@ TEST_CASE("pointer access")
 | 
			
		|||
        CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::internal_binary_t*>() != nullptr);
 | 
			
		||||
        CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue