Skip to content

Commit

Permalink
rebase to add signoffs
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/mkdocs/docs/features/binary_formats/bson.md
#	docs/mkdocs/docs/home/exceptions.md
#	include/nlohmann/detail/output/binary_writer.hpp
#	single_include/nlohmann/json.hpp
#	tests/src/unit-bson.cpp
  • Loading branch information
slowriot committed Jan 10, 2025
1 parent 0b2f4b4 commit 5d0b29b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
9 changes: 7 additions & 2 deletions docs/mkdocs/docs/features/binary_formats/bson.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ representation of data types that are not part of the JSON spec. For example, BS

- [BSON Website](http://bsonspec.org) - the main source on BSON
- [BSON Specification](http://bsonspec.org/spec.html) - the specification


## Serialization

Expand Down Expand Up @@ -42,7 +42,7 @@ The library uses the following mapping from JSON values types to BSON types:
```cpp
--8<-- "examples/to_bson.cpp"
```

Output:

```c
Expand Down Expand Up @@ -93,3 +93,8 @@ The library maps BSON record types to JSON value types as follows:
```json
--8<-- "examples/from_bson.output"
```

!!! note "Handling of BSON type 0x11"

BSON type 0x11 is used to represent uint64 numbers. This library treats these values purely as uint64 numbers
and does not parse them into date-related formats.
22 changes: 11 additions & 11 deletions docs/mkdocs/docs/home/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ Note that [`JSON_THROW_USER`](../api/macros/json_throw_user.md) should leave the

```cpp
#include <iostream>

#define JSON_TRY_USER if(true)
#define JSON_CATCH_USER(exception) if(false)
#define JSON_THROW_USER(exception) \
{std::clog << "Error in " << __FILE__ << ":" << __LINE__ \
<< " (function " << __FUNCTION__ << ") - " \
<< (exception).what() << std::endl; \
std::abort();}

#include <nlohmann/json.hpp>
```

Expand All @@ -72,7 +72,7 @@ Exceptions in the library are thrown in the local context of the JSON value they
```cpp
--8<-- "examples/diagnostics_standard.cpp"
```

Output:

```
Expand All @@ -90,7 +90,7 @@ As this global context comes at the price of storing one additional pointer per
```cpp
--8<-- "examples/diagnostics_extended.cpp"
```

Output:

```
Expand Down Expand Up @@ -125,7 +125,7 @@ Exceptions have ids 1xx.
```cpp
--8<-- "examples/parse_error.cpp"
```

Output:

```
Expand Down Expand Up @@ -377,7 +377,7 @@ Exceptions have ids 2xx.
```cpp
--8<-- "examples/invalid_iterator.cpp"
```

Output:

```
Expand Down Expand Up @@ -541,7 +541,7 @@ Exceptions have ids 3xx.
```cpp
--8<-- "examples/type_error.cpp"
```

Output:

```
Expand Down Expand Up @@ -735,7 +735,7 @@ The `dump()` function only works with UTF-8 encoded strings; that is, if you ass

- Store the source file with UTF-8 encoding.
- Pass an error handler as last parameter to the `dump()` function to avoid this exception:
- `json::error_handler_t::replace` will replace invalid bytes sequences with `U+FFFD`
- `json::error_handler_t::replace` will replace invalid bytes sequences with `U+FFFD`
- `json::error_handler_t::ignore` will silently ignore invalid byte sequences

### json.exception.type_error.317
Expand Down Expand Up @@ -770,7 +770,7 @@ Exceptions have ids 4xx.
```cpp
--8<-- "examples/out_of_range.cpp"
```

Output:

```
Expand Down Expand Up @@ -849,7 +849,7 @@ UBJSON only supports integer numbers up to 9223372036854775807.

!!! note

Since version 3.9.0, integer numbers beyond int64 are serialized as high-precision UBJSON numbers, and this exception does not further occur.
Since version 3.9.0, integer numbers beyond int64 are serialized as high-precision UBJSON numbers, and this exception does not further occur.

### json.exception.out_of_range.408

Expand Down Expand Up @@ -885,7 +885,7 @@ Exceptions have ids 5xx.
```cpp
--8<-- "examples/other_error.cpp"
```

Output:

```
Expand Down
6 changes: 6 additions & 0 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ class binary_reader
return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
}

case 0x11: // uint64
{
std::uint64_t value{};
return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
}

default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
Expand Down
6 changes: 6 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10012,6 +10012,12 @@ class binary_reader
return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
}

case 0x11: // uint64
{
std::uint64_t value{};
return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
}

default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
Expand Down
8 changes: 2 additions & 6 deletions tests/src/unit-bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ TEST_CASE("BSON")

SECTION("Some more complex document")
{
// directly encoding uint64 is not supported in bson (only for timestamp values)
json const j =
{
{"double", 42.5},
Expand Down Expand Up @@ -1163,10 +1162,7 @@ TEST_CASE("BSON numerical data")
std::vector<std::uint64_t> const numbers
{
static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()) + 1ULL,
10000000000000000000ULL,
18000000000000000000ULL,
(std::numeric_limits<std::uint64_t>::max)() - 1ULL,
(std::numeric_limits<std::uint64_t>::max)(),
0xffffffffffffffff,
};

for (const auto i : numbers)
Expand Down Expand Up @@ -1202,7 +1198,7 @@ TEST_CASE("BSON numerical data")
auto j_roundtrip = json::from_bson(bson);

CHECK(j.at("entry").is_number_unsigned());
CHECK(j_roundtrip.at("entry").is_number_integer());
CHECK(j_roundtrip.at("entry").is_number_unsigned());
CHECK(j_roundtrip == j);
CHECK(json::from_bson(bson, true, false) == j);
}
Expand Down

0 comments on commit 5d0b29b

Please sign in to comment.