libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmSerialize.h 12KB

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