BRL-CAD
|
Routines to translate data formats. More...
Modules | |
Network Data Sizes | |
Conversion Bit Masks | |
Conversion Defines | |
Base64 Encoding and Decoding | |
Network Byte-order Conversion | |
Files | |
file | cv.h |
Macros | |
#define | ntohll(_val) |
#define | htonll(_val) ntohll(_val) |
Functions | |
size_t | bu_cv (void *out, char *outfmt, size_t size, void *in, char *infmt, size_t count) |
int | bu_cv_cookie (const char *in) |
int | bu_cv_optimize (int cookie) |
size_t | bu_cv_itemlen (int cookie) |
size_t | bu_cv_w_cookie (void *out, int outcookie, size_t size, void *in, int incookie, size_t count) |
Routines to translate data formats.
The data formats are:
The method of conversion is to convert up to double then back down the the expected output format.
Also included are library routines for conversion between the local host 64-bit ("double precision") representation, and 64-bit IEEE double precision representation, in "network order", i.e., big-endian, the MSB in byte [0], on the left.
As a quick review, the IEEE double precision format is as follows: sign bit, 11 bits of exponent (bias 1023), and 52 bits of mantissa, with a hidden leading one (0.1 binary).
When the exponent is 0, IEEE defines a "denormalized number", which is not supported here.
When the exponent is 2047 (all bits set), and: all mantissa bits are zero, value is infinity*sign, mantissa is non-zero, and: msb of mantissa=0: signaling NAN msb of mantissa=1: quiet NAN
Note that neither the input or output buffers need be word aligned, for greatest flexibility in converting data, even though this imposes a speed penalty here.
These subroutines operate on a sequential block of numbers, to save on subroutine linkage execution costs, and to allow some hope for vectorization.
On brain-damaged machines like the SGI 3-D, where type "double" allocates only 4 bytes of space, these routines still return 8 bytes in the IEEE buffer.
The base64 encoding algorithm is an adaptation of the libb64 project - for details, see http://sourceforge.net/projects/libb64
#define ntohll | ( | _val | ) |
provide for 64-bit network/host conversions using ntohl()
size_t bu_cv | ( | void * | out, |
char * | outfmt, | ||
size_t | size, | ||
void * | in, | ||
char * | infmt, | ||
size_t | count | ||
) |
convert from one format to another.
in | input pointer |
out | output pointer |
count | number of entries to convert |
size | size of output buffer |
infmt | input format |
outfmt | output format |
int bu_cv_cookie | ( | const char * | in | ) |
Sets a bit vector after parsing an input string.
Set up the conversion tables/flags for vert.
in | format description. |
Format description: [channels][h|n][s|u] c|s|i|l|d|8|16|32|64 [N|C|L]
channels must be null or 1
Host | Network
signed | unsigned
char | short | integer | long | double | number of bits of integer
Normalize | Clip | low-order
int bu_cv_optimize | ( | int | cookie | ) |
It is always more efficient to handle host data, rather than network. If host and network formats are the same, and the request was for network format, modify the cookie to request host format.
size_t bu_cv_itemlen | ( | int | cookie | ) |
Returns the number of bytes each "item" of type "cookie" occupies.
size_t bu_cv_w_cookie | ( | void * | out, |
int | outcookie, | ||
size_t | size, | ||
void * | in, | ||
int | incookie, | ||
size_t | count | ||
) |
convert with cookie
in | input pointer |
incookie | input format cookie. |
count | number of entries to convert. |
out | output pointer. |
outcookie | output format cookie. |
size | size of output buffer in bytes; |
A worst case would be: ns16 on vax to ns32
The worst case is probably the easiest to deal with because all steps are done. The more difficult cases are when only a subset of steps need to be done.