blob: 747abe27b84f42a82889891400b32ab86255188d [file] [log] [blame]
Lev Walkin59b176e2005-11-26 11:25:14 +00001/*
2 * Copyright (c) 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _PER_SUPPORT_H_
6#define _PER_SUPPORT_H_
7
8#include <asn_system.h> /* Platform-specific types */
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/*
Lev Walkin523de9e2006-08-18 01:34:18 +000015 * This structure describes a position inside an incoming PER bit stream.
Lev Walkin59b176e2005-11-26 11:25:14 +000016 */
17typedef struct asn_per_data_s {
Lev Walkin1d9e8dd2005-12-07 05:46:03 +000018 const uint8_t *buffer; /* Pointer to the octet stream */
19 size_t nboff; /* Bit offset to the meaningful bit */
20 size_t nbits; /* Number of bits in the stream */
Lev Walkin59b176e2005-11-26 11:25:14 +000021} asn_per_data_t;
22
23/*
Lev Walkin523de9e2006-08-18 01:34:18 +000024 * This structure supports forming PER output.
25 */
26typedef struct asn_per_outp_s {
27 uint8_t *buffer; /* Pointer into the (tmpspace) */
28 size_t nboff; /* Bit offset to the meaningful bit */
29 size_t nbits; /* Number of bits left in (tmpspace) */
30 uint8_t tmpspace[32]; /* Preliminary storage to hold data */
31 int (*outper)(const void *data, size_t size, void *op_key);
32 void *op_key;
33} asn_per_outp_t;
34
35/*
Lev Walkin60364882005-11-28 06:58:11 +000036 * Extract a small number of bits (<= 31) from the specified PER data pointer.
Lev Walkin59b176e2005-11-26 11:25:14 +000037 * This function returns -1 if the specified number of bits could not be
38 * extracted due to EOD or other conditions.
39 */
40int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits);
41
Lev Walkin523de9e2006-08-18 01:34:18 +000042/* Output a small number of bits (<= 31) */
43int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits);
44
Lev Walkin59b176e2005-11-26 11:25:14 +000045/*
46 * Extract a large number of bits from the specified PER data pointer.
47 * This function returns -1 if the specified number of bits could not be
48 * extracted due to EOD or other conditions.
49 */
50int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align,
51 int get_nbits);
52
Lev Walkin523de9e2006-08-18 01:34:18 +000053/* Output a large number of bits */
54int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits);
55
Lev Walkin59b176e2005-11-26 11:25:14 +000056/*
57 * Get the length "n" from the Unaligned PER stream.
58 */
59ssize_t uper_get_length(asn_per_data_t *pd,
60 int effective_bound_bits,
61 int *repeat);
62
63/*
Lev Walkin523de9e2006-08-18 01:34:18 +000064 * Put the length "n" to the Unaligned PER stream.
65 * This function returns the number of units which may be flushed
66 * in the next units saving iteration.
67 */
68ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length);
69
70/*
Lev Walkin59b176e2005-11-26 11:25:14 +000071 * Get the normally small non-negative whole number.
72 */
73ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
74
Lev Walkin523de9e2006-08-18 01:34:18 +000075/*
76 * Put the normally small non-negative whole number.
77 */
78int uper_put_nsnnwn(asn_per_outp_t *po, int n);
79
Lev Walkin59b176e2005-11-26 11:25:14 +000080#ifdef __cplusplus
81}
82#endif
83
84#endif /* _PER_SUPPORT_H_ */