CARMA C++
netobj.h
1 #ifndef netobj_h
2 #define netobj_h
3 
4 #include <stddef.h> /* size_t */
5 
6 #include "carma/szaarrayutils/netbuf.h"
7 
8 typedef struct NetObjTable NetObjTable;
9 
10 /*
11  * This file describes network-transparent objects and the functions
12  * that manipulate them.
13  */
14 
15 int obj_to_net(const NetObjTable *types, sza::array::NetBuf *net, int id, void *obj);
16 int net_to_obj(const NetObjTable *types, sza::array::NetBuf *net, int id, void *obj);
17 
18 /* Enumerate known basic database types */
19 
20 typedef enum {
21  NET_ASCII, /* char elements interpretted as a '\0' terminated ASCII string*/
22  NET_BYTE, /* char elements interpretted as 8-bit integers */
23  NET_SHORT, /* short int elements */
24  NET_ENUM, /* short int enumeration (Use type NetEnum) */
25  NET_BOOL, /* short int boolean (0:false, !=0:true) (use type NetBool) */
26  NET_MASK, /* unsigned long bit-mask (Use type NetMask) */
27  NET_LONG, /* long int elements */
28  NET_FLOAT, /* float elements */
29  NET_DOUBLE /* double elements */
30 } NetDataType;
31 
32 /* Declare type aliases for special types */
33 
34 typedef short NetEnum;
35 typedef short NetBool;
36 typedef unsigned long NetMask;
37 typedef unsigned long NetUlong;
38 
39 /* Declare a symbol table for enumeration members */
40 
41 typedef struct {
42  char *name; /* Symbolic name for the enumerator */
43 } NetObjEnumTab;
44 
45 /* Declare a type to be used to describe one member of an object */
46 
47 typedef struct {
48  const char *name; /* Member name */
49  size_t offset; /* Byte offset of member wrt start of object */
50  NetDataType type; /* The data-type of the member */
51  int ntype; /* The number of elements of type 'type' in the member */
52  const NetObjEnumTab *etab; /* Enumeration symbols (NULL if type!=NET_ENUM) */
53  int nenum; /* The number of elements in etab[] (0 if type!=NET_ENUM) */
54 } NetObjMember;
55 
56 /* Declare an object description type */
57 
58 typedef struct {
59  char *name; /* Name to refer to object by */
60  const NetObjMember *member;/* An array of nmember object member descriptors */
61  int nmember; /* The number of elements in member[] */
62  size_t native_size; /* The native size of the object */
63 } NetObjInfo;
64 
65 /*
66  * A container of the following type should be used to describe each
67  * of the network objects that are to be supported.
68  */
69 struct NetObjTable {
70  char *name; /* The name of the object collection */
71  const NetObjInfo *info; /* Descriptions of each of nobj objects */
72  /* This can be NULL if nobj==0. */
73  int nobj; /* The number of objects in the database */
74  size_t union_size; /* The size of the union of all object types */
75 };
76 
77 size_t net_max_obj_size(const NetObjTable *types);
78 size_t net_obj_size(const NetObjTable *types, int id);
79 size_t net_type_size(NetDataType type);
80 size_t net_native_size(const NetObjTable *types, int id);
81 const NetObjInfo *net_obj_info(const NetObjTable *types, int id);
82 
83 #endif