BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balber_berdecoder

Functions

 balber::BerDecoder::MemOutStream::MemOutStream (bslma::Allocator *basicAllocator=0)
 
void balber::BerDecoder::MemOutStream::reset ()
 Reset the internal streambuf to the empty state.
 
const char * balber::BerDecoder::MemOutStream::data () const
 
int balber::BerDecoder::MemOutStream::length () const
 

Detailed Description

Outline

Purpose

Provide a BER decoder class.

Classes

See also
balber_berencoder, bdem_bdemdecoder, balxml_decoder

Description

This component defines a single class, balber::BerDecoder, that contains a parameterized decode function. The decode function decodes data read from a specified stream and loads the corresponding object to an object of the parameterized type. The decode method is overloaded for two types of input streams:

This class decodes objects based on the X.690 BER specification and is restricted to types supported by the bdlat framework.

Usage

This section illustrates intended use of this component.

Example 1: Decoding an Employee Record

Suppose that an "employee record" consists of a sequence of attributes – name, age, and salary – that are of types bsl::string, int, and float, respectively. Furthermore, we have a need to BER encode employee records as a sequence of values (for out-of-process consumption).

Assume that we have defined a usage::EmployeeRecord class to represent employee record values, and assume that we have provided the bdlat specializations that allow the balber codec components to represent class values as a sequence of BER primitive values. See {bdlat_sequencefunctions |Usage} for details of creating specializations for a sequence type.

First, we create an employee record object having typical values:

usage::EmployeeRecord bob("Bob", 56, 1234.00);
assert("Bob" == bob.name());
assert( 56 == bob.age());
assert(1234.00 == bob.salary());

Next, we create a balber::Encoder object and use it to encode our bob object. Here, to facilitate the examination of our results, the BER encoding data is delivered to a bslsb::MemOutStreamBuf object:

int rc = encoder.encode(&osb, bob);
assert( 0 == rc);
assert(18 == osb.length());
Definition balber_berencoder.h:248
int encode(bsl::streambuf *streamBuf, const TYPE &value)
Definition balber_berencoder.h:717
Definition bdlsb_memoutstreambuf.h:212
bsl::size_t length() const
Return the number of valid characters in this stream buffer.
Definition bdlsb_memoutstreambuf.h:400

Now, we create a bdlsb::FixedMemInStreamBuf object to manage our access to the data portion of the bdlsb::MemOutStreamBuf (where our BER encoding resides), decode the values found there, and use them to set the value of an usage::EmployeeRecord object.

balber::BerDecoder decoder(&options);
usage::EmployeeRecord obj;
rc = decoder.decode(&isb, &obj);
assert(0 == rc);
Definition balber_berdecoderoptions.h:76
Definition balber_berdecoder.h:172
Definition bdlsb_fixedmeminstreambuf.h:187
const char * data() const
Definition bdlsb_memoutstreambuf.h:394

Finally, we confirm that the object defined by the BER encoding has the same value as the original object.

assert(bob.name() == obj.name());
assert(bob.age() == obj.age());
assert(bob.salary() == obj.salary());

Function Documentation

◆ data()

const char * balber::BerDecoder::MemOutStream::data ( ) const
inline

Return a pointer to the memory containing the formatted values formatted to this stream. The data is not null-terminated unless a null character was appended onto this stream.

◆ length()

int balber::BerDecoder::MemOutStream::length ( ) const
inline

Return the length of the formatted data, including null characters appended to the stream, if any.

◆ MemOutStream()

balber::BerDecoder::MemOutStream::MemOutStream ( bslma::Allocator basicAllocator = 0)
inline

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

◆ reset()

void balber::BerDecoder::MemOutStream::reset ( )
inline