das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
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 <das3/value.h>
26#include <das3/array.h>
27#include <das3/buffer.h>
28
29#include <das3/encoding.h> /* <-- only to get DASENC_FMT_LEN */
30 /* otherwise independent */
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/* Not public, only here because used in a macro */
37#define DASENC_VALID 0x0001
38
45typedef struct das_codec {
46
47 bool bResLossWarn; /* If true, the resolution loss warning has already been emitted */
48
49 uint32_t uProc; /* Internal processing flags setup on the call to _init */
50
51 int nAryValSz; /* The size of each array value in internal buffer */
52
53 const char* sEncType; /* a canonical DAS_ENC_* global, or NULL */
54
55 int16_t nBufValSz; /* Width of a single value in the external buffer, -1 is */
56
57 das_val_type vtBuf; /* The value type in the external buffer */
58
59 const char* sSemantic; /* Intended meaning: a canonical DAS_SEM_* global, or NULL */
60
61 DasAry* pAry; /* The array for which values are encoded/decoded */
62
63 ubyte nSep;
64 char sSepSet[VARIDX_MAX]; /* Split strings on these chars by rank */
65
66 ubyte nExtRagged; /* Number of the variable's EXTERNAL ragged indices inside a packet
67 (excludes the packet-framed streaming index and any internal axis
68 such as a string's chars). This is the count of idxTerm run
69 terminators the var needs; set from the index= shape at creation. */
70
71 bool bItemLen; /* Ignore nSep, read val lengths from packet data */
72
73 uint32_t uMaxString; /* If we are storing fixed strings, this is set */
74
75 das_units timeUnits; /* If ascii times are to be stored as an integral type
76 this is needed */
77
78 /* For output, the sprintf string (if UTF8) or the stream encode type */
79 char sOutFmt[DASENC_FMT_LEN];
80
81 char* pOverflow; /* If the size of a variable length value breaks the */
82 size_t uOverflow; /* small vector assumption, extra space is here */
83
84} DasCodec;
85
86
87#define DASENC_VARSZOUT -1
88#define DASENC_READ true
89#define DASENC_WRITE false
90
91#define DASENC_ITEM_TERM -9 /* Packet items are terminated by a special byte sequence
92 aka: "Hi There!|Go Away.|" */
93
94#define DASENC_ITEM_LEN -1 /* Packet items have explicit byte lengths in packets
95 aka: "|9|Hi There!|8|Go Away." */
96
101#define DasCodec_isValid(pCd) (((pCd)->uProc & DASENC_VALID)==(DASENC_VALID))
102
163DAS_API DasErrCode DasCodec_init(
164 bool bRead, DasCodec* pThis, DasAry* pAry, const char* sSemantic,
165 const char* sEncType, int16_t uSzEach, ubyte cSep, das_units epoch,
166 const char* sOutFmt
167);
168
212DAS_API DasErrCode DasCodec_update(
213 bool bRead, DasCodec* pThis, const char* sEncType, int16_t uSzEach,
214 ubyte cSep, das_units epoch, const char* sOutFmt
215);
216
220DAS_API void DasCodec_eatSpace(DasCodec* pThis, bool bEat);
221
230DAS_API void DasCodec_setTrim(DasCodec* pThis, bool bTrim);
231
236DAS_API bool DasCodec_isTrim(const DasCodec* pThis);
237
246DAS_API void DasCodec_postBlit(DasCodec* pThis, DasAry* pAry);
247
267DAS_API DasErrCode DasCodec_setIdxTerms(DasCodec* pThis, ubyte nLevels, const char* sLevels);
268
273DAS_API bool DasCodec_isReader(const DasCodec* pThis);
274
282DAS_API bool DasCodec_isText(const DasCodec* pThis);
283
317DAS_API int DasCodec_decode(
318 DasCodec* pThis, const ubyte* pBuf, int nBufLen, int nExpect, int* pValsRead
319);
320
332DAS_API int DasCodec_raggedIndices(const DasCodec* pThis, int* aRagIdx);
333
355DAS_API int DasCodec_decodeRuns(
356 DasCodec* pThis, const ubyte* pBuf, int nBufLen, bool bLastVar, int* pValsRead
357);
358
359#define DASENC_PKT_LAST 0x02
360#define DASENC_IN_HDR 0x04
361
401DAS_API int DasCodec_encode(
402 DasCodec* pThis, DasBuf* pBuf, int nDim, ptrdiff_t* pLoc, int nExpect,
403 uint32_t uFlags
404);
405
418DAS_API int DasCodec_encodeRuns(DasCodec* pThis, DasBuf* pBuf, ptrdiff_t iRec);
419
424DAS_API void DasCodec_deInit(DasCodec* pThis);
425
426#ifdef __cplusplus
427}
428#endif
429
430
431#endif /* _das_codec_h_ */
A dynamic buffer with multi-dimensional array style access.
Utility to assist with encode and decode operations.
Defines storage and access methods for values in a das stream.
#define VARIDX_MAX
Max index count for the model.
Definition generator.h:55
DAS_API int DasCodec_encode(DasCodec *pThis, DasBuf *pBuf, int nDim, ptrdiff_t *pLoc, int nExpect, uint32_t uFlags)
Write values from an array into a buffer, does not change the array.
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition defs.h:184
const char * das_units
Handle SI and other units, with accommodations for Epoch systems, from units.h.
Definition units.h:144
das_val_type
Enumeration of types stored in Das Array (DasAry) objects from value.h.
Definition value.h:81
Dynamic recursive ragged arrays.
Definition array.h:271
Buffer class to handle accumulating byte streams.
Definition buffer.h:47
Reading and writing array data to buffers.
Definition codec.h:45
A generic value type for use in arrays, datums and variables.