BRL-CAD
Collaboration diagram for Data Conversion:

Files

file  convert.c
 
file  htond.c
 
file  htonf.c
 
file  b64.c
 

Macros

#define SIZEOF_NETWORK_SHORT   2 /* htons(), bu_gshort(), bu_pshort() */
 
#define SIZEOF_NETWORK_LONG   4 /* htonl(), bu_glong(), bu_plong() */
 
#define SIZEOF_NETWORK_FLOAT   4 /* htonf() */
 
#define SIZEOF_NETWORK_DOUBLE   8 /* htond() */
 
#define ntohll(_val)
 
#define htonll(_val)   ntohll(_val)
 
#define CV_CHANNEL_MASK   0x00ff
 
#define CV_HOST_MASK   0x0100
 
#define CV_SIGNED_MASK   0x0200
 
#define CV_TYPE_MASK   0x1c00 /* 0001 1100 0000 0000 */
 
#define CV_CONVERT_MASK   0x6000 /* 0110 0000 0000 0000 */
 
#define CV_TYPE_SHIFT   10
 
#define CV_CONVERT_SHIFT   13
 
#define CV_8   0x0400
 
#define CV_16   0x0800
 
#define CV_32   0x0c00
 
#define CV_64   0x1000
 
#define CV_D   0x1400
 
#define CV_CLIP   0x0000
 
#define CV_NORMAL   0x2000
 
#define CV_LIT   0x4000
 
#define END_NOTSET   0
 
#define END_BIG   1 /* PowerPC/MIPS */
 
#define END_LITTLE   2 /* Intel */
 
#define END_ILL   3 /* PDP-11 */
 
#define END_CRAY   4 /* Old Cray */
 
#define IND_NOTSET   0
 
#define IND_BIG   1
 
#define IND_LITTLE   2
 
#define IND_ILL   3
 
#define IND_CRAY   4
 

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)
 
size_t bu_cv_ntohss (signed short *in, size_t count, void *out, size_t size)
 Network TO Host Signed Short. More...
 
size_t bu_cv_ntohus (unsigned short *, size_t, void *, size_t)
 
size_t bu_cv_ntohsl (signed long int *, size_t, void *, size_t)
 
size_t bu_cv_ntohul (unsigned long int *, size_t, void *, size_t)
 
size_t bu_cv_htonss (void *, size_t, signed short *, size_t)
 
size_t bu_cv_htonus (void *, size_t, unsigned short *, size_t)
 
size_t bu_cv_htonsl (void *, size_t, long *, size_t)
 
size_t bu_cv_htonul (void *, size_t, unsigned long *, size_t)
 
void bu_cv_htond (unsigned char *out, const unsigned char *in, size_t count)
 
void bu_cv_ntohd (unsigned char *out, const unsigned char *in, size_t count)
 
void bu_cv_htonf (unsigned char *out, const unsigned char *in, size_t count)
 
void bu_cv_ntohf (unsigned char *out, const unsigned char *in, size_t count)
 
signed char * bu_b64_encode (const signed char *input)
 
signed char * bu_b64_encode_block (const signed char *input, size_t length_in)
 
int bu_b64_decode (signed char **output_buffer, const signed char *input)
 
int bu_b64_decode_block (signed char **output_buffer, const signed char *input, size_t length_in)
 

Detailed Description

Macro Definition Documentation

#define SIZEOF_NETWORK_SHORT   2 /* htons(), bu_gshort(), bu_pshort() */

Sizes of "network" format data. We use the same convention as the TCP/IP specification, namely, big-Endian, IEEE format, twos complement. This is the BRL-CAD external data representation (XDR). See also the support routines in libbu/xdr.c

Definition at line 45 of file cv.h.

Referenced by rt_dsp_export5(), rt_dsp_import5(), rt_pnts_export5(), and rt_pnts_import5().

#define SIZEOF_NETWORK_FLOAT   4 /* htonf() */
#define SIZEOF_NETWORK_DOUBLE   8 /* htond() */
#define ntohll (   _val)
Value:
((((uint64_t)ntohl((_val))) << 32) + ntohl((_val) >> 32)) : \
(_val)) /* sorry pdp-endian */
bu_endian_t bu_byteorder(void)
Definition: endian.c:27

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

Definition at line 54 of file cv.h.

