das2C
das core C utilities (v3)
codec.h
Go to the documentation of this file.
1 /* Copyright (C) 2024 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * This file is part of das2C, the Core Das2 C Library.
4  *
5  * das2C is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
20 #ifndef _das_codec_h_
21 #define _das_codec_h_
22 
23 #include <stdint.h>
24 
25 #include <das2/value.h>
26 #include <das2/array.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /* Not public, only here because used in a macro */
33 #define DASENC_VALID 0x0001
34 
40 typedef struct das_codec {
41 
42  bool bResLossWarn; /* If true, the resolution loss warning has already been emitted */
43 
44  uint32_t uProc; /* Internal processing flags setup on the call to _init */
45 
46  int nAryValSz; /* The size of each array value in internal buffer */
47 
48  int16_t nBufValSz; /* Width of a single value in the external buffer */
49 
50  das_val_type vtBuf; /* The value type in the external buffer */
51 
52  DasAry* pAry; /* The array for which values are encoded/decoded */
53 
54  ubyte cSep; /* Split strings on this byte value, in addition to null */
55 
56  uint32_t uMaxString; /* If we are storing fixed strings, this is set */
57 
58  das_units timeUnits; /* If ascii times are to be stored as an integral type
59  this is needed */
60 
61  char* pOverflow; /* If the size of a variable length value breaks */
62  size_t uOverflow; /* the small vector assumption, extra space is here */
63 
64 } DasCodec;
65 
66 
71 #define DasCodec_isValid(pCd) (((pCd)->uProc & DASENC_VALID)==(DASENC_VALID))
72 
121  DasCodec* pThis, DasAry* pAry, const char* sSemantic, const char* sEncType,
122  int16_t uSzEach, ubyte cSep, das_units epoch
123 );
124 
158 DAS_API int DasCodec_decode(
159  DasCodec* pThis, const ubyte* pBuf, int nBufLen, int nExpect, int* pValsRead
160 );
161 
166 DAS_API void DasCodec_deInit(DasCodec* pThis);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 
173 #endif /* _das_codec_h_ */
A dynamic buffer with multi-dimensional array style access.
DAS_API int DasCodec_decode(DasCodec *pThis, const ubyte *pBuf, int nBufLen, int nExpect, int *pValsRead)
Read values from a simple buffer into an array.
DAS_API void DasCodec_deInit(DasCodec *pThis)
Release the reference count on the array given to this encoder/decoder.
DAS_API DasErrCode DasCodec_init(DasCodec *pThis, DasAry *pAry, const char *sSemantic, const char *sEncType, int16_t uSzEach, ubyte cSep, das_units epoch)
Initialize a serial buffer decoder/encoder.
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition: defs.h:164
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition: units.h:139
das_val_type
Enumeration of types stored in Das Array (DasAry) objects from value.h.
Definition: value.h:64
Dynamic recursive ragged arrays.
Definition: array.h:270
Reading and writing array data to buffers.
Definition: codec.h:40
A generic value type for use in arrays, datums and variables.