parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
json_io.h File Reference

Stream / byte-span JSON I/O for cells. More...

#include <parcel/cell.h>
#include <parcel/error.h>
#include <parcel/json.h>
#include <parcel/registry.h>
#include <cstddef>
#include <span>
#include <string>
Include dependency graph for json_io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

cell_t parcel::cell_from_stream (std::istream &is, ParcelRegistry const &reg)
 Read one JSON document from is and dispatch via reg.
 
cell_t parcel::cell_from_bytes (const std::span< const std::byte > bytes, ParcelRegistry const &reg)
 Read raw bytes as JSON and dispatch via reg.
 
void parcel::cell_to_stream (std::ostream &os, cell_t const &c, const int indent=-1)
 Render c as JSON onto os.
 

Detailed Description

Stream / byte-span JSON I/O for cells.

Adds thin facades on top of ParcelRegistry::cell_from_json and ICell::to_json so callers don't have to do the std::string round-trip themselves. The non-throwing try_* overloads are wired in when <expected> is available.

Function Documentation

◆ cell_from_bytes()

cell_t parcel::cell_from_bytes ( const std::span< const std::byte >  bytes,
ParcelRegistry const &  reg 
)
inline

Read raw bytes as JSON and dispatch via reg.

Parameters
bytesUTF-8 JSON bytes.
regRegistry used to resolve the kind.
Exceptions
std::runtime_erroron parse failure or shape/kind mismatch.

◆ cell_from_stream()

cell_t parcel::cell_from_stream ( std::istream &  is,
ParcelRegistry const &  reg 
)
inline

Read one JSON document from is and dispatch via reg.

Parameters
isInput stream — read to EOF as a single JSON value.
regRegistry used to resolve the kind.
Returns
Newly built cell handle.
Exceptions
std::runtime_erroron parse failure or shape/kind mismatch.

◆ cell_to_stream()

void parcel::cell_to_stream ( std::ostream &  os,
cell_t const &  c,
const int  indent = -1 
)
inline

Render c as JSON onto os.

Parameters
osOutput stream.
cCell to dump (null → JSON null).
indent-1 for compact (default); non-negative for pretty.