Adding initial code jy.oak@samsung.com
[ric-app/kpimon.git] / asn1c_defs / all-defs / asn_bit_data.h
1 /*\r
2  * Copyright (c) 2005-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.\r
3  * Redistribution and modifications are permitted subject to BSD license.\r
4  */\r
5 #ifndef ASN_BIT_DATA\r
6 #define ASN_BIT_DATA\r
7 \r
8 #include <asn_system.h>         /* Platform-specific types */\r
9 \r
10 #ifdef __cplusplus\r
11 extern "C" {\r
12 #endif\r
13 \r
14 /*\r
15  * This structure describes a position inside an incoming PER bit stream.\r
16  */\r
17 typedef struct asn_bit_data_s {\r
18   const uint8_t *buffer;  /* Pointer to the octet stream */\r
19          size_t  nboff;   /* Bit offset to the meaningful bit */\r
20          size_t  nbits;   /* Number of bits in the stream */\r
21          size_t  moved;   /* Number of bits moved through this bit stream */\r
22   int (*refill)(struct asn_bit_data_s *);\r
23   void *refill_key;\r
24 } asn_bit_data_t;\r
25 \r
26 /*\r
27  * Create a contiguous non-refillable bit data structure.\r
28  * Can be freed by FREEMEM().\r
29  */\r
30 asn_bit_data_t *asn_bit_data_new_contiguous(const void *data, size_t size_bits);\r
31 \r
32 /*\r
33  * Extract a small number of bits (<= 31) from the specified PER data pointer.\r
34  * This function returns -1 if the specified number of bits could not be\r
35  * extracted due to EOD or other conditions.\r
36  */\r
37 int32_t asn_get_few_bits(asn_bit_data_t *, int get_nbits);\r
38 \r
39 /* Undo the immediately preceeding "get_few_bits" operation */\r
40 void asn_get_undo(asn_bit_data_t *, int get_nbits);\r
41 \r
42 /*\r
43  * Extract a large number of bits from the specified PER data pointer.\r
44  * This function returns -1 if the specified number of bits could not be\r
45  * extracted due to EOD or other conditions.\r
46  */\r
47 int asn_get_many_bits(asn_bit_data_t *, uint8_t *dst, int right_align,\r
48                         int get_nbits);\r
49 \r
50 /* Non-thread-safe debugging function, don't use it */\r
51 char *asn_bit_data_string(asn_bit_data_t *);\r
52 \r
53 /*\r
54  * This structure supports forming bit output.\r
55  */\r
56 typedef struct asn_bit_outp_s {\r
57         uint8_t *buffer;        /* Pointer into the (tmpspace) */\r
58         size_t nboff;           /* Bit offset to the meaningful bit */\r
59         size_t nbits;           /* Number of bits left in (tmpspace) */\r
60         uint8_t tmpspace[32];   /* Preliminary storage to hold data */\r
61         int (*output)(const void *data, size_t size, void *op_key);\r
62         void *op_key;           /* Key for (output) data callback */\r
63         size_t flushed_bytes;   /* Bytes already flushed through (output) */\r
64 } asn_bit_outp_t;\r
65 \r
66 /* Output a small number of bits (<= 31) */\r
67 int asn_put_few_bits(asn_bit_outp_t *, uint32_t bits, int obits);\r
68 \r
69 /* Output a large number of bits */\r
70 int asn_put_many_bits(asn_bit_outp_t *, const uint8_t *src, int put_nbits);\r
71 \r
72 /*\r
73  * Flush whole bytes (0 or more) through (outper) member.\r
74  * The least significant bits which are not used are guaranteed to be set to 0.\r
75  * Returns -1 if callback returns -1. Otherwise, 0.\r
76  */\r
77 int asn_put_aligned_flush(asn_bit_outp_t *);\r
78 \r
79 #ifdef __cplusplus\r
80 }\r
81 #endif\r
82 \r
83 #endif  /* ASN_BIT_DATA */\r