das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
stream.h
Go to the documentation of this file.
1/* Copyright (C) 2015-2024 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * Adapted from:
4 * Copyright (C) 2006 Jeremy Faden <jeremy-faden@uiowa.edu>
5 *
6 * This file is part of das2C, the Core Das2 C Library.
7 *
8 * das2C is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License version 2.1 as published
10 * by the Free Software Foundation.
11 *
12 * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
19 */
20
23#ifndef _das_stream_h_
24#define _das_stream_h_
25
26#include <stdbool.h>
27#include <das3/packet.h>
28#include <das3/dataset.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#define STREAM_MODEL_MIXED -1
35#define STREAM_MODEL_V2 2
36#define STREAM_MODEL_V3 3
37
38#define STREAMDESC_CMP_SZ 48
39#define STREAMDESC_VER_SZ 48
40#define STREAMDESC_TYPE_SZ 48
41
42#define MAX_PKTIDS 100
43
44
91typedef struct das_stream{
94
95 /* TODO: Replace this with a sorted array of structures of the type
96
97 {int id, DasDesc* pDesc}
98
99 and use sorted insert and binary search to retrieve packet IDs
100 if greater then say 10. For 10 or less the "small vector"
101 assumption applies and we just an embedded 10-element array
102 and loops.
103 */
104 DasDesc* descriptors[MAX_PKTIDS];
105
106 /* Common properties */
107 char compression[STREAMDESC_CMP_SZ];
108 char type[STREAMDESC_TYPE_SZ];
109 char version[STREAMDESC_VER_SZ];
110 bool bDescriptorSent;
111
112 /* Reader opt-in: recover an undecodable embedded format (a mime'd blob with no
113 registered codec extension) as opaque per-record bytes instead of failing.
114 Set from DasIO_embedAsBytes() when the stream descriptor is decoded; the
115 dataset parser reads it via DasStream_getEmbedAsBytes(). */
116 bool bEmbedAsBytes;
117
125 void* pUser;
126} DasStream;
127
134#define StreamDesc DasStream
135
143#define DasStream_getEmbedAsBytes(P) ((P)->bEmbedAsBytes)
144
152
153#define new_StreamDesc new_DasStream
154
155DAS_API DasStream* new_DasStream_str(DasBuf* pBuf, int nModel);
156
157#define new_StreamDesc_str new_DasStream_str
158
164DAS_API char* DasStream_info(const DasStream* pSd, char* sBuf, int nLen);
165
166#define StreamDesc_info DasStream_info
167
186DAS_API DasStream* DasStream_copy(const DasStream* pThis);
187
188#define StreamDesc_copy DasStream_copy
189
197DAS_API void del_DasStream(DasStream* pThis);
198
199#define del_StreamDesc del_DasStream
200
217DAS_API size_t DasStream_getNPktDesc(const DasStream* pThis);
218
219#define StreamDesc_getNPktDesc DasStream_getNPktDesc
220
244DAS_API DasDesc* DasStream_nextDesc(const DasStream* pThis, int* pPrevPktId);
245
246#define StreamDesc_nextPktDesc DasStream_nextDesc
247
264DAS_API DasErrCode DasStream_addDesc(DasStream* pThis, DasDesc* pDesc, int nPktId);
265
266#define StreamDesc_addPktDesc DasStream_addDesc
267
283DAS_API DasErrCode DasStream_shadowPktDesc(DasStream* pThis, DasDesc* pDesc, int nPktId);
284
301DAS_API DasErrCode DasStream_takePktDesc(DasStream* pThis, DasDesc* pDesc, int nPktId);
302
322DAS_API DasErrCode DasStream_rmDesc(DasStream* pThis, DasDesc* pDesc, int nPktId);
323
324#define DasStream_rmPktDesc DasStream_rmDesc
325
330DAS_API void DasStream_setMonotonic(DasStream* pThis, bool isMonotonic );
331
332#define StreamDesc_setMonotonic DasStream_setMonotonic
333
339DAS_API void DasStream_addStdProps(DasStream* pThis);
340
341#define StreamDesc_addStdProps DasStream_addStdProps
342
347DAS_API void DasStream_addCmdLineProp(DasStream* pThis, int argc, char* argv[] );
348
349#define StreamDesc_addCmdLineProp DasStream_addCmdLineProp
350
375 DasStream* pThis, DasEncoding* pXEncoder, das_units xUnits
376);
377
378#define StreamDesc_createPktDesc DasStream_createPktDesc
379
380
381
394
395#define StreamDesc_clonePktDesc DasStream_clonePktDesc
396
410 DasStream* pThis, const DasStream* pOther, int nPktId
411);
412
413#define StreamDesc_clonePktDescById DasStream_clonePktDescById
414
422DAS_API bool DasStream_isValidId(const DasStream* pThis, int nPktId);
423
424#define StreamDesc_isValidId DasStream_isValidId
425
435DAS_API PktDesc* DasStream_getPktDesc(const DasStream* pThis, int id);
436
437#define StreamDesc_getPktDesc DasStream_getPktDesc
438
449DAS_API DasDesc* DasStream_getDesc(const DasStream* pThis, int id);
450
463DAS_API int DasStream_getPktId(DasStream* pThis, const DasDesc* pDesc);
464
465
466DAS_API DasErrCode DasStream_freeDatDesc(DasStream* pThis, int nPktId);
467
468#define StreamDesc_freeDesc DasStream_freeDatDesc
469
473DAS_API int DasStream_getOffset(DasStream* pThis);
474
475#define StreamDesc_getOffset DasStream_getOffset
476
485
486#define StreamDesc_encode DasStream_encode2
487
496
512 DasBuf* pBuf, DasStream* pSd, int nPktId, int nModel
513);
514
515
516#ifdef __cplusplus
517}
518#endif
519
520#endif /* _das_stream_h_ */
Objects which correlate arrays in index space.
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_API bool DasStream_isValidId(const DasStream *pThis, int nPktId)
Check to see if an packet ID has been defined for the stream.
DAS_API DasDesc * DasDesc_decode(DasBuf *pBuf, DasStream *pSd, int nPktId, int nModel)
Packetized Stream Descriptor Factory Function.
Buffer class to handle accumulating byte streams.
Definition buffer.h:47
Base structure for Stream Header Items.
Definition descriptor.h:74
Reading and writing values to buffers.
Definition encoding.h:108
Describes the stream itself, in particular the compression used, current packetDescriptors,...
Definition stream.h:91
DAS_API PktDesc * DasStream_createPktDesc(DasStream *pThis, DasEncoding *pXEncoder, das_units xUnits)
Creates a descriptor structure that for a stream packet type.
DAS_API DasErrCode DasStream_takePktDesc(DasStream *pThis, DasDesc *pDesc, int nPktId)
Take ownership of a dataset (DasDs or PktDesc)
DAS_API DasErrCode DasStream_addDesc(DasStream *pThis, DasDesc *pDesc, int nPktId)
Attach a packet descriptor to this stream.
DAS_API DasErrCode DasStream_encode3(DasStream *pThis, DasBuf *pBuf)
Encode a DasStream to an version 3 XML string.
DAS_API PktDesc * DasStream_getPktDesc(const DasStream *pThis, int id)
Get the packet descriptor associated with an ID.
DAS_API DasDesc * DasStream_getDesc(const DasStream *pThis, int id)
Get any descriptor associated with a packet ID.
DAS_API void del_DasStream(DasStream *pThis)
Delete a stream descriptor and all it's sub objects.
DAS_API int DasStream_getOffset(DasStream *pThis)
An I/O function that makes sense to use for either operation.
DAS_API DasStream * new_DasStream(void)
Creates a new blank StreamDesc.
DAS_API char * DasStream_info(const DasStream *pSd, char *sBuf, int nLen)
Print a short description of the stream to a string buffer, This is not a serialization,...
DAS_API DasErrCode DasStream_shadowPktDesc(DasStream *pThis, DasDesc *pDesc, int nPktId)
Loosely attach a dataset (DasDs or PktDesc) to this stream.
DAS_API int DasStream_getPktId(DasStream *pThis, const DasDesc *pDesc)
If a data container is owned by this stream object, return it's packet ID.
DAS_API void DasStream_setMonotonic(DasStream *pThis, bool isMonotonic)
Indicates if the xtags on the stream are monotonic, in which case there might be optimal ways of proc...
DAS_API void DasStream_addStdProps(DasStream *pThis)
Adds metadata into the property set of the DasStream.
DAS_API DasErrCode DasStream_encode2(DasStream *pThis, DasBuf *pBuf)
Encode a DasStream to an version 2 XML string.
DAS_API PktDesc * DasStream_clonePktDescById(DasStream *pThis, const DasStream *pOther, int nPktId)
Deepcopy a PacketDescriptor from one stream to another.
DAS_API void DasStream_addCmdLineProp(DasStream *pThis, int argc, char *argv[])
Adds the command line into the property set of the DasStream.
DasDesc base
The base structure.
Definition stream.h:93
DAS_API DasErrCode DasStream_rmDesc(DasStream *pThis, DasDesc *pDesc, int nPktId)
Detach a packet descriptor from this stream.
DAS_API DasDesc * DasStream_nextDesc(const DasStream *pThis, int *pPrevPktId)
Iterate over packet descriptors.
DAS_API DasStream * DasStream_copy(const DasStream *pThis)
Creates a deep-copy of an existing DasStream object.
DAS_API size_t DasStream_getNPktDesc(const DasStream *pThis)
Get the number of packet descriptors defined for this stream.
DAS_API PktDesc * DasStream_clonePktDesc(DasStream *pThis, const PktDesc *pd)
Make a deep copy of a PacketDescriptor on a new stream.
void * pUser
User data pointer.
Definition stream.h:125
Holds information for a single packet type in a Das2 stream.
Definition packet.h:138