libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
encoding.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * This file is part of libdas2, the Core Das2 C Library.
4  *
5  * Libdas2 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  * Libdas2 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 libdas2; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
23 #ifndef _das_encoding_h_
24 #define _das_encoding_h_
25 
26 #include <das2/util.h>
27 #include <das2/units.h>
28 #include <das2/buffer.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
35 double getDas2Fill(void);
36 
38 int isDas2Fill( double value );
39 
40 
41 /* Most Significant byte First (big-endian) IEEE-754 reals */
42 #define DAS2DT_BE_REAL 0x0001
43 
44 /* Most Significant byte last (little-endian) IEEE-754 reals */
45 #define DAS2DT_LE_REAL 0x0002
46 
47 #ifdef HOST_IS_LSB_FIRST
48 #define DAS2DT_HOST_REAL 0x0002
49 #else
50 #define DAS2DT_HOST_REAL 0x0001
51 #endif
52 
53 /* A real number formatted in some number of characters.
54  * Conventionally there are a whitespace characters to improve readability,
55  * but this is not required. The formatted number should be parsable by
56  * scanf in C, readf in IDL, or Double.parseDouble in java.
57  */
58 #define DAS2DT_ASCII 0x0003
59 
60 /* A date-time formatted as an ASCII ISO-8601 string.
61  * Actually any time that is parseable by the parsetime routine will work
62  * Generally if a human can read it, it's parseable. For example,
63  * YYYY-MM-DDThh:mm:ss.mmmZ.
64  */
65 #define DAS2DT_TIME 0x0004
66 
67 /* Most Significant byte First (big-endian) signed integers */
68 #define DAS2DT_BE_INT 0x0005
69 
70 /* Most Significant byte last (little-endian) signed integers */
71 #define DAS2DT_LE_INT 0x0006
72 
73 /* Most Significant byte First (big-endian) un-signed integers */
74 #define DAS2DT_BE_UINT 0x0007
75 
76 /* Most Significant byte last (little-endian) un-signed integers */
77 #define DAS2DT_LE_UINT 0x0008
78 
79 #define DASENC_FMT_LEN 64
80 #define DASENC_TYPE_LEN 48
81 
82 
108 typedef struct das_encoding{
119  unsigned int nCat;
120 
126  unsigned int nWidth;
127 
133  char sFmt[DASENC_FMT_LEN];
134 
140  char sType[DASENC_TYPE_LEN];
141 
142 } DasEncoding;
143 
177 DasEncoding* new_DasEncoding(int nCat, int nWidth, const char* sFmt);
178 
192 DasEncoding* new_DasEncoding_str(const char* sType);
193 
194 
197 
198 
206 bool DasEnc_equals(const DasEncoding* pOne, const DasEncoding* pTwo);
207 
233 void DasEnc_setAsciiFormat(DasEncoding* pThis, const char* sValFmt,
234  int nFmtWidth);
235 
236 
270 void DasEnc_setTimeFormat(DasEncoding* pThis, const char* sTimeFmt,
271  int nFmtWidth);
272 
273 
274 /* More explicit indication of a big-endian 8-byte number */
275 #define DAS2DT_BE_REAL_8 0x0801
276 
277 /* little-endian (least significant byte first) 8-byte real */
278 #define DAS2DT_LE_REAL_8 0x0802
279 
280 /* 8-byte real number, in host byte order */
281 #ifdef HOST_IS_LSB_FIRST
282 #define DAS2DT_DOUBLE 0x0802
283 #else
284 #define DAS2DT_DOUBLE 0x0801
285 #endif
286 
287 /* More explicit indication of a big-endian 4-byte number */
288 #define DAS2DT_BE_REAL_4 0x0401
289 
290 /* little-endian (least significant byte first) 4-byte real */
291 #define DAS2DT_LE_REAL_4 0x0402
292 
293 
295 #ifdef HOST_IS_LSB_FIRST
296 #define DAS2DT_FLOAT 0x0402
297 #else
298 #define DAS2DT_FLOAT 0x0401
299 #endif
300 
301 /* Legacy specific width encoding */
302 #define DAS2DT_ASCII_10 0x0A03
303 #define DAS2DT_ASCII_24 0x1804
304 #define DAS2DT_ASCII_14 0x0E04
305 
306 #define DAS2DT_TIME_25 0x1904
307 #define DAS2DT_TIME_28 0x1c04
308 
309 
340 unsigned int DasEnc_hash(const DasEncoding* pThis);
341 
342 
359 DasErrCode DasEnc_toStr(DasEncoding* pThis, char* sType, size_t nLen);
360 
361 
380 DasErrCode DasEnc_write(DasEncoding* pThis, DasBuf* pBuf, double value,
381  das_units units);
382 
383 
384 /* (Not Implemented)
385  * Encode and write a value to a buffer.
386  *
387  * Similar to DasEnc_write except this version outputs to a DasBuf object.
388  *
389  * @param pThis the DasEncoding object to handle the translation
390  * @param pBuf the buffer to receive the encoded bytes
391  * @param value the numeric value to write
392  * @param units Handles scaling and offset of values if needed.
393  *
394  * @returns 0 on success, a positive error code on failure.
395  * @memberof DasEncoding
396  */
397 /* ErrorCode DasEnc_encode(
398  DasEncoding* pThis, DasBuf* pBuf, double value, UnitType units
399 ); */
400 
421  const DasEncoding* pThis, DasBuf* pBuf, das_units units, double* pOut
422 );
423 
424 #ifdef __cplusplus
425 }
426 #endif
427 
428 #endif /* _das_encoding_h_ */
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition: util.h:117
void DasEnc_setTimeFormat(DasEncoding *pThis, const char *sTimeFmt, int nFmtWidth)
Set the output format to be used when converting binary time values to to ASCII strings.
Little buffer class to handle accumulating string data.
Definition: buffer.h:49
void DasEnc_setAsciiFormat(DasEncoding *pThis, const char *sValFmt, int nFmtWidth)
Set the output format to be used when converting interal binary values to ASCII strings.
DasErrCode DasEnc_read(const DasEncoding *pThis, DasBuf *pBuf, das_units units, double *pOut)
Read and Decode a value from a string.
unsigned int nCat
The basic encoding category.
Definition: encoding.h:119
DasEncoding * new_DasEncoding_str(const char *sType)
Create a new encoding based on the encoding type string.
Reading and writing values on das2 streams.
Definition: encoding.h:108
bool DasEnc_equals(const DasEncoding *pOne, const DasEncoding *pTwo)
Check for equality between two encodings.
DasEncoding * new_DasEncoding(int nCat, int nWidth, const char *sFmt)
Make a new data encoder/decoder.
DasErrCode DasEnc_toStr(DasEncoding *pThis, char *sType, size_t nLen)
Get a string representation of the data type.
Defines units used for items in the stream, most notably time units that reference an epoch and a ste...
DasEncoding * DasEnc_copy(DasEncoding *pThis)
Deepcopy a DasEncoding pointer.
Utility to assist with encode and decode operations.
double getDas2Fill(void)
An inconvenient way to get canonical fill value, -1e31.
unsigned int DasEnc_hash(const DasEncoding *pThis)
Get a hash value suitable for use in switch statements.
DasErrCode DasEnc_write(DasEncoding *pThis, DasBuf *pBuf, double value, das_units units)
Encode and write a value onto a string.
unsigned int nWidth
The width in bytes of the encoded values.
Definition: encoding.h:126
const char * das_units
Enumeration of unit types, that correspond to physical unit types.
Definition: units.h:135
int isDas2Fill(double value)
An inconvenient way to check for the canonical fill value, -1e31.