#define htonll (   _val)    ntohll(_val)

Definition at line 59 of file cv.h.

Referenced by db5_encode_length().

#define CV_CHANNEL_MASK   0x00ff

Definition at line 63 of file cv.h.

Referenced by bu_cv_fmt_cookie().

#define CV_HOST_MASK   0x0100

Definition at line 64 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), bu_cv_itemlen(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_SIGNED_MASK   0x0200

Definition at line 65 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_w_cookie().

#define CV_TYPE_MASK   0x1c00 /* 0001 1100 0000 0000 */

Definition at line 66 of file cv.h.

Referenced by bu_cv_fmt_cookie(), bu_cv_itemlen(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_CONVERT_MASK   0x6000 /* 0110 0000 0000 0000 */

Definition at line 67 of file cv.h.

Referenced by bu_cv_fmt_cookie().

#define CV_TYPE_SHIFT   10

Definition at line 69 of file cv.h.

Referenced by bu_cv_itemlen().

#define CV_CONVERT_SHIFT   13

Definition at line 70 of file cv.h.

#define CV_8   0x0400

Definition at line 72 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_16   0x0800

Definition at line 73 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_32   0x0c00

Definition at line 74 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_64   0x1000

Definition at line 75 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), and bu_cv_optimize().

#define CV_D   0x1400

Definition at line 76 of file cv.h.

Referenced by bu_cv_cookie(), bu_cv_fmt_cookie(), bu_cv_optimize(), and bu_cv_w_cookie().

#define CV_CLIP   0x0000

Definition at line 78 of file cv.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define CV_NORMAL   0x2000

Definition at line 79 of file cv.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define CV_LIT   0x4000

Definition at line 80 of file cv.h.

Referenced by bu_cv_cookie(), and bu_cv_fmt_cookie().

#define END_NOTSET   0

deprecated

Definition at line 83 of file cv.h.

#define END_BIG   1 /* PowerPC/MIPS */

Definition at line 84 of file cv.h.

#define END_LITTLE   2 /* Intel */

Definition at line 85 of file cv.h.

#define END_ILL   3 /* PDP-11 */

Definition at line 86 of file cv.h.

#define END_CRAY   4 /* Old Cray */

Definition at line 87 of file cv.h.

#define IND_NOTSET   0

deprecated

Definition at line 90 of file cv.h.

#define IND_BIG   1

Definition at line 91 of file cv.h.

#define IND_LITTLE   2

Definition at line 92 of file cv.h.

#define IND_ILL   3

Definition at line 93 of file cv.h.

#define IND_CRAY   4

Definition at line 94 of file cv.h.

Function Documentation

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

Definition at line 250 of file convert.c.

References bu_cv_cookie(), and bu_cv_w_cookie().

Here is the call graph for this function:

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

Definition at line 33 of file convert.c.

References CV_16, CV_32, CV_64, CV_8, CV_CLIP, CV_D, CV_HOST_MASK, CV_LIT, CV_NORMAL, CV_SIGNED_MASK, and UNLIKELY.

Referenced by bu_cv(), get_file_data(), get_obj_data(), rt_binunif_export5(), rt_binunif_import5_minor_type(), and rt_hf_import4().

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.

Referenced by get_file_data(), get_obj_data(), rt_binunif_export5(), rt_binunif_import5_minor_type(), and rt_hf_import4().

size_t bu_cv_itemlen ( int  cookie)

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

Referenced by rt_hf_import4().

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

1 ns16 -> hs16
2  -> hd
3  -> hs32
4  -> 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:
1 HOSTDBL defined as true or false
2 if ! hostother then
3  hostother = (Endian == END_BIG) ? SAME : DIFFERENT;
4 fi
5 if (infmt == double) then
6  if (HOSTDBL == SAME) {
7  inIsHost = host;
8  fi
9 else
10  if (hostother == SAME) {
11  inIsHost = host;
12  fi
13 fi
14 if (outfmt == double) then
15  if (HOSTDBL == SAME) {
16  outIsHost == host;
17 else
18  if (hostother == SAME) {
19  outIsHost = host;
20  fi
21 fi
22 if (infmt == outfmt) {
23  if (inIsHost == outIsHost) {
24  copy(in, out)
25  exit
26  else if (inIsHost == net) {
27  ntoh?(in, out);
28  exit
29  else
30  hton?(in, out);
31  exit
32  fi
33 fi
34 
35 while not done {
36  from = in;
37 
38  if (inIsHost == net) {
39  ntoh?(from, t1);
40  from = t1;
41  fi
42  if (infmt != double) {
43  if (outIsHost == host) {
44  to = out;
45  else
46  to = t2;
47  fi
48  castdbl(from, to);
49  from = to;
50  fi
51 
52  if (outfmt == double) {
53  if (outIsHost == net) {
54  hton?(from, out);
55  fi
56  else
57  if (outIsHost == host) {
58  dblcast(from, out);
59  else
60  dblcast(from, t3);
61  hton?(t3, out);
62  fi
63  fi
64 done

Definition at line 474 of file convert.c.

References bu_cv_htond(), bu_cv_htonsl(), bu_cv_htonss(), bu_cv_htonul(), bu_cv_htonus(), bu_cv_itemlen(), bu_cv_ntohd(), bu_cv_ntohsl(), bu_cv_ntohss(), bu_cv_ntohul(), bu_cv_ntohus(), bu_cv_optimize(), bu_free(), bu_malloc(), CV_16, CV_32, CV_8, CV_D, CV_HOST_MASK, CV_SIGNED_MASK, CV_TYPE_MASK, and out.

Referenced by bu_cv(), get_file_data(), get_obj_data(), rt_binunif_export5(), rt_binunif_import5_minor_type(), and rt_hf_import4().

Here is the call graph for this function:

size_t bu_cv_ntohss ( signed short *  in,
size_t  count,
void *  out,
size_t  size 
)

Network TO Host Signed Short.

bu_cv_ntohss

It is assumed that this routine will only be called if there is real work to do. Ntohs does no checking to see if it is reasonable to do any conversions.

Parameters
ingeneric pointer for input.
countnumber of shorts to be generated.
outshort pointer for output
sizenumber of bytes of space reserved for out.
Returns
number of conversions done.
size_t bu_cv_ntohus ( unsigned short *  ,
size_t  ,
void *  ,
size_t   
)
size_t bu_cv_ntohsl ( signed long int *  ,
size_t  ,
void *  ,
size_t   
)
size_t bu_cv_ntohul ( unsigned long int *  ,
size_t  ,
void *  ,
size_t   
)
size_t bu_cv_htonss ( void *  ,
size_t  ,
signed short *  ,
size_t   
)
size_t bu_cv_htonus ( void *  ,
size_t  ,
unsigned short *  ,
size_t   
)
size_t bu_cv_htonsl ( void *  ,
size_t  ,
long *  ,
size_t   
)
size_t bu_cv_htonul ( void *  ,
size_t  ,
unsigned long *  ,
size_t   
)
void bu_cv_htonf ( unsigned char *  out,
const unsigned char *  in,
size_t  count 
)

Host to Network Floats

Referenced by bu_struct_export(), and rt_binunif_export5().

void bu_cv_ntohf ( unsigned char *  out,
const unsigned char *  in,
size_t  count 
)

Network to Host Floats

Referenced by bu_struct_import(), and rt_binunif_import5_minor_type().

signed char* bu_b64_encode ( const signed char *  input)

Definition at line 240 of file b64.c.

References bu_b64_encode_block().

Here is the call graph for this function:

signed char* bu_b64_encode_block ( const signed char *  input,
size_t  length_in 
)

Definition at line 212 of file b64.c.

References bu_b64_encode_block_internal(), bu_b64_encode_blockend(), bu_b64_init_encodestate(), bu_calloc(), output, and s.

Referenced by bu_b64_encode(), and rt_brep_get().

Here is the call graph for this function:

int bu_b64_decode ( signed char **  output_buffer,
const signed char *  input 
)

Definition at line 274 of file b64.c.

References bu_b64_decode_block().

Referenced by rt_brep_adjust().

Here is the call graph for this function:

int bu_b64_decode_block ( signed char **  output_buffer,
const signed char *  input,
size_t  length_in 
)

Definition at line 247 of file b64.c.

References bu_b64_decode_block_internal(), bu_b64_init_decodestate(), bu_calloc(), and s.

Referenced by bu_b64_decode().

Here is the call graph for this function: