jcrist · GitHub

@jcrist

`Raw` objects have two uses:
- During decoding, fields annotated with `Raw` won't be immediately
decoded. Instead, a `Raw` object will be created wrapping a view into
the larger message buffer where the respective field is encoded. This
can be useful for decoding fields whose type depends on other values in
the message (and where the builtin "tagged union" support is
insufficient). Note that for efficiency the `Raw` type provides a *view*
and not a *copy* of this data.
- During encoding. Some JSON responses contain some static data shared
between all objects - pre-encoding this data and wrapping it in `Raw`
can accelerate encoding, since the pre-encoded data can be appended to
the message with a simple `memcpy`. This is also useful for APIs
returning a response composed of already encoded objects (e.g. JSON data
read from a database), since this lets the application avoid decoding
and then re-encoding the objects again later.

Read the original on github.com ↗