Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | bbd03114b6024cf876b8492839c9b7b97d5b1c04 |
|---|---|
| Date: | 2008-11-14 18:02:53 |
| User: | stephan |
| Comment: | minor doc re-orgs |
Changes
Changes to include/s11n.net/c11n/c11n.h
| Old (7799fac2c567514e) | New (da50eb6636dbb0a4) | |||
|---|---|---|---|---|
| 1 | #ifndef S11N_NET_C11N_H_INCLUDED | 1 | #ifndef S11N_NET_C11N_H_INCLUDED | |
| 2 | #define S11N_NET_C11N_H_INCLUDED 1 | 2 | #define S11N_NET_C11N_H_INCLUDED 1 | |
| 3 | 3 | |||
| 4 | /** @page c11n_page_main c11n: generic serialization library for C | 4 | /** @page c11n_page_main c11n: generic serialization library for C | |
| 5 | 5 | |||
| 1128 hidden lines | ||||
| 1134 | c11n_marshaller_api. | 1134 | c11n_marshaller_api. | |
| 1135 | 1135 | |||
| 1136 | implData can be used to store private data required by the | 1136 | implData can be used to store private data required by the | |
| 1137 | implementation functions. Note that because the "self" argument | 1137 | implementation functions. Note that because the "self" argument | |
| 1138 | of all of the members is const, the implData object is | 1138 | of all of the members is const, the implData object is | |
| 1139 | necessarily also const. | | | 1139 | also const. |
| 1140 | 1140 | |||
| 1141 | The reason for this member is because C99's "strict aliasing" | 1141 | The reason for this member is because C99's "strict aliasing" | |
| 1142 | rules won't let us legally treat a (c11n_marshaller*) as-a | 1142 | rules won't let us legally treat a (c11n_marshaller*) as-a | |
| 1143 | (c11n_marshaller_some_subclass*) - even if we know that they're | 1143 | (c11n_marshaller_some_subclass*) - even if we know that they're | |
| 1144 | the same object (at the same address), C99 explicitly specifies | 1144 | the same object (at the same address), C99 explicitly specifies | |
| 9 hidden lines | ||||
| 1154 | "c11n_marshaller_pod_api". | 1154 | "c11n_marshaller_pod_api". | |
| 1155 | */ | 1155 | */ | |
| 1156 | void const * implData; | 1156 | void const * implData; | |
| 1157 | }; | 1157 | }; | |
| 1158 | typedef struct c11n_marshaller_api c11n_marshaller_api; | 1158 | typedef struct c11n_marshaller_api c11n_marshaller_api; | |
| > | 1159 | |||
| > | 1160 | /** | ||
| > | 1161 | c11n_marshaller_api_init is an empty c11n_marshaller_api | ||
| > | 1162 | object which has non-null, but useless, member functions. | ||
| > | 1163 | */ | ||
| 1159 | extern const c11n_marshaller_api c11n_marshaller_api_init; | 1164 | extern const c11n_marshaller_api c11n_marshaller_api_init; | |
| 1160 | 1165 | |||
| 1161 | /** | 1166 | /** | |
| 1162 | C11N_MARSHALLER_API_INIT is used to initialize a shared/static | 1167 | C11N_MARSHALLER_API_INIT is used to initialize a shared/static | |
| 1163 | c11n_marshaller_api object. The parameters are: | 1168 | c11n_marshaller_api object. The parameters are: | |
| 26 hidden lines | ||||
| 1190 | CLEAR, \ | 1195 | CLEAR, \ | |
| 1191 | DTOR, \ | 1196 | DTOR, \ | |
| 1192 | ISA,\ | 1197 | ISA,\ | |
| 1193 | DATA\ | 1198 | DATA\ | |
| 1194 | } | 1199 | } | |
| > | 1200 | /** | ||
| > | 1201 | C11N_MARSHALLER_API_INIT is a variant of C11N_MARSHALLER_API_INIT_FULL, | ||
| > | 1202 | minus the ISA and DATA parameters of the latter macro. | ||
| > | 1203 | */ | ||
| 1195 | #define C11N_MARSHALLER_API_INIT(N,SER,DES,CREATE,CLEAR,DTOR) \ | 1204 | #define C11N_MARSHALLER_API_INIT(N,SER,DES,CREATE,CLEAR,DTOR) \ | |
| 1196 | C11N_MARSHALLER_API_INIT_FULL(N,SER,DES,CREATE,CLEAR,DTOR,c11n_marshaller_api_is_a,0) | 1205 | C11N_MARSHALLER_API_INIT_FULL(N,SER,DES,CREATE,CLEAR,DTOR,c11n_marshaller_api_is_a,0) | |
| 1197 | 1206 | |||
| 1198 | /** | 1207 | /** | |
| 1199 | @struct c11n_marshaller | 1208 | @struct c11n_marshaller | |
| 2 hidden lines | ||||
| 1202 | exact algorithms used for de/serializing a certain type, and a | 1211 | exact algorithms used for de/serializing a certain type, and a | |
| 1203 | different marshaller object is required for each type we want to | 1212 | different marshaller object is required for each type we want to | |
| 1204 | make Cerializable. | 1213 | make Cerializable. | |
| 1205 | 1214 | |||
| 1206 | Support for de/serializing new types involves implementing a | 1215 | Support for de/serializing new types involves implementing a | |
| 1207 | c11n_marshaller instance or creating a custom struct which has a | | | 1216 | c11n_marshaller instance which has a |
| 1208 | c11n_marshaller_api object (named api) as its first member. One | | | 1217 | const c11n_marshaller_api pointer (named api) as its first member. One |
| 1209 | should then create a shared object instance of that type, which | 1218 | should then create a shared object instance of that type, which | |
| 1210 | client code can pass to c11n_serialize() and c11n_deserialize(). | 1219 | client code can pass to c11n_serialize() and c11n_deserialize(). | |
| 1211 | One way to create such an instance is: | 1220 | One way to create such an instance is: | |
| 1212 | 1221 | |||
| 1213 | Add the following to your public API (or some scope where all | 1222 | Add the following to your public API (or some scope where all | |
| 1214 | of your client code can see it): | 1223 | of your client code can see it): | |
| 1215 | 1224 | |||
| 1216 | @code | 1225 | @code | |
| 1217 | extern const c11n_marshaller myMarshaller; | | | 1226 | extern const c11n_marshaller MyType_c11n; |
| 1218 | @endcode | 1227 | @endcode | |
| 1219 | 1228 | |||
| 1220 | Then initialize that object somewhere in your private implementation: | 1229 | Then initialize that object somewhere in your private implementation: | |
| 1221 | 1230 | |||
| 1222 | @code | 1231 | @code | |
| 1223 | static const c11n_marshaller_api myMarshaller_api = | | | 1232 | static const c11n_marshaller_api MyType_c11n_api = |
| 1224 | C11N_MARSHALLER_API_INIT( | 1233 | C11N_MARSHALLER_API_INIT( | |
| 1225 | "MyType", | 1234 | "MyType", | |
| 1226 | MyType_serialize, | 1235 | MyType_serialize, | |
| 1227 | MyType_deserialize, | 1236 | MyType_deserialize, | |
| 1228 | MyType_create, | 1237 | MyType_create, | |
| > | 1238 | MyType_clear, | ||
| 1229 | MyType_destroy); | 1239 | MyType_destroy); | |
| 1230 | static const c11n_marshaller myMarshaller = { | | | 1240 | static const c11n_marshaller MyType_c11n = {&MyType_c11n_api}; |
| 1231 | &myMarshaller_api | | | ||
| 1232 | ... custom members go here ... | | | ||
| 1233 | }; | | | ||
| 1234 | @endcode | 1241 | @endcode | |
| 1235 | 1242 | |||
| 1236 | It is also possible to create extended marshaller types, for those | 1243 | It is also possible to create extended marshaller types, for those | |
| 1237 | which need access to some other metadata. The only hard | | | 1244 | which need access to some other metadata. This is primarily useful |
| 1238 | requirement is that the custom marshaller type have, as their very | | | 1245 | when de/serialization algorithms need to share some static |
| 1239 | first member, a c11n_marshaller_api object named api. For example: | | | 1246 | information, e.g. a version number, a sscanf()/printf() conversion |
| 1240 | | | 1247 | specifier, or some such. For examples of this see c11n.c and | |
| 1241 | @code | | | 1248 | search for "c11n_marshaller_pod_api_". |
| 1242 | struct myExtendedMarshaller { | | | ||
| 1243 | c11n_marshaller_api const * api; | | | ||
| 1244 | int version; | | | ||
| 1245 | ... whatever ... | | | ||
| 1246 | }; | | | ||
| 1247 | @endcode | | | ||
| 1248 | | | |||
| 1249 | and then initialize it as above, but adding values for your own | | | ||
| 1250 | entries. | | | ||
| 1251 | | | |||
| 1252 | Inside the myExtendedMarshaller->api functions we can cast the | | | ||
| 1253 | (c11n_marshaller*) to a (myExtendedMarshaller*) to get at the | | | ||
| 1254 | extended members. This is primarily useful when de/serialization | | | ||
| 1255 | algorithms need to share some static information, e.g. a version | | | ||
| 1256 | number, a sscanf()/printf() conversion specifier, or some such. | | | ||
| 1257 | */ | 1249 | */ | |
| 1258 | typedef struct c11n_marshaller { | 1250 | typedef struct c11n_marshaller { | |
| 1259 | /** | 1251 | /** | |
| 1260 | Common marshaller data used by the core library. For custom | 1252 | Common marshaller data used by the core library. For custom | |
| 1261 | marshaller the first member MUST be a const pointer | 1253 | marshaller the first member MUST be a const pointer | |
| 5 hidden lines | ||||
| 1267 | 1259 | |||
| 1268 | /* any custom members of similar structs must go after this point. */ | 1260 | /* any custom members of similar structs must go after this point. */ | |
| 1269 | } c11n_marshaller; | 1261 | } c11n_marshaller; | |
| 1270 | 1262 | |||
| 1271 | /** | 1263 | /** | |
| 1272 | A default is_a() implementation for c11n_marshaller classes. It | | | 1264 | A default c11n_marshaller_api::is_a() implementation for |
| 1273 | returns the result of c11n_compare_str(self->api->classname,classname), or false if either | | | 1265 | c11n_marshaller classes. It returns the result of |
| 1274 | self is 0. | | | 1266 | c11n_compare_str(self->api->classname,classname), or false if |
| | | 1267 | either self or classname is 0. | ||
| 1275 | */ | 1268 | */ | |
| 1276 | bool c11n_marshaller_api_is_a( c11n_marshaller const * self, c11n_const_string_t classname ); | 1269 | bool c11n_marshaller_api_is_a( c11n_marshaller const * self, c11n_const_string_t classname ); | |
| 1277 | 1270 | |||
| 1278 | /** | 1271 | /** | |
| 1279 | A default clear() implementation for c11n_marshaller classes. It | | | 1272 | A default c11n_marshaller_api::clear() implementation for c11n_marshaller classes. It |
| 1280 | does nothing. | 1273 | does nothing. | |
| 1281 | */ | 1274 | */ | |
| 1282 | void c11n_marshaller_api_clear( c11n_marshaller const * self, void * v ); | 1275 | void c11n_marshaller_api_clear( c11n_marshaller const * self, void * v ); | |
| 1283 | 1276 | |||
| 1284 | /** | 1277 | /** | |
| 1285 | A default destroy() implementation for c11n_marshaller classes. It | | | 1278 | A default c11n_marshaller_api::destroy() implementation for c11n_marshaller classes. It |
| 1286 | calls self->api->clear(self,v) then calls free(v). | 1279 | calls self->api->clear(self,v) then calls free(v). | |
| 1287 | */ | 1280 | */ | |
| 1288 | void c11n_marshaller_api_destroy( c11n_marshaller const * self, void * v ); | 1281 | void c11n_marshaller_api_destroy( c11n_marshaller const * self, void * v ); | |
| 1289 | 1282 | |||
| 1290 | /** | 1283 | /** | |
| 1291 | A placeholder serialize() implementation for c11n_marshaller | | | 1284 | A placeholder c11n_marshaller_api::serialize() implementation for c11n_marshaller |
| 1292 | classes. It does nothing and returns false. | 1285 | classes. It does nothing and returns false. | |
| 1293 | */ | 1286 | */ | |
| 1294 | bool c11n_marshaller_api_serialize( c11n_marshaller const * self, | 1287 | bool c11n_marshaller_api_serialize( c11n_marshaller const * self, | |
| 1295 | c11n_node * dest, | 1288 | c11n_node * dest, | |
| 1296 | void const * src ); | 1289 | void const * src ); | |
| 1297 | /** | 1290 | /** | |
| 1298 | A placeholder deserialize() implementation for c11n_marshaller | | | 1291 | A placeholder c11n_marshaller_api::deserialize() implementation for c11n_marshaller |
| 1299 | classes. It does nothing and returns false. | 1292 | classes. It does nothing and returns false. | |
| 1300 | */ | 1293 | */ | |
| 1301 | bool c11n_marshaller_api_deserialize( c11n_marshaller const * self, | 1294 | bool c11n_marshaller_api_deserialize( c11n_marshaller const * self, | |
| 1302 | c11n_node const * src, | 1295 | c11n_node const * src, | |
| 1303 | void * dest ); | 1296 | void * dest ); | |
| 1304 | 1297 | |||
| 1305 | /** | < | ||
| 1306 | A marshaller instance for de/serializing objects of type int. Note, | < | ||
| 1307 | however, that it is always much more efficient to store ints as | < | ||
| 1308 | node properties, as opposed to as full-fledged (traited) | < | ||
| 1309 | Cerializables. | < | ||
| 1310 | < | |||
| 1311 | Sample usage: | < | ||
| 1312 | < | |||
| 1313 | @code | < | ||
| 1314 | // Serialize: | < | ||
| 1315 | int const src = 42; | < | ||
| 1316 | c11n_serialize( destNode, c11n_marshaller_pod_int, &src ); | < | ||
| 1317 | < | |||
| 1318 | // Deserialize: | < | ||
| 1319 | int dest = 0; | < | ||
| 1320 | c11n_deserialize( srcNode, c11n_marshaller_pod_int, &dest ); | < | ||
| 1321 | @endcode | < | ||
| 1322 | < | |||
| 1323 | But the saner thing to do in most cases is to store simple | < | ||
| 1324 | PODs as properties of some parent c11n_node: | < | ||
| 1325 | < | |||
| 1326 | @code | < | ||
| 1327 | int const src = 42; | < | ||
| 1328 | c11n_node_prop_set_fe( destNode, "myInt", "%d", src ); | < | ||
| 1329 | @endcode | < | ||
| 1330 | < | |||
| 1331 | as that has creates much less output when saved. | < | ||
| 1332 | */ | < | ||
| 1333 | extern const c11n_marshaller * c11n_marshaller_pod_int; | < | ||
| 1334 | < | |||
| 1335 | /** | < | ||
| 1336 | A marshaller instance for de/serializing objects of type unsigned int. | < | ||
| 1337 | See c11n_marshaller_pod_int for more details and sample usage. | < | ||
| 1338 | */ | < | ||
| 1339 | extern const c11n_marshaller * c11n_marshaller_pod_uint; | < | ||
| 1340 | < | |||
| 1341 | /** | < | ||
| 1342 | A marshaller instance for de/serializing objects of type long. | < | ||
| 1343 | See c11n_marshaller_pod_int for more details and sample usage. | < | ||
| 1344 | */ | < | ||
| 1345 | extern const c11n_marshaller * c11n_marshaller_pod_long; | < | ||
| 1346 | < | |||
| 1347 | /** | < | ||
| 1348 | A marshaller instance for de/serializing objects of type unsigned long. | < | ||
| 1349 | See c11n_marshaller_pod_int for more details and sample usage. | < | ||
| 1350 | */ | < | ||
| 1351 | extern const c11n_marshaller * c11n_marshaller_pod_ulong; | < | ||
| 1352 | < | |||
| 1353 | /** | < | ||
| 1354 | A marshaller instance for de/serializing objects of type double. | < | ||
| 1355 | See c11n_marshaller_pod_int for more details and sample usage. | < | ||
| 1356 | */ | < | ||
| 1357 | extern const c11n_marshaller * c11n_marshaller_pod_double; | < | ||
| 1358 | < | |||
| 1359 | /** | < | ||
| 1360 | DON'T USE! It can't work safely for some common cases. | < | ||
| 1361 | < | |||
| 1362 | A marshaller instance for de/serializing objects of type double. | < | ||
| 1363 | The string value deserialized by api->deserialize() | < | ||
| 1364 | will not be a copy, but will be a pointer to the data stored | < | ||
| 1365 | within the c11n_node we are deserializing from. Thus if | < | ||
| 1366 | you need to keep the string around longer than the corresponding | < | ||
| 1367 | c11n_node, copy it. | < | ||
| 1368 | < | |||
| 1369 | Example usage: | < | ||
| 1370 | @code | < | ||
| 1371 | // Serialize: | < | ||
| 1372 | c11n_const_string_t src = "This is a string."; | < | ||
| 1373 | c11n_serialize( destNode, c11n_marshaller_pod_string, src ); | < | ||
| 1374 | < | |||
| 1375 | // Deserialize: | < | ||
| 1376 | c11n_const_string_t dest = 0; | < | ||
| 1377 | if( c11n_deserialize( srcNode, c11n_marshaller_pod_string, &dest ) ) | < | ||
| 1378 | { // note the POINTER to dest here -->-->-->-->-->-->-->-^^^^^ | < | ||
| 1379 | // Now dest points to a copy of the deserialized string value | < | ||
| 1380 | // of srcNode. Copy it here if you need it after srcNode goes | < | ||
| 1381 | // out of your scope. | < | ||
| 1382 | } | < | ||
| 1383 | @endcode | < | ||
| 1384 | < | |||
| 1385 | BUG WARNING: this marshaller instance cannot work with | < | ||
| 1386 | c11n_deserialize_new() because this object requires that | < | ||
| 1387 | deserialization take a pointer to a pointer, which | < | ||
| 1388 | c11n_deserialize_new() cannot generically handle. It also | < | ||
| 1389 | cannot work with c11n_load_serializable() because it cannot | < | ||
| 1390 | know how big of a string to allocate (and then cannot generically | < | ||
| 1391 | handle the pointer-to-pointer part). | < | ||
| 1392 | */ | < | ||
| 1393 | //extern const c11n_marshaller * c11n_marshaller_pod_string; | < | ||
| 1394 | < | |||
| 1395 | #if 0 | < | ||
| 1396 | struct c11n_s_proxy_cstring | < | ||
| 1397 | { | < | ||
| 1398 | c11n_marshaller_api api; | < | ||
| 1399 | char * string; | < | ||
| 1400 | }; | < | ||
| 1401 | typedef struct c11n_s_proxy_cstring c11n_s_proxy_cstring; | < | ||
| 1402 | extern const c11n_s_proxy_cstring c11n_s_proxy_cstring_init; | < | ||
| 1403 | #define C11N_S_PROXY_CSTRING_INIT(Name,CString) \ | < | ||
| 1404 | c11n_s_proxy_cstring Name = c11n_s_proxy_cstring_init; Name.string=CString | < | ||
| 1405 | #endif | < | ||
| 1406 | 1298 | |||
| 1407 | /** | 1299 | /** | |
| 1408 | Serializes src to dest using the given marshaller for the | 1300 | Serializes src to dest using the given marshaller for the | |
| 1409 | conversion. If any parameters are null then false is returned. | 1301 | conversion. If any parameters are null then false is returned. | |
| 1410 | 1302 | |||
| 8 hidden lines | ||||
| 1419 | name. If serialization succeeeds, it is added to the parent and | 1311 | name. If serialization succeeeds, it is added to the parent and | |
| 1420 | true is returned, otherwise the child is destroyed, parent | 1312 | true is returned, otherwise the child is destroyed, parent | |
| 1421 | is not modified, and false is returned. | 1313 | is not modified, and false is returned. | |
| 1422 | */ | 1314 | */ | |
| 1423 | bool c11n_serialize_subnode( c11n_node * parent, c11n_marshaller const * marshaller, c11n_key_type childName, void const * src ); | 1315 | bool c11n_serialize_subnode( c11n_node * parent, c11n_marshaller const * marshaller, c11n_key_type childName, void const * src ); | |
| > | 1316 | |||
| 1424 | /** | 1317 | /** | |
| 1425 | NYI | | | 1318 | The converse of c11n_serialize_subnode(), this routine searches |
| | | 1319 | parent for a child node with the given name. If found, that child | ||
| | | 1320 | is used as the deserialization source for the given marshaller and | ||
| | | 1321 | serializable. On error (child not found or deserialization failed) | ||
| | | 1322 | false is returned and the serializable may be in an undefined state | ||
| | | 1323 | (that is up to the marshaller, actually). | ||
| | | 1324 | |||
| | | 1325 | Note that this only finds the first child with the given name. If | ||
| | | 1326 | parent has multiple children with the same name, use the | ||
| | | 1327 | c11n_node_iter_c API to iterate over them. | ||
| 1426 | */ | 1328 | */ | |
| 1427 | bool c11n_deserialize_subnode( c11n_node const * parent, c11n_marshaller const * marshaller, c11n_key_type childName, void * dest ); | | | 1329 | bool c11n_deserialize_subnode( c11n_node const * parent, c11n_marshaller const * marshaller, c11n_key_type childName, void * serializable ); |
| 1428 | 1330 | |||
| 1429 | /** | 1331 | /** | |
| 1430 | Deserializes dest from src using the given marshaller for the | 1332 | Deserializes dest from src using the given marshaller for the | |
| 1431 | conversion. If any parameters are null then false is returned. | 1333 | conversion. If any parameters are null then false is returned. | |
| 1432 | 1334 | |||
| 87 hidden lines | ||||
| 1520 | # define C11N_CONFIG_LOG_ENABLE 0 | 1422 | # define C11N_CONFIG_LOG_ENABLE 0 | |
| 1521 | #endif | 1423 | #endif | |
| 1522 | 1424 | |||
| 1523 | /** @enum c11n_log_flags | 1425 | /** @enum c11n_log_flags | |
| 1524 | 1426 | |||
| 1525 | The c11n_log_flags enum contains a bitmask | | | 1427 | The c11n_log_flags enum contains a bitmask of logging/debugging flags, |
| 1526 | of debugging flags, for use with c11n_log() and | | | 1428 | for use with c11n_log() and friends. |
| 1527 | friends. | | | ||
| 1528 | */ | 1429 | */ | |
| 1529 | enum c11n_log_flags { | 1430 | enum c11n_log_flags { | |
| 1530 | /** | 1431 | /** | |
| 1531 | Never log any debug message. | 1432 | Never log any debug message. | |
| 1532 | */ | 1433 | */ | |
| 159 hidden lines | ||||
| 1692 | /** | 1593 | /** | |
| 1693 | Gets the current debug mask. See the c11n_log_flags enum for | 1594 | Gets the current debug mask. See the c11n_log_flags enum for | |
| 1694 | details. | 1595 | details. | |
| 1695 | */ | 1596 | */ | |
| 1696 | unsigned int c11n_log_get_flags(); | 1597 | unsigned int c11n_log_get_flags(); | |
| > | 1598 | |||
| 1697 | /** | 1599 | /** | |
| 1698 | Sets the current debug mask and returns the previous one. See the | 1600 | Sets the current debug mask and returns the previous one. See the | |
| 1699 | c11n_log_flags enum for details. | 1601 | c11n_log_flags enum for details. | |
| 1700 | */ | 1602 | */ | |
| 1701 | unsigned int c11n_log_set_flags(unsigned int newflags); | 1603 | unsigned int c11n_log_set_flags(unsigned int newflags); | |
| > | 1604 | |||
| 1702 | /** | 1605 | /** | |
| 1703 | Sets the debug output stream to f. Setting it to 0 completely | 1606 | Sets the debug output stream to f. Setting it to 0 completely | |
| 1704 | disables debug output sent via c11n_log() and friends. | 1607 | disables debug output sent via c11n_log() and friends. | |
| 1705 | 1608 | |||
| 1706 | Does not transfer ownership of f, and f must outlive all | 1609 | Does not transfer ownership of f, and f must outlive all | |
| 36 hidden lines | ||||
| 1743 | va_list vargs ); | 1646 | va_list vargs ); | |
| 1744 | /** | 1647 | /** | |
| 1745 | Identical to c11n_logv() but takes an ellipses list instead of | 1648 | Identical to c11n_logv() but takes an ellipses list instead of | |
| 1746 | a va_list. | 1649 | a va_list. | |
| 1747 | */ | 1650 | */ | |
| 1748 | void c11n_log( unsigned int condition, | | | 1651 | void c11n_log( unsigned int condition, |
| 1749 | C11N_SOURCE_INFO_PARAMS_DECL, | | | 1652 | C11N_SOURCE_INFO_PARAMS_DECL, |
| 1750 | c11n_const_string_t fmt, | | | 1653 | c11n_const_string_t fmt, |
| 1751 | ... ); | 1654 | ... ); | |
| 1752 | //#define C11N_LOG_MARKER c11n_log(C,"c11n_log():%s:%d:%s(): ",__FILE__,__LINE__,__func__); | 1655 | //#define C11N_LOG_MARKER c11n_log(C,"c11n_log():%s:%d:%s(): ",__FILE__,__LINE__,__func__); | |
| 1753 | //#define C11N_LOG c11n_log(C,"c11n_log():%s:%d:%s(): ",__FILE__,__LINE__,__func__); c11n_log | 1656 | //#define C11N_LOG c11n_log(C,"c11n_log():%s:%d:%s(): ",__FILE__,__LINE__,__func__); c11n_log | |
| 1754 | < | |||
| 1755 | #if 0 | < | ||
| 1756 | bool c11n_register_marshaller( c11n_context * cx, c11n_key_type, c11n_marshaller const * marshaller ); | < | ||
| 1757 | c11n_marshaller const * c11n_get_marshaller_for_type( c11n_context * cx, c11n_key_type classname ); | < | ||
| 1758 | void * c11n_classload( c11n_context * cx, c11n_key_type key ); | < | ||
| 1759 | /** | < | ||
| 1760 | Registration of factories requires knowing: | < | ||
| 1761 | < | |||
| 1762 | - complete type | < | ||
| 1763 | < | |||
| 1764 | - class name | < | ||
| 1765 | < | |||
| 1766 | - factory function: void* (*)(); | < | ||
| 1767 | < | |||
| 1768 | */ | < | ||
| 1769 | #endif | < | ||
| 1770 | 1657 | |||
| 1771 | /** | 1658 | /** | |
| 1772 | Saves src as encoded binary data in dest. It does this by casting | 1659 | Saves src as encoded binary data in dest. It does this by casting | |
| 1773 | src to a (char const *), writing sizeOfSrc bytes to a string | 1660 | src to a (char const *), writing sizeOfSrc bytes to a string | |
| 1774 | buffer, base64-encoding that buffer and then storing the | 1661 | buffer, base64-encoding that buffer and then storing the | |
| 82 hidden lines | ||||
| 1857 | @endcode | 1744 | @endcode | |
| 1858 | 1745 | |||
| 1859 | @see c11n_deserialize_binary() | 1746 | @see c11n_deserialize_binary() | |
| 1860 | */ | 1747 | */ | |
| 1861 | bool c11n_deserialize_binary( c11n_node const * src, c11n_binary_data * dest ); | 1748 | bool c11n_deserialize_binary( c11n_node const * src, c11n_binary_data * dest ); | |
| > | 1749 | |||
| > | 1750 | |||
| > | 1751 | /** | ||
| > | 1752 | A marshaller instance for de/serializing objects of type int. Note, | ||
| > | 1753 | however, that it is always much more efficient to store ints as | ||
| > | 1754 | node properties, as opposed to as full-fledged (traited) | ||
| > | 1755 | Cerializables. | ||
| > | 1756 | |||
| > | 1757 | Sample usage: | ||
| > | 1758 | |||
| > | 1759 | @code | ||
| > | 1760 | // Serialize: | ||
| > | 1761 | int const src = 42; | ||
| > | 1762 | c11n_serialize( destNode, c11n_marshaller_pod_int, &src ); | ||
| > | 1763 | |||
| > | 1764 | // Deserialize: | ||
| > | 1765 | int dest = 0; | ||
| > | 1766 | c11n_deserialize( srcNode, c11n_marshaller_pod_int, &dest ); | ||
| > | 1767 | @endcode | ||
| > | 1768 | |||
| > | 1769 | But the saner thing to do in most cases is to store simple | ||
| > | 1770 | PODs as properties of some parent c11n_node: | ||
| > | 1771 | |||
| > | 1772 | @code | ||
| > | 1773 | int const src = 42; | ||
| > | 1774 | c11n_node_prop_set_fe( destNode, "myInt", "%d", src ); | ||
| > | 1775 | @endcode | ||
| > | 1776 | |||
| > | 1777 | as that requires far fewer resources internally and is | ||
| > | 1778 | suitable for many POD types. | ||
| > | 1779 | */ | ||
| > | 1780 | extern const c11n_marshaller * c11n_marshaller_pod_int; | ||
| > | 1781 | |||
| > | 1782 | /** | ||
| > | 1783 | A marshaller instance for de/serializing objects of type unsigned int. | ||
| > | 1784 | See c11n_marshaller_pod_int for more details and sample usage. | ||
| > | 1785 | */ | ||
| > | 1786 | extern const c11n_marshaller * c11n_marshaller_pod_uint; | ||
| > | 1787 | |||
| > | 1788 | /** | ||
| > | 1789 | A marshaller instance for de/serializing objects of type long. | ||
| > | 1790 | See c11n_marshaller_pod_int for more details and sample usage. | ||
| > | 1791 | */ | ||
| > | 1792 | extern const c11n_marshaller * c11n_marshaller_pod_long; | ||
| > | 1793 | |||
| > | 1794 | /** | ||
| > | 1795 | A marshaller instance for de/serializing objects of type unsigned long. | ||
| > | 1796 | See c11n_marshaller_pod_int for more details and sample usage. | ||
| > | 1797 | */ | ||
| > | 1798 | extern const c11n_marshaller * c11n_marshaller_pod_ulong; | ||
| > | 1799 | |||
| > | 1800 | /** | ||
| > | 1801 | A marshaller instance for de/serializing objects of type double. | ||
| > | 1802 | See c11n_marshaller_pod_int for more details and sample usage. | ||
| > | 1803 | */ | ||
| > | 1804 | extern const c11n_marshaller * c11n_marshaller_pod_double; | ||
| > | 1805 | |||
| > | 1806 | #if 0 | ||
| > | 1807 | /* | ||
| > | 1808 | DON'T USE! It can't work safely for some common cases. | ||
| > | 1809 | |||
| > | 1810 | A marshaller instance for de/serializing objects of type double. | ||
| > | 1811 | The string value deserialized by api->deserialize() | ||
| > | 1812 | will not be a copy, but will be a pointer to the data stored | ||
| > | 1813 | within the c11n_node we are deserializing from. Thus if | ||
| > | 1814 | you need to keep the string around longer than the corresponding | ||
| > | 1815 | c11n_node, copy it. | ||
| > | 1816 | |||
| > | 1817 | Example usage: | ||
| > | 1818 | @code | ||
| > | 1819 | // Serialize: | ||
| > | 1820 | c11n_const_string_t src = "This is a string."; | ||
| > | 1821 | c11n_serialize( destNode, c11n_marshaller_pod_string, src ); | ||
| > | 1822 | |||
| > | 1823 | // Deserialize: | ||
| > | 1824 | c11n_const_string_t dest = 0; | ||
| > | 1825 | if( c11n_deserialize( srcNode, c11n_marshaller_pod_string, &dest ) ) | ||
| > | 1826 | { // note the POINTER to dest here -->-->-->-->-->-->-->-^^^^^ | ||
| > | 1827 | // Now dest points to a copy of the deserialized string value | ||
| > | 1828 | // of srcNode. Copy it here if you need it after srcNode goes | ||
| > | 1829 | // out of your scope. | ||
| > | 1830 | } | ||
| > | 1831 | @endcode | ||
| > | 1832 | |||
| > | 1833 | BUG WARNING: this marshaller instance cannot work with | ||
| > | 1834 | c11n_deserialize_new() because this object requires that | ||
| > | 1835 | deserialization take a pointer to a pointer, which | ||
| > | 1836 | c11n_deserialize_new() cannot generically handle. It also | ||
| > | 1837 | cannot work with c11n_load_serializable() because it cannot | ||
| > | 1838 | know how big of a string to allocate (and then cannot generically | ||
| > | 1839 | handle the pointer-to-pointer part). | ||
| > | 1840 | */ | ||
| > | 1841 | //extern const c11n_marshaller * c11n_marshaller_pod_string; | ||
| > | 1842 | struct c11n_s_proxy_cstring | ||
| > | 1843 | { | ||
| > | 1844 | c11n_marshaller_api api; | ||
| > | 1845 | char * string; | ||
| > | 1846 | }; | ||
| > | 1847 | typedef struct c11n_s_proxy_cstring c11n_s_proxy_cstring; | ||
| > | 1848 | extern const c11n_s_proxy_cstring c11n_s_proxy_cstring_init; | ||
| > | 1849 | #define C11N_S_PROXY_CSTRING_INIT(Name,CString) \ | ||
| > | 1850 | c11n_s_proxy_cstring Name = c11n_s_proxy_cstring_init; Name.string=CString | ||
| > | 1851 | #endif | ||
| 1862 | 1852 | |||
| 1863 | #ifdef __cplusplus | 1853 | #ifdef __cplusplus | |
| 1864 | } /* extern "C" */ | 1854 | } /* extern "C" */ | |
| 1865 | #endif | 1855 | #endif | |
| 1866 | 1856 | |||
| 1867 | #endif /* S11N_NET_C11N_H_INCLUDED */ | 1857 | #endif /* S11N_NET_C11N_H_INCLUDED */ | |