BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baljsn::Decoder Class Reference

#include <baljsn_decoder.h>

Public Member Functions

 Decoder (bslma::Allocator *basicAllocator=0)
 
template<class TYPE >
int decode (bsl::streambuf *streamBuf, TYPE *value, const DecoderOptions &options)
 
template<class TYPE >
int decode (bsl::streambuf *streamBuf, TYPE *value, const DecoderOptions *options)
 
template<class TYPE >
int decode (bsl::istream &stream, TYPE *value, const DecoderOptions &options)
 
template<class TYPE >
int decode (bsl::istream &stream, TYPE *value, const DecoderOptions *options)
 
template<class TYPE >
int decode (bsl::streambuf *streamBuf, TYPE *value)
 
template<class TYPE >
int decode (bsl::istream &stream, TYPE *value)
 
bsl::string loggedMessages () const
 

Friends

struct Decoder_DecodeImpProxy
 
struct Decoder_ElementVisitor
 

Detailed Description

This class provides a mechanism for decoding JSON data into value-semantic objects. The decode methods are function templates that will decode 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 manipulating struct-like and union-like objects. In particular, the types generated by bas_codegen.pl provide the necessary interface and can be decoded using this component.

See baljsn_decoder

Constructor & Destructor Documentation

◆ Decoder()

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

Construct a decoder object using the optionally specified basicAllocator. If basicAllocator is 0, the default allocator is used.

Member Function Documentation

◆ decode() [1/6]

template<class TYPE >
int baljsn::Decoder::decode ( bsl::istream &  stream,
TYPE *  value 
)

Decode an object of (template parameter) TYPE from the specified stream and load the result into the specified modifiable value. Return 0 on success, and a non-zero value otherwise. Note that stream will be invalidated if the decoding fails.

Deprecated:
Use decode function passed a reference to a non-modifiable DecoderOptions object instead.

◆ decode() [2/6]

template<class TYPE >
int baljsn::Decoder::decode ( bsl::istream &  stream,
TYPE *  value,
const DecoderOptions options 
)

Decode into the specified value, of a (template parameter) TYPE, the JSON data read from the specified stream and using the specified options. TYPE shall be a bdeat-compatible sequence, choice, or array type, or a bdeat-compatible dynamic type referring to one of those types. Specifying a nullptr options is equivalent to passing a default-constructed DecoderOptions in options. Return 0 on success, and a non-zero value otherwise. Note that this operation internally buffers input from stream, and if decoding is successful, will attempt to update the input position of stream to the last unprocessed byte.

◆ decode() [3/6]

template<class TYPE >
int baljsn::Decoder::decode ( bsl::istream &  stream,
TYPE *  value,
const DecoderOptions options 
)

◆ decode() [4/6]

template<class TYPE >
int baljsn::Decoder::decode ( bsl::streambuf *  streamBuf,
TYPE *  value 
)

Decode an object of (template parameter) TYPE from the specified streamBuf and load the result into the specified modifiable value. Return 0 on success, and a non-zero value otherwise.

Deprecated:
Use decode function passed a reference to a non-modifiable DecoderOptions object instead.

◆ decode() [5/6]

template<class TYPE >
int baljsn::Decoder::decode ( bsl::streambuf *  streamBuf,
TYPE *  value,
const DecoderOptions options 
)

Decode into the specified value, of a (template parameter) TYPE, the JSON data read from the specified streamBuf and using the specified options. Specifying a nullptr options is equivalent to passing a default-constructed DecoderOptions in options. TYPE shall be a bdeat-compatible sequence, choice, or array type, or a bdeat-compatible dynamic type referring to one of those types. Return 0 on success, and a non-zero value otherwise. Note that this operation internally buffers input from streambuf, and if decoding is successful, will attempt to update the input position of streambuf to the last unprocessed byte.

◆ decode() [6/6]

template<class TYPE >
int baljsn::Decoder::decode ( bsl::streambuf *  streamBuf,
TYPE *  value,
const DecoderOptions options 
)

◆ loggedMessages()

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

Return a string containing any error, warning, or trace messages that were logged during the last call to the decode method. The log is reset each time decode is called.

Friends And Related Symbol Documentation

◆ Decoder_DecodeImpProxy

friend struct Decoder_DecodeImpProxy
friend

◆ Decoder_ElementVisitor

friend struct Decoder_ElementVisitor
friend

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