BDE 4.39.x Production Release
Loading...
Searching...
No Matches
balber_berutil

Detailed Description

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

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:

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:419
const char * data() const
Definition bdlsb_memoutstreambuf.h:413
TagType
Definition balber_berconstants.h:117
@ e_PRIMITIVE
Definition balber_berconstants.h:120
TagClass
Definition balber_berconstants.h:96
@ e_CONTEXT_SPECIFIC
Definition balber_berconstants.h:101
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)