#include <baljsn_decoder.h>
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
|
| | 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) |
| |
| template<class TYPE > |
| int | decodeAny (bsl::streambuf *streamBuf, TYPE *value, const DecoderOptions &options) |
| |
| template<class TYPE > |
| int | decodeAny (bsl::streambuf *streamBuf, TYPE *value, const DecoderOptions *options=0) |
| |
| int | decodeAny (bsl::streambuf *streamBuf, bdlar::AnyRef *value, const DecoderOptions &options) |
| |
| template<class TYPE > |
| int | decodeAny (bsl::istream &stream, TYPE *value, const DecoderOptions &options) |
| |
| template<class TYPE > |
| int | decodeAny (bsl::istream &stream, TYPE *value, const DecoderOptions *options=0) |
| |
| int | decodeAny (bsl::istream &stream, bdlar::AnyRef *value, const DecoderOptions &options) |
| |
| bsl::string | loggedMessages () const |
| |
| int | numUnknownElementsSkipped () const |
| |
◆ Decoder()
Construct a decoder object using the optionally specified basicAllocator. If basicAllocator is 0, the default allocator is used.
◆ 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
- 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
- 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
- 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 |
|
) |
| |
◆ decodeAny() [1/6]
◆ decodeAny() [2/6]
template<class TYPE >
| int baljsn::Decoder::decodeAny |
( |
bsl::istream & |
stream, |
|
|
TYPE * |
value, |
|
|
const DecoderOptions & |
options |
|
) |
| |
|
inline |
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 bdlat-compatible sequence, choice, or array type, or a bdlat-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
- Note that this function behaves identically to
decode, 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.
◆ decodeAny() [3/6]
template<class TYPE >
| int baljsn::Decoder::decodeAny |
( |
bsl::istream & |
stream, |
|
|
TYPE * |
value, |
|
|
const DecoderOptions * |
options = 0 |
|
) |
| |
|
inline |
◆ decodeAny() [4/6]
◆ decodeAny() [5/6]
template<class TYPE >
| int baljsn::Decoder::decodeAny |
( |
bsl::streambuf * |
streamBuf, |
|
|
TYPE * |
value, |
|
|
const DecoderOptions & |
options |
|
) |
| |
|
inline |
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 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
decode, 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.
◆ decodeAny() [6/6]
template<class TYPE >
| int baljsn::Decoder::decodeAny |
( |
bsl::streambuf * |
streamBuf, |
|
|
TYPE * |
value, |
|
|
const DecoderOptions * |
options = 0 |
|
) |
| |
|
inline |
◆ loggedMessages()
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.
◆ numUnknownElementsSkipped()
| int baljsn::Decoder::numUnknownElementsSkipped |
( |
| ) |
const |
|
inline |
Return the number of unknown elements that were skipped during the previous decoding operation.
- Note
- Note that unknown elements are skipped only if
options.skipUnknownElements() == true.
◆ Decoder_DecodeImpProxy
◆ Decoder_ElementVisitor
The documentation for this class was generated from the following file: