Skip to content

Commit

Permalink
Add documentation regarding direct RapidJSON usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Jun 29, 2020
1 parent 1e95c3d commit 1970145
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The following table shows the mapping of supported C++ types to supported JSON t
* The binary (de)serializer supports approximately the same C++ types but obviously maps them to a platform
independent binary representation rather than a JSON type.


## Usage
This example shows how the library can be used to make a `struct` serializable:
<pre>
Expand Down Expand Up @@ -143,6 +144,22 @@ There are further arguments available, see:
reflective_rapidjson_generator --help
</pre>

### Mixing with direct RapidJSON usage and further notes
It is of course possible to mix automatic serialization/deserialization with direct RapidJSON usage. This can be
done by invoking the `push` and `pull` functions within the `ReflectiveRapidJSON::JsonReflector` namespace directly.

The `push` functions are used on serialization to populate intermediate data structures for the serializer of the
RapidJSON library. The intermediate JSON document can also easily be obtained via
`JsonSerializable<Type>::toJsonDocument()`.

Note that this means a copy of the provided data will be made. That includes all strings as well. Currently there
is no way to use RapidJSON's copy-free `SetString`-overloads instead. As a consequence the mentioned intermediate
JSON document can be serialized without causing any further read accesses to the actual data structures.

The `pull` functions are used to populate your data structures from intermediate data structures produced by the
parser of RapidJSON. Also in this case a copy will be made so only owning data structures can be used when
deserializing (see remarks regarding supported datatypes).

#### Binary (de)serialization
It works very similar to the example above. Just use the `BinarySerializable` class instead (or in addition):

Expand Down

0 comments on commit 1970145

Please sign in to comment.