Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
carbonate.cpp
1 // @file C/carbonate.cpp
2 //
3 // The implementation for the Carbon functions with C-linkage.
4 //
5 // The MIT License(MIT)
6 // @copyright 2015 Paul M Watt
7 // ****************************************************************************
8 // Includes *******************************************************************
9 #include <C/carbonate.h>
10 #include <algorithm>
11 
12 
13 
14 // Disable name-mangling for these
15 // functions when compiled with C++.
16 extern "C"
17 {
18 
19 // ****************************************************************************
20 ALCHEMY_API
21 int Hg_local_endianess()
22 {
23  return ALCHEMY_ENDIANESS == ALCHEMY_BIG_ENDIAN
24  ? k_big_endian
26 }
27 
28 // ****************************************************************************
29 ALCHEMY_API
30 Hg_msg_t* Hg_create(
31  Hg_type_t msg_type
32 )
33 {
34  size_t size = GetTypeSize(msg_type);
35  if (0 == size)
36  return 0;
37 
38  C::carbon_t* p_msg = new C::carbon_t[size + C::k_carbon_footprint];
39  uint32_t base = C::k_carbon_id | (size << 8);
40 
41  ::memcpy(p_msg, &base, 4);
42  ::memcpy(p_msg + C::k_type_offset, &msg_type, 4);
43 
44  return p_msg;
45 }
46 
47 
48 // ****************************************************************************
49 ALCHEMY_API
50 Hg_msg_t* Hg_clone(
51  const Hg_msg_t* p_src
52 )
53 {
54  GetTotalSize(const_cast<Hg_msg_t*>(p_src));
55 
56  return 0;
57 }
58 
59 
60 // ****************************************************************************
61 ALCHEMY_API
62 void Hg_destroy(
63  Hg_msg_t* p_msg
64 )
65 {
66  C::carbon_t* p_base = C::carbon_ptr(p_msg);
67  if (!p_base)
68  return;
69 
70  // TODO: Handle dynamic buffers.
71  // Use the type information to
72  // destroy any dynamic buffers.
73 
74  delete[] p_base;
75 }
76 
77 
78 // ****************************************************************************
79 ALCHEMY_API
80 size_t Hg_resize_dynamic(
81  Hg_msg_t* p_msg,
82  void* p_field,
83  size_t len
84 )
85 {
86  return 0;
87 }
88 
89 
90 // ****************************************************************************
91 ALCHEMY_API
92 Hg_type_t Hg_type(
93  const Hg_msg_t* p_msg
94 )
95 {
96  return C::carbon_type(p_msg);
97 }
98 
99 
100 // ****************************************************************************
101 ALCHEMY_API
102 size_t Hg_size(
103  const Hg_msg_t* p_msg
104 )
105 {
106  return C::carbon_size(p_msg);
107 }
108 
109 
110 // ****************************************************************************
111 ALCHEMY_API
112 size_t Hg_data_size(
113  const Hg_msg_t* p_msg
114 )
115 {
116  // TODO:
117  // Use the type information to calculate
118  // the size of the output buffer.
119 
120 
121  return 0;
122 }
123 
124 
125 // ****************************************************************************
126 ALCHEMY_API
127 int Hg_to_network(
128  Hg_msg_t* p_msg
129 )
130 {
131  // TODO: Dispatch to the correct type converter.
132 
133 
134  return 0;
135 }
136 
137 
138 // ****************************************************************************
139 ALCHEMY_API
140 int Hg_to_host(
141  Hg_msg_t* p_msg
142 )
143 {
144  // TODO: Dispatch to the correct type converter.
145  return 0;
146 }
147 
148 
149 // ****************************************************************************
150 ALCHEMY_API
151 int Hg_to_big_end(
152  Hg_msg_t* p_msg
153 )
154 {
155  // TODO: Dispatch to the correct type converter.
156  return 0;
157 }
158 
159 
160 // ****************************************************************************
161 ALCHEMY_API
162 int Hg_to_little_end(
163  Hg_msg_t* p_msg
164 )
165 {
166  // TODO: Dispatch to the correct type converter.
167  return 0;
168 }
169 
170 
171 // ****************************************************************************
172 ALCHEMY_API
173 size_t Hg_pack(
174  const Hg_msg_t* p_msg,
175  void* p_buffer,
176  size_t len
177 )
178 {
179  // TODO: Dispatch to the correct serializer.
180  return 0;
181 }
182 
183 
184 // ****************************************************************************
185 ALCHEMY_API
186 size_t Hg_unpack(
187  Hg_msg_t* p_msg,
188  const void* p_buffer,
189  size_t len
190 )
191 {
192  // TODO: Dispatch to the correct deserializer.
193  return 0;
194 }
195 
196 
197 // End of name-mangling guard.
198 }
199 
200