--- /dev/null
+/*\r
+ * Copyright (c) 2005-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.\r
+ * Redistribution and modifications are permitted subject to BSD license.\r
+ */\r
+#ifndef ASN_BIT_DATA\r
+#define ASN_BIT_DATA\r
+\r
+#include <asn_system.h> /* Platform-specific types */\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*\r
+ * This structure describes a position inside an incoming PER bit stream.\r
+ */\r
+typedef struct asn_bit_data_s {\r
+ const uint8_t *buffer; /* Pointer to the octet stream */\r
+ size_t nboff; /* Bit offset to the meaningful bit */\r
+ size_t nbits; /* Number of bits in the stream */\r
+ size_t moved; /* Number of bits moved through this bit stream */\r
+ int (*refill)(struct asn_bit_data_s *);\r
+ void *refill_key;\r
+} asn_bit_data_t;\r
+\r
+/*\r
+ * Create a contiguous non-refillable bit data structure.\r
+ * Can be freed by FREEMEM().\r
+ */\r
+asn_bit_data_t *asn_bit_data_new_contiguous(const void *data, size_t size_bits);\r
+\r
+/*\r
+ * Extract a small number of bits (<= 31) from the specified PER data pointer.\r
+ * This function returns -1 if the specified number of bits could not be\r
+ * extracted due to EOD or other conditions.\r
+ */\r
+int32_t asn_get_few_bits(asn_bit_data_t *, int get_nbits);\r
+\r
+/* Undo the immediately preceeding "get_few_bits" operation */\r
+void asn_get_undo(asn_bit_data_t *, int get_nbits);\r
+\r
+/*\r
+ * Extract a large number of bits from the specified PER data pointer.\r
+ * This function returns -1 if the specified number of bits could not be\r
+ * extracted due to EOD or other conditions.\r
+ */\r
+int asn_get_many_bits(asn_bit_data_t *, uint8_t *dst, int right_align,\r
+ int get_nbits);\r
+\r
+/* Non-thread-safe debugging function, don't use it */\r
+char *asn_bit_data_string(asn_bit_data_t *);\r
+\r
+/*\r
+ * This structure supports forming bit output.\r
+ */\r
+typedef struct asn_bit_outp_s {\r
+ uint8_t *buffer; /* Pointer into the (tmpspace) */\r
+ size_t nboff; /* Bit offset to the meaningful bit */\r
+ size_t nbits; /* Number of bits left in (tmpspace) */\r
+ uint8_t tmpspace[32]; /* Preliminary storage to hold data */\r
+ int (*output)(const void *data, size_t size, void *op_key);\r
+ void *op_key; /* Key for (output) data callback */\r
+ size_t flushed_bytes; /* Bytes already flushed through (output) */\r
+} asn_bit_outp_t;\r
+\r
+/* Output a small number of bits (<= 31) */\r
+int asn_put_few_bits(asn_bit_outp_t *, uint32_t bits, int obits);\r
+\r
+/* Output a large number of bits */\r
+int asn_put_many_bits(asn_bit_outp_t *, const uint8_t *src, int put_nbits);\r
+\r
+/*\r
+ * Flush whole bytes (0 or more) through (outper) member.\r
+ * The least significant bits which are not used are guaranteed to be set to 0.\r
+ * Returns -1 if callback returns -1. Otherwise, 0.\r
+ */\r
+int asn_put_aligned_flush(asn_bit_outp_t *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* ASN_BIT_DATA */\r