libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmSerialize.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #ifndef cmSerialize_h
  2. #define cmSerialize_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //{
  7. //(
  8. // cmSerialize is an API for serializing data structures into
  9. // byte streams and then deserializing them back into data structures.
  10. //
  11. //)
  12. //(
  13. // Result codes
  14. enum
  15. {
  16. kOkSrRC,
  17. kLHeapFailSrRC,
  18. kParamErrSrRC,
  19. kFormatViolationSrRC,
  20. };
  21. // type id
  22. enum
  23. {
  24. kArraySrFl = 0x80000000,
  25. kInvalidSrId = 0, // 0
  26. kCharSrId, // 1
  27. kUCharSrId, // 2
  28. kShortSrId, // 3
  29. kUShortSrId, // 4
  30. kIntSrId, // 5
  31. kUIntSrId, // 6
  32. kLongSrId, // 7
  33. kULongSrId, // 8
  34. kFloatSrId, // 9
  35. kDoubleSrId, // 10
  36. kBoolSrId, // 11
  37. kStructSrId, // 12 (all structTypeId's are >= kStructSrId)
  38. kCharVSrId = kCharSrId + kArraySrFl,
  39. kUCharVSrId = kUCharSrId + kArraySrFl,
  40. kShortVSrId = kShortSrId + kArraySrFl,
  41. kUShortVSrId = kUShortSrId + kArraySrFl,
  42. kIntVSrId = kIntSrId + kArraySrFl,
  43. kUIntVSrId = kUIntSrId + kArraySrFl,
  44. kLongVSrId = kLongSrId + kArraySrFl,
  45. kULongVSrId = kULongSrId + kArraySrFl,
  46. kFloatVSrId = kFloatSrId + kArraySrFl,
  47. kDoubleVSrId = kDoubleSrId + kArraySrFl,
  48. };
  49. typedef cmHandle_t cmSrH_t;
  50. typedef unsigned cmSrRC_t;
  51. extern cmSrH_t cmSrNullHandle;
  52. cmSrRC_t cmSrAlloc( cmSrH_t* hp, cmCtx_t* ctx );
  53. cmSrRC_t cmSrFree( cmSrH_t* hp );
  54. bool cmSrIsValid( cmSrH_t h );
  55. cmSrRC_t cmSrLastErrorCode( cmSrH_t h );
  56. cmSrRC_t cmSrGetAndClearLastErrorCode( cmSrH_t h );
  57. //
  58. // Serializer Format Interface
  59. //
  60. cmSrRC_t cmSrFmtReset( cmSrH_t h );
  61. cmSrRC_t cmSrFmtDefineStruct( cmSrH_t h, unsigned structTypeId );
  62. cmSrRC_t cmSrFmtStruct( cmSrH_t h, unsigned structTypeId );
  63. cmSrRC_t cmSrFmtChar( cmSrH_t h );
  64. cmSrRC_t cmSrFmtUChar( cmSrH_t h );
  65. cmSrRC_t cmSrFmtShort( cmSrH_t h );
  66. cmSrRC_t cmSrFmtUShort( cmSrH_t h );
  67. cmSrRC_t cmSrFmtLong( cmSrH_t h );
  68. cmSrRC_t cmSrFmtULong( cmSrH_t h );
  69. cmSrRC_t cmSrFmtInt( cmSrH_t h );
  70. cmSrRC_t cmSrFmtUInt( cmSrH_t h );
  71. cmSrRC_t cmSrFmtFloat( cmSrH_t h );
  72. cmSrRC_t cmSrFmtDouble( cmSrH_t h );
  73. cmSrRC_t cmSrFmtBool( cmSrH_t h );
  74. cmSrRC_t cmSrFmtStructV( cmSrH_t h, unsigned structTypeId );
  75. cmSrRC_t cmSrFmtCharV( cmSrH_t h );
  76. cmSrRC_t cmSrFmtUCharV( cmSrH_t h );
  77. cmSrRC_t cmSrFmtShortV( cmSrH_t h );
  78. cmSrRC_t cmSrFmtUShortV( cmSrH_t h );
  79. cmSrRC_t cmSrFmtLongV( cmSrH_t h );
  80. cmSrRC_t cmSrFmtULongV( cmSrH_t h );
  81. cmSrRC_t cmSrFmtIntV( cmSrH_t h );
  82. cmSrRC_t cmSrFmtUIntV( cmSrH_t h );
  83. cmSrRC_t cmSrFmtFloatV( cmSrH_t h );
  84. cmSrRC_t cmSrFmtDoubleV( cmSrH_t h );
  85. cmSrRC_t cmSrFmtBool( cmSrH_t h );
  86. // Combine a call to cmSrFmtDefineStruct() followed by multiple calls
  87. // to cmSrFmtXXX().
  88. // Notes:
  89. // 1. The arg. list must be terminated with a kInvalidSrId.
  90. // 2. Define primitive types using the appropriate id (kXXXSrId or kXXXVSrId)
  91. // 3. To define a structure field use the user defined structure type id.
  92. // 4. To define a structure array field use include the kArraySrFl flag as part of the id. (e.g. kMyStructId | kArraySrFl)
  93. cmSrRC_t cmSrDefFmt( cmSrH_t h, unsigned structTypeId, ... );
  94. cmSrRC_t cmSrFmtPrint( cmSrH_t h );
  95. //
  96. // Serializer Input (Write) Interface
  97. //
  98. cmSrRC_t cmSrWrReset( cmSrH_t h );
  99. cmSrRC_t cmSrWrStructBegin( cmSrH_t h, unsigned structTypeId );
  100. cmSrRC_t cmSrWrStructEnd( cmSrH_t h );
  101. cmSrRC_t cmSrWrStruct( cmSrH_t h, unsigned structTypeId, unsigned eleCnt );
  102. cmSrRC_t cmSrWrChar( cmSrH_t h, char val );
  103. cmSrRC_t cmSrWrUChar( cmSrH_t h, unsigned char val );
  104. cmSrRC_t cmSrWrShort( cmSrH_t h, short val );
  105. cmSrRC_t cmSrWrUShort( cmSrH_t h, unsigned short val );
  106. cmSrRC_t cmSrWrLong( cmSrH_t h, long val );
  107. cmSrRC_t cmSrWrULong( cmSrH_t h, unsigned long val );
  108. cmSrRC_t cmSrWrInt( cmSrH_t h, int val );
  109. cmSrRC_t cmSrWrUInt( cmSrH_t h, unsigned val );
  110. cmSrRC_t cmSrWrFloat( cmSrH_t h, float val );
  111. cmSrRC_t cmSrWrDouble( cmSrH_t h, double val );
  112. cmSrRC_t cmSrWrBool( cmSrH_t h, bool val );
  113. cmSrRC_t cmSrWrStr( cmSrH_t h, const cmChar_t* val );
  114. cmSrRC_t cmSrWrCharV( cmSrH_t h, const char* val, unsigned eleCnt );
  115. cmSrRC_t cmSrWrUCharV( cmSrH_t h, const unsigned char* val, unsigned eleCnt );
  116. cmSrRC_t cmSrWrShortV( cmSrH_t h, const short* val, unsigned eleCnt );
  117. cmSrRC_t cmSrWrUShortV( cmSrH_t h, const unsigned short* val, unsigned eleCnt );
  118. cmSrRC_t cmSrWrLongV( cmSrH_t h, const long* val, unsigned eleCnt );
  119. cmSrRC_t cmSrWrULongV( cmSrH_t h, const unsigned long* val, unsigned eleCnt );
  120. cmSrRC_t cmSrWrIntV( cmSrH_t h, const int* val, unsigned eleCnt );
  121. cmSrRC_t cmSrWrUIntV( cmSrH_t h, const unsigned* val, unsigned eleCnt );
  122. cmSrRC_t cmSrWrFloatV( cmSrH_t h, const float* val, unsigned eleCnt );
  123. cmSrRC_t cmSrWrDoubleV( cmSrH_t h, const double* val, unsigned eleCnt );
  124. cmSrRC_t cmSrWrBoolV( cmSrH_t h, const bool* val, unsigned eleCnt );
  125. void* cmSrWrAllocBuf( cmSrH_t h, unsigned* bufByteCntPtr );
  126. void* cmSrWrGetBuf( cmSrH_t h, unsigned* bufByteCntPtr );
  127. //
  128. // Serializer Output (Read) Interface
  129. //
  130. // cmSrRdProcessBuffer() validates the buffer and swaps its endianess if necessary.
  131. // This function must be called prior to cmSrRdSetup() however it should only be called
  132. // once on a given buffer. Multiple calls to cmSrRdSetup() however may be made on
  133. // the same buffer following the call to this function.
  134. cmSrRC_t cmSrRdProcessBuffer( cmSrH_t h, void* buf, unsigned bufByteCnt );
  135. // Prepare a buffer for reading.
  136. cmSrRC_t cmSrRdSetup( cmSrH_t h, const void* buf, unsigned bufByteCnt );
  137. cmSrRC_t cmSrRdStructBegin( cmSrH_t h, unsigned structId );
  138. cmSrRC_t cmSrRdStructEnd( cmSrH_t h );
  139. cmSrRC_t cmSrReadStruct( cmSrH_t h, unsigned structTypeId, unsigned* arrayCnt );
  140. cmSrRC_t cmSrReadChar( cmSrH_t h, char* valPtr );
  141. cmSrRC_t cmSrReadUChar( cmSrH_t h, unsigned char* valPtr );
  142. cmSrRC_t cmSrReadShort( cmSrH_t h, short* valPtr );
  143. cmSrRC_t cmSrReadUShort( cmSrH_t h, unsigned short* valPtr );
  144. cmSrRC_t cmSrReadLong( cmSrH_t h, long* valPtr);
  145. cmSrRC_t cmSrReadULong( cmSrH_t h, unsigned long* valPtr );
  146. cmSrRC_t cmSrReadInt( cmSrH_t h, int* valPtr);
  147. cmSrRC_t cmSrReadUInt( cmSrH_t h, unsigned* valPtr );
  148. cmSrRC_t cmSrReadFloat( cmSrH_t h, float* valPtr );
  149. cmSrRC_t cmSrReadDouble( cmSrH_t h, double* valPtr );
  150. cmSrRC_t cmSrReadBool( cmSrH_t h, bool* boolPtr );
  151. cmSrRC_t cmSrReadCharV( cmSrH_t h, char** valPtr, unsigned* eleCntPtr );
  152. cmSrRC_t cmSrReadUCharV( cmSrH_t h, unsigned char** valPtr, unsigned* eleCntPtr );
  153. cmSrRC_t cmSrReadShortV( cmSrH_t h, short** valPtr, unsigned* eleCntPtr );
  154. cmSrRC_t cmSrReadUShortV( cmSrH_t h, unsigned short** valPtr, unsigned* eleCntPtr );
  155. cmSrRC_t cmSrReadLongV( cmSrH_t h, long** valPtr, unsigned* eleCntPtr);
  156. cmSrRC_t cmSrReadULongV( cmSrH_t h, unsigned long** valPtr, unsigned* eleCntPtr );
  157. cmSrRC_t cmSrReadIntV( cmSrH_t h, int** valPtr, unsigned* eleCntPtr);
  158. cmSrRC_t cmSrReadUIntV( cmSrH_t h, unsigned** valPtr, unsigned* eleCntPtr );
  159. cmSrRC_t cmSrReadFloatV( cmSrH_t h, float** valPtr, unsigned* eleCntPtr );
  160. cmSrRC_t cmSrReadDoubleV( cmSrH_t h, double** valPtr, unsigned* eleCntPtr );
  161. cmSrRC_t cmSrReadBoolV( cmSrH_t h, bool** valPtr, unsigned* eleCntPtr );
  162. cmSrRC_t cmSrReadCharCV( cmSrH_t h, const char** valPtr, unsigned* eleCntPtr );
  163. cmSrRC_t cmSrReadUCharCV( cmSrH_t h, const unsigned char** valPtr, unsigned* eleCntPtr );
  164. cmSrRC_t cmSrReadShortCV( cmSrH_t h, const short** valPtr, unsigned* eleCntPtr );
  165. cmSrRC_t cmSrReadUShortCV( cmSrH_t h, const unsigned short** valPtr, unsigned* eleCntPtr );
  166. cmSrRC_t cmSrReadLongCV( cmSrH_t h, const long** valPtr, unsigned* eleCntPtr);
  167. cmSrRC_t cmSrReadULongCV( cmSrH_t h, const unsigned long** valPtr, unsigned* eleCntPtr );
  168. cmSrRC_t cmSrReadIntCV( cmSrH_t h, const int** valPtr, unsigned* eleCntPtr);
  169. cmSrRC_t cmSrReadUIntCV( cmSrH_t h, const unsigned** valPtr, unsigned* eleCntPtr );
  170. cmSrRC_t cmSrReadFloatCV( cmSrH_t h, const float** valPtr, unsigned* eleCntPtr );
  171. cmSrRC_t cmSrReadDoubleCV( cmSrH_t h, const double** valPtr, unsigned* eleCntPtr );
  172. cmSrRC_t cmSrReadBoolCV( cmSrH_t h, const bool** valPtr, unsigned* eleCntPtr );
  173. //
  174. // Abbreviated read functions.
  175. //
  176. // (Use cmSrLastErrorCode() to check for errors.)
  177. //
  178. // Same as cmSrReadFieldStruct but returns array element count or cmInvalidCnt on error.
  179. unsigned cmSrRdStruct( cmSrH_t h, unsigned structTypeId );
  180. char cmSrRdChar( cmSrH_t h );
  181. unsigned char cmSrRdUChar( cmSrH_t h );
  182. short cmSrRdShort( cmSrH_t h );
  183. unsigned short cmSrRdUShort( cmSrH_t h );
  184. long cmSrRdLong( cmSrH_t h );
  185. unsigned long cmSrRdULong( cmSrH_t h );
  186. int cmSrRdInt( cmSrH_t h );
  187. unsigned int cmSrRdUInt( cmSrH_t h );
  188. float cmSrRdFloat( cmSrH_t h );
  189. double cmSrRdDouble( cmSrH_t h );
  190. bool cmSrRdBool( cmSrH_t h );
  191. char* cmSrRdCharV( cmSrH_t h, unsigned* eleCntPtr);
  192. unsigned char* cmSrRdUCharV( cmSrH_t h, unsigned* eleCntPtr);
  193. short* cmSrRdShortV( cmSrH_t h, unsigned* eleCntPtr);
  194. unsigned short* cmSrRdUShortV( cmSrH_t h, unsigned* eleCntPtr);
  195. long* cmSrRdLongV( cmSrH_t h, unsigned* eleCntPtr);
  196. unsigned long* cmSrRdULongV( cmSrH_t h, unsigned* eleCntPtr);
  197. int* cmSrRdIntV( cmSrH_t h, unsigned* eleCntPtr);
  198. unsigned int* cmSrRdUIntV( cmSrH_t h, unsigned* eleCntPtr);
  199. float* cmSrRdFloatV( cmSrH_t h, unsigned* eleCntPtr);
  200. double* cmSrRdDoubleV( cmSrH_t h, unsigned* eleCntPtr);
  201. bool* cmSrRdBoolV( cmSrH_t h, unsigned* aleCntPtr);
  202. const char* cmSrRdCharCV( cmSrH_t h, unsigned* eleCntPtr);
  203. const unsigned char* cmSrRdUCharCV( cmSrH_t h, unsigned* eleCntPtr);
  204. const short* cmSrRdShortCV( cmSrH_t h, unsigned* eleCntPtr);
  205. const unsigned short* cmSrRdUShortCV( cmSrH_t h, unsigned* eleCntPtr);
  206. const long* cmSrRdLongCV( cmSrH_t h, unsigned* eleCntPtr);
  207. const unsigned long* cmSrRdULongCV( cmSrH_t h, unsigned* eleCntPtr);
  208. const int* cmSrRdIntCV( cmSrH_t h, unsigned* eleCntPtr);
  209. const unsigned int* cmSrRdUIntCV( cmSrH_t h, unsigned* eleCntPtr);
  210. const float* cmSrRdFloatCV( cmSrH_t h, unsigned* eleCntPtr);
  211. const double* cmSrRdDoubleCV( cmSrH_t h, unsigned* eleCntPtr);
  212. const bool* cmSrRdBoolCV( cmSrH_t h, unsigned* aleCntPtr);
  213. #if CM_FLOAT_SMP == 1
  214. #define kSampleSrId kFloatSrId
  215. #define kSampleVSrId kFloatSrId + kArraySrFl
  216. #define cmSrFmtSmp cmSrFmtFloat
  217. #define cmSrFmtSmpV cmSrFmtFloatV
  218. #define cmSrWrSmp cmSrWrFloat
  219. #define cmSrWrSmpV cmSrWrFloatV
  220. #define cmSrReadSmp cmSrReadFloat
  221. #define cmSrReadSmpV cmSrReadFloatV
  222. #define cmSrRdSmp cmSrRdFloat
  223. #define cmSrRdSmpV cmSrRdFloatV
  224. #else
  225. #define kSampleSrId kDoubleSrId
  226. #define kSampleVSrId kDoubleSrId + kArraySrFl
  227. #define cmSrFmtSmp cmSrFmtDouble
  228. #define cmSrFmtSmpV cmSrFmtDoubleV
  229. #define cmSrWrSmp cmSrWrDouble
  230. #define cmSrWrSmpV cmSrWrDoubleV
  231. #define cmSrReadSmp cmSrReadDouble
  232. #define cmSrReadSmpV cmSrReadDoubleV
  233. #define cmSrRdSmp cmSrRdDouble
  234. #define cmSrRdSmpV cmSrRdDoubleV
  235. #endif
  236. #if CM_FLOAT_REAL == 1
  237. #define kRealSrId kFloatSrId
  238. #define kRealVSrId kFloatSrId + kArraySrFl
  239. #define cmSrFmtReal cmSrFmtFloat
  240. #define cmSrFmtRealV cmSrFmtFloatV
  241. #define cmSrWrReal cmSrWrFloat
  242. #define cmSrWrRealV cmSrWrFloatV
  243. #define cmSrReadReal cmSrReadFloat
  244. #define cmSrReadRealV cmSrReadFloatV
  245. #define cmSrRdReal cmSrRdFloat
  246. #define cmSrRdRealV cmSrRdFloatV
  247. #else
  248. #define kRealSrId kDoubleSrId
  249. #define kRealVSrId kDoubleSrId + kArraySrFl
  250. #define cmSrFmtReal cmSrFmtDouble
  251. #define cmSrFmtRealV cmSrFmtDoubleV
  252. #define cmSrWrReal cmSrWrDouble
  253. #define cmSrWrRealV cmSrWrDoubleV
  254. #define cmSrReadReal cmSrReadDouble
  255. #define cmSrReadRealV cmSrReadDoubleV
  256. #define cmSrRdReal cmSrRdDouble
  257. #define cmSrRdRealV cmSrRdDoubleV
  258. #endif
  259. cmSrRC_t cmSrTest( cmCtx_t* ctx );
  260. //)
  261. //}
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265. #endif