AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::codec::ProtobufJson Struct Reference

#include <protobuf.hpp>

Collaboration diagram for anch::codec::ProtobufJson:

Static Public Member Functions

static std::string_view mediaType () noexcept
template<anch::codec::ProtobufMessage T>
static void serialize (const T &value, std::ostream &out, anch::codec::Side side)
template<anch::codec::ProtobufMessage T>
static void deserialize (T &value, std::istream &input, anch::codec::Side side)
static std::string toJson (const google::protobuf::Message &message)
static void fromJson (google::protobuf::Message &message, std::string_view json, bool ignoreUnknownFields)

Detailed Description

application/json codec for protoc messages: Protocol Buffers JSON mapping (field names in lowerCamelCase, 64 bits integers as strings, ...). Unknown fields are refused on server side and ignored on client side (server responses are trusted). Invalid messages raise std::invalid_argument ( 400 on server side).

Author
Vincent Lachenal
Since
0.2

Member Function Documentation

◆ deserialize()

void anch::codec::ProtobufJson::deserialize ( T & value,
std::istream & input,
anch::codec::Side side )
static

Read message

Parameters
valuethe message to fill
inputthe input stream
sidethe side which reads message
Exceptions
std::invalid_argumentwhen message is invalid
ContentTooLargewhen body is larger than maxBodySize
Here is the call graph for this function:

◆ fromJson()

void anch::codec::ProtobufJson::fromJson ( google::protobuf::Message & message,
std::string_view json,
bool ignoreUnknownFields )
static

Read message from JSON

Parameters
messagethe message to fill
jsonthe JSON text
ignoreUnknownFieldsignore unknown fields
Exceptions
std::invalid_argumentwhen JSON is not a valid message
Here is the call graph for this function:

◆ mediaType()

std::string_view anch::codec::ProtobufJson::mediaType ( )
staticnoexcept

Media type

Returns
application/json

◆ serialize()

void anch::codec::ProtobufJson::serialize ( const T & value,
std::ostream & out,
anch::codec::Side side )
static

Write message

Parameters
valuethe message
outthe output stream
sidethe side which writes message
Exceptions
std::runtime_errorwhen message can not be written
Here is the call graph for this function:

◆ toJson()

std::string anch::codec::ProtobufJson::toJson ( const google::protobuf::Message & message)
static

Get JSON of a message

Parameters
messagethe message
Returns
the JSON text
Exceptions
std::runtime_errorwhen message can not be written
Here is the call graph for this function:

The documentation for this struct was generated from the following file: