BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn::Encoder Class Reference

#include <baljsn_encoder.h>

Detailed Description

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.

See baljsn_encoder

Public Member Functions

 Encoder (bslma::Allocator *basicAllocator=0)
 
 ~Encoder ()=default
 
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)
 
template<class TYPE >
int encodeAny (bsl::streambuf *streamBuf, const TYPE &value, const EncoderOptions &options)
 
template<class TYPE >
int encodeAny (bsl::streambuf *streamBuf, const TYPE &value, const EncoderOptions *options=0)
 
int encodeAny (bsl::streambuf *streamBuf, const bdlar::AnyConstRef &any, const EncoderOptions &options)
 
int encodeAny (bsl::streambuf *streamBuf, const bdlar::AnyConstRef &any, const EncoderOptions *options=0)
 
template<class TYPE >
int encodeAny (bsl::ostream &stream, const TYPE &value, const EncoderOptions &options)
 
template<class TYPE >
int encodeAny (bsl::ostream &stream, const TYPE &value, const EncoderOptions *options=0)
 
int encodeAny (bsl::ostream &stream, const bdlar::AnyConstRef &any, const EncoderOptions &options)
 
int encodeAny (bsl::ostream &stream, const bdlar::AnyConstRef &any, const EncoderOptions *options=0)
 
bsl::string loggedMessages () const
 

Constructor & Destructor Documentation

◆ Encoder()

baljsn::Encoder::Encoder ( bslma::Allocator basicAllocator = 0)
inlineexplicit

Create a encoder object. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~Encoder()

baljsn::Encoder::~Encoder ( )
default

Destroy this object.

Member Function Documentation

◆ encode() [1/6]

template<class TYPE >
int baljsn::Encoder::encode ( bsl::ostream &  stream,
const TYPE &  value 
)
inline

Encode the specified value of (template parameter) TYPE into the specified stream. Return 0 on success, and a non-zero value otherwise.

Note
Note that stream will be invalidated if the encoding failed.
Deprecated:
Use encode function passed a reference to a non-modifiable EncoderOptions object instead.

◆ encode() [2/6]

template<class TYPE >
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 EncoderOptions 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.

◆ encode() [3/6]

template<class TYPE >
int baljsn::Encoder::encode ( bsl::ostream &  stream,
const TYPE &  value,
const EncoderOptions options 
)
inline

◆ encode() [4/6]

template<class TYPE >
int baljsn::Encoder::encode ( bsl::streambuf *  streamBuf,
const TYPE &  value 
)
inline

Encode the specified value of (template parameter) TYPE into the specified streamBuf. Return 0 on success, and a non-zero value otherwise.

Deprecated:
Use encode function passed a reference to a non-modifiable EncoderOptions object instead.

◆ encode() [5/6]

template<class TYPE >
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 EncoderOptions 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.

◆ encode() [6/6]

template<class TYPE >
int baljsn::Encoder::encode ( bsl::streambuf *  streamBuf,
const TYPE &  value,
const EncoderOptions options 
)

◆ encodeAny() [1/8]

int baljsn::Encoder::encodeAny ( bsl::ostream &  stream,
const bdlar::AnyConstRef any,
const EncoderOptions options 
)

◆ encodeAny() [2/8]

int baljsn::Encoder::encodeAny ( bsl::ostream &  stream,
const bdlar::AnyConstRef any,
const EncoderOptions options = 0 
)
inline

◆ encodeAny() [3/8]

template<class TYPE >
int baljsn::Encoder::encodeAny ( bsl::ostream &  stream,
const TYPE &  value,
const EncoderOptions options 
)
inline

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.

Note
Note that this function behaves identically to encode, but does not instantiate any templates at compile time at the expense of being slightly slower at runtime; see the baljsn package documentation for more details.

◆ encodeAny() [4/8]

template<class TYPE >
int baljsn::Encoder::encodeAny ( bsl::ostream &  stream,
const TYPE &  value,
const EncoderOptions options = 0 
)
inline

◆ encodeAny() [5/8]

int baljsn::Encoder::encodeAny ( bsl::streambuf *  streamBuf,
const bdlar::AnyConstRef any,
const EncoderOptions options 
)

◆ encodeAny() [6/8]

int baljsn::Encoder::encodeAny ( bsl::streambuf *  streamBuf,
const bdlar::AnyConstRef any,
const EncoderOptions options = 0 
)
inline

◆ encodeAny() [7/8]

template<class TYPE >
int baljsn::Encoder::encodeAny ( bsl::streambuf *  streamBuf,
const TYPE &  value,
const EncoderOptions options 
)
inline

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.

Note
Note that this function behaves identically to encode, but does not instantiate any templates at compile time at the expense of being slightly slower at runtime; see the baljsn package documentation for more details.

◆ encodeAny() [8/8]

template<class TYPE >
int baljsn::Encoder::encodeAny ( bsl::streambuf *  streamBuf,
const TYPE &  value,
const EncoderOptions options = 0 
)
inline

◆ loggedMessages()

bsl::string baljsn::Encoder::loggedMessages ( ) const
inline

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.


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