Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | /* |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame^] | 15 | * This structure describes a position inside an incoming PER bit stream. |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 16 | */ |
| 17 | typedef struct asn_per_data_s { |
Lev Walkin | 1d9e8dd | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 18 | 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 Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 21 | } asn_per_data_t; |
| 22 | |
| 23 | /* |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame^] | 24 | * This structure supports forming PER output. |
| 25 | */ |
| 26 | typedef 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 Walkin | 6036488 | 2005-11-28 06:58:11 +0000 | [diff] [blame] | 36 | * Extract a small number of bits (<= 31) from the specified PER data pointer. |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 37 | * This function returns -1 if the specified number of bits could not be |
| 38 | * extracted due to EOD or other conditions. |
| 39 | */ |
| 40 | int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits); |
| 41 | |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame^] | 42 | /* Output a small number of bits (<= 31) */ |
| 43 | int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits); |
| 44 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 45 | /* |
| 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 | */ |
| 50 | int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align, |
| 51 | int get_nbits); |
| 52 | |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame^] | 53 | /* Output a large number of bits */ |
| 54 | int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits); |
| 55 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Get the length "n" from the Unaligned PER stream. |
| 58 | */ |
| 59 | ssize_t uper_get_length(asn_per_data_t *pd, |
| 60 | int effective_bound_bits, |
| 61 | int *repeat); |
| 62 | |
| 63 | /* |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame^] | 64 | * 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 | */ |
| 68 | ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length); |
| 69 | |
| 70 | /* |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 71 | * Get the normally small non-negative whole number. |
| 72 | */ |
| 73 | ssize_t uper_get_nsnnwn(asn_per_data_t *pd); |
| 74 | |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame^] | 75 | /* |
| 76 | * Put the normally small non-negative whole number. |
| 77 | */ |
| 78 | int uper_put_nsnnwn(asn_per_outp_t *po, int n); |
| 79 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 80 | #ifdef __cplusplus |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | #endif /* _PER_SUPPORT_H_ */ |