Quick Links: |
#include <baljsn_encoder.h>
Public Member Functions | |
Encoder (bslma::Allocator *basicAllocator=0) | |
~Encoder () | |
template<class TYPE > | |
int | encode (bsl::streambuf *streamBuf, const TYPE &value, const EncoderOptions &options) |
template<class TYPE > | |
int | encode (bsl::streambuf *streamBuf, const TYPE &value, const EncoderOptions *options) |
template<class TYPE > | |
int | encode (bsl::ostream &stream, const TYPE &value, const EncoderOptions &options) |
template<class TYPE > | |
int | encode (bsl::ostream &stream, const TYPE &value, const EncoderOptions *options) |
template<class TYPE > | |
int | encode (bsl::streambuf *streamBuf, const TYPE &value) |
template<class TYPE > | |
int | encode (bsl::ostream &stream, const TYPE &value) |
bsl::string | loggedMessages () const |
This class provides a mechanism for encoding value-semantic objects in the JSON format. The encode
methods are function templates that will encode any object that meets the requirements of a sequence, choice, or array object as defined in the bdlat_sequencefunctions
, bdlat_choicefunctions
, and bdlat_choicefunctions
components respectively. These generic frameworks provide a common compile-time interface for accessing struct-like and union-like objects. In particular, the types generated by bas_codegen.pl
provide the necessary interface and can be encoded using this component.
baljsn::Encoder::Encoder | ( | bslma::Allocator * | basicAllocator = 0 |
) | [explicit] |
Create a encoder object. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
baljsn::Encoder::~Encoder | ( | ) |
Destroy this object.
int baljsn::Encoder::encode | ( | bsl::streambuf * | streamBuf, | |
const TYPE & | value, | |||
const EncoderOptions & | options | |||
) |
int baljsn::Encoder::encode | ( | bsl::streambuf * | streamBuf, | |
const TYPE & | value, | |||
const EncoderOptions * | options | |||
) |
Encode the specified value
, of (template parameter) TYPE
, in the JSON format using the specified options
and output it onto the specified streamBuf
. Specifying a nullptr options
is equivalent to passing a default-constructed DecoderOptions in options
. TYPE
shall be a bdlat
-compatible sequence, choice, or array type, or a bdlat
-compatible dynamic type referring to one of those types. Return 0 on success, and a non-zero value otherwise.
int baljsn::Encoder::encode | ( | bsl::ostream & | stream, | |
const TYPE & | value, | |||
const EncoderOptions & | options | |||
) |
int baljsn::Encoder::encode | ( | bsl::ostream & | stream, | |
const TYPE & | value, | |||
const EncoderOptions * | options | |||
) |
Encode the specified value
, of (template parameter) TYPE
, in the JSON format using the specified options
and output it onto the specified stream
. Specifying a nullptr options
is equivalent to passing a default-constructed DecoderOptions in options
. TYPE
shall be a bdlat
-compatible choice, or array type, or a bdlat
-compatible dynamic type referring to one of those types. Return 0 on success, and a non-zero value otherwise.
int baljsn::Encoder::encode | ( | bsl::streambuf * | streamBuf, | |
const TYPE & | value | |||
) |
Encode the specified value
of (template parameter) TYPE
into the specified streamBuf
. Return 0 on success, and a non-zero value otherwise.
DEPRECATED: Use the encode
function passed a reference to a non-modifiable EncoderOptions
object instead.
int baljsn::Encoder::encode | ( | bsl::ostream & | stream, | |
const TYPE & | value | |||
) |
Encode the specified value
of (template parameter) TYPE
into the specified stream
. Return 0 on success, and a non-zero value otherwise. Note that stream
will be invalidated if the encoding failed.
DEPRECATED: Use the encode
function passed a reference to a non-modifiable EncoderOptions
object instead.
bsl::string baljsn::Encoder::loggedMessages | ( | ) | const |
Return a string containing any error, warning, or trace messages that were logged during the last call to the encode
method. The log is reset each time encode
is called.