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

Detailed Description

Outline

Purpose

Provide functions to encode and decode simple types in BER format.

Classes

See also
balber_berencoder, balber_berdecoder

Description

This component provides utility functions for encoding and decoding of primitive BER constructs, such as tag identifier octets, length octets, fundamental C++ types. The encoding and decoding of bsl::string and BDE date/time types is also implemented. For bsl::string_view and bslstl::StringRef types only encoding is supported.

These utility functions operate on bsl::streambuf for buffer management.

More information about BER constructs can be found in the BER specification (X.690). A copy of the specification can be found at the URL:

Note that this is a low-level component that only encodes and decodes primitive constructs. Clients should use the balber_berencoder and balber_berdecoder components (which use this component in the implementation) to encode and decode well-formed BER messages.

Terminology

The documentation of this component occasionally uses the following terminology as shorthand:

date-and-time type: A data type provided by BDE for the representation of a date and/or time value. The date-and-time types are: bdlt::Date, bdlt::DateTz, bdlt::Datetime, bdlt::DatetimeTz, bdlt::Time, and bdlt::TimeTz. Note that under this definition, the time-zone-aware types provided by BDE, such as baltzo::LocalDatetime, are not date-and-time types.

date-and-time value: The value associated with an object of a date-and-time type.

Usage

This section illustrates intended use of this component.

Example 1: Reading and Writing Identifier Octets

The following snippets of code illustrate the usage of this component. Due to the low-level nature of this component, an extended usage example is not necessary.

Suppose we wanted to write the identifier octets for a BER tag having the following properties:

Tag Class: Context-specific
Tag Type: Primitive
Tag Number: 31

According to the BER specification, this should generate two octets containing the values 0x9F and 0x1F. The following function demonstrates this:

int tagNumber = 31;
tagClass,
tagType,
tagNumber);
assert(0 == retCode);
assert(2 == osb.length());
assert(0x9F == (unsigned char)osb.data()[0]);
assert(0x1F == (unsigned char)osb.data()[1]);
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
const char * data() const
Definition bdlsb_memoutstreambuf.h:394
TagType
Definition balber_berconstants.h:113
@ e_PRIMITIVE
Definition balber_berconstants.h:116
TagClass
Definition balber_berconstants.h:92
@ e_CONTEXT_SPECIFIC
Definition balber_berconstants.h:97
static int putIdentifierOctets(bsl::streambuf *streamBuf, BerConstants::TagClass tagClass, BerConstants::TagType tagType, int tagNumber)

The next part of the function will read the identifier octets from the stream and verify its contents:

int tagNumberIn;
int numBytesConsumed = 0;
&tagClassIn,
&tagTypeIn,
&tagNumberIn,
&numBytesConsumed);
assert(0 == retCode);
assert(2 == numBytesConsumed);
assert(tagClass == tagClassIn);
assert(tagType == tagTypeIn);
assert(tagNumber == tagNumberIn);
Definition bdlsb_fixedmeminstreambuf.h:187
static int getIdentifierOctets(bsl::streambuf *streamBuf, BerConstants::TagClass *tagClass, BerConstants::TagType *tagType, int *tagNumber, int *accumNumBytesConsumed)