BRL-CAD

Routines to translate data formats. More...

Collaboration diagram for Data Conversion:

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)
 

Detailed Description

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

Macro Definition Documentation

◆ ntohll

#define ntohll (   _val)
Value:
((((uint64_t)ntohl((_val))) << 32) + ntohl((_val) >> 32)) : \
(_val)) /* sorry pdp-endian */
uint32_t ntohl(uint32_t)
bu_endian_t bu_byteorder(void)
@ BU_LITTLE_ENDIAN
Definition: endian.h:39

provide for 64-bit network/host conversions using ntohl()

Definition at line 157 of file cv.h.

◆ htonll

#define htonll (   _val)    ntohll(_val)

Definition at line 162 of file cv.h.

Function Documentation

◆ bu_cv()

size_t bu_cv ( void *  out,
char *  outfmt,
size_t  size,
void *  in,
char *  infmt,
size_t  count 
)

convert from one format to another.

Parameters
ininput pointer
outoutput pointer
countnumber of entries to convert
sizesize of output buffer
infmtinput format
outfmtoutput format

◆ bu_cv_cookie()

int bu_cv_cookie ( const char *  in)

Sets a bit vector after parsing an input string.

Set up the conversion tables/flags for vert.

Parameters
informat description.
Returns
a 32 bit vector.

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

◆ bu_cv_optimize()

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.

◆ bu_cv_itemlen()

size_t bu_cv_itemlen ( int  cookie)

Returns the number of bytes each "item" of type "cookie" occupies.

◆ bu_cv_w_cookie()

size_t bu_cv_w_cookie ( void *  out,
int  outcookie,
size_t  size,
void *  in,
int  incookie,
size_t  count 
)

convert with cookie

Parameters
ininput pointer
incookieinput format cookie.
countnumber of entries to convert.
outoutput pointer.
outcookieoutput format cookie.
sizesize of output buffer in bytes;

A worst case would be: ns16 on vax to ns32

ns16 -> hs16
-> hd
-> hs32
-> 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.

Method:
HOSTDBL defined as true or false
if ! hostother then
hostother = (Endian == END_BIG) ? SAME : DIFFERENT;
fi
if (infmt == double) then
if (HOSTDBL == SAME) {
inIsHost = host;
fi
else
if (hostother == SAME) {
inIsHost = host;
fi
fi
if (outfmt == double) then
if (HOSTDBL == SAME) {
outIsHost == host;
else
if (hostother == SAME) {
outIsHost = host;
fi
fi
if (infmt == outfmt) {
if (inIsHost == outIsHost) {
copy(in, out)
exit
else if (inIsHost == net) {
ntoh?(in, out);
exit
else
hton?(in, out);
exit
fi
fi
while not done {
from = in;
if (inIsHost == net) {
ntoh?(from, t1);
from = t1;
fi
if (infmt != double) {
if (outIsHost == host) {
to = out;
else
to = t2;
fi
castdbl(from, to);
from = to;
fi
if (outfmt == double) {
if (outIsHost == net) {
hton?(from, out);
fi
else
if (outIsHost == host) {
dblcast(from, out);
else
dblcast(from, t3);
hton?(t3, out);
fi
fi
done
#define END_BIG
Definition: cv.h:137