BDE 4.14.0 Production release
|
Support platform-independent marshalling of fundamental types.
This component provides a byte-array-based implementation, bslx::MarshallingUtil
, for a suite of marshalling functions used to convert values (and arrays of values) of the following fundamental integer and floating-point types:
In addition to basic marshalling functions, where each marshalled instance of a fundamental type occupies the same number of bytes in the stream (regardless of its value), this component provides an interface for efficient marshalling of integer types. In particular, 64-bit values can be streamed as 40-, 48-, 56-, or 64-bit values, and 32-bit values can be streamed as 24- or 32-bit values. Marshalled integers are written and assumed to be in two's complement, big-endian format (i.e., network byte order). Floating-point formats are described below.
The names and interfaces of the functions of bslx::MarshallingUtil
follow a systematic fashion explained below. This makes it easier to guess the name and signature of the intended function. In what follows, buffer
is always of type char *
or const char *
depending on whether it is used as an input or an output, and variable
and value
are of a type that depends on the name of the function and intended width, with variable
used as an output, while value
is used as an input.
Here are the get...
functions for integral and floating-point scalar types:
Here are the put...
functions for scalar types. Note that there is no putUintNN
since putIntNN
applies equally to unsigned NN
-bit values (through a conversion to a signed value):
Here are the getArray...
functions for integral and floating-point scalar array types:
Finally, the putArray...
functions follow. Note that this time there is an overload for unsigned types, but that the function name is still putArrayInt...
for arrays of both signed and unsigned integrals:
A double
is assumed to be at least 64 bits in size. The externalized byte representation of a 64-bit floating-point value is defined to conform to the IEEE double-precision format illustrated below. If the native representation of a 64-bit floating-point value does not match this format, a conversion process to and from this format is performed. This conversion may (of course) be lossy:
A float
is assumed to be at least 32 bits in size. The externalized byte representation of a 32-bit floating-point value is defined to conform to the IEEE single-precision format illustrated below. If the native representation of a 32-bit floating-point value does not match this format, a conversion process to and from this format is performed. This conversion may (of course) be lossy:
This section illustrates intended use of this component.
The bslx::MarshallingUtil
component can be used stand-alone to marshal a platform-neutral representation of fundamental data and arrays of fundamental data to and from a buffer. In this example, the round-trip marshalling of an int
and an array of int
values will be demonstrated. First, declare the buffer and the data to be marshalled:
Then, marshal all data into the buffer
:
Next, declare variables to hold the values to be extracted from the buffer
:
Finally, marshal the data from the buffer
to these variables and confirm the round-trip marshalling was successful: