BRL-CAD
xdr.c
Go to the documentation of this file.
1 /* X D R . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <math.h>
26 #include <string.h>
27 
28 #include "bu/cv.h"
29 
30 
31 unsigned char *
32 bu_pshort(register unsigned char *msgp, register uint16_t s)
33 {
34 
35  msgp[1] = (unsigned char)s;
36  msgp[0] = (unsigned char)(s >> 8);
37  return msgp+2;
38 }
39 
40 uint16_t
41 bu_gshort(const unsigned char *msgp)
42 {
43  register const unsigned char *p = msgp;
44  register uint16_t u;
45 
46  u = *p++ << 8;
47  return (uint16_t)(u | *p);
48 }
49 
50 
51 unsigned char *
52 bu_plong(register unsigned char *msgp, register uint32_t l)
53 {
54 
55  msgp[3] = (unsigned char)l;
56  msgp[2] = (unsigned char)(l >>= 8);
57  msgp[1] = (unsigned char)(l >>= 8);
58  msgp[0] = (unsigned char)(l >> 8);
59  return msgp+4;
60 }
61 
62 uint32_t
63 bu_glong(const unsigned char *msgp)
64 {
65  register const unsigned char *p = msgp;
66  register uint32_t u;
67 
68  u = *p++; u <<= 8;
69  u |= *p++; u <<= 8;
70  u |= *p++; u <<= 8;
71  return u | *p;
72 }
73 
74 
75 unsigned char *
76 bu_plonglong(register unsigned char *msgp, register uint64_t l)
77 {
78 
79  msgp[7] = (unsigned char)l;
80  msgp[6] = (unsigned char)(l >>= 8);
81  msgp[5] = (unsigned char)(l >>= 8);
82  msgp[4] = (unsigned char)(l >>= 8);
83  msgp[3] = (unsigned char)(l >>= 8);
84  msgp[2] = (unsigned char)(l >>= 8);
85  msgp[1] = (unsigned char)(l >>= 8);
86  msgp[0] = (unsigned char)(l >> 8);
87  return msgp+8;
88 }
89 
90 
91 /*
92  * Local Variables:
93  * mode: C
94  * tab-width: 8
95  * indent-tabs-mode: t
96  * c-file-style: "stroustrup"
97  * End:
98  * ex: shiftwidth=4 tabstop=8
99  */
uint32_t bu_glong(const unsigned char *msgp)
Definition: xdr.c:63
if lu s
Definition: nmg_mod.c:3860
Header file for the BRL-CAD common definitions.
uint16_t bu_gshort(const unsigned char *msgp)
Definition: xdr.c:41
unsigned char * bu_pshort(register unsigned char *msgp, register uint16_t s)
Definition: xdr.c:32
unsigned char * bu_plonglong(register unsigned char *msgp, register uint64_t l)
Definition: xdr.c:76
unsigned char * bu_plong(register unsigned char *msgp, register uint32_t l)
Definition: xdr.c:52