Fix licensing issues
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / e2ap_engine / ber_tlv_tag.h
1
2 /*-
3  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _BER_TLV_TAG_H_
7 #define _BER_TLV_TAG_H_
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 enum asn_tag_class {
14         ASN_TAG_CLASS_UNIVERSAL         = 0,    /* 0b00 */
15         ASN_TAG_CLASS_APPLICATION       = 1,    /* 0b01 */
16         ASN_TAG_CLASS_CONTEXT           = 2,    /* 0b10 */
17         ASN_TAG_CLASS_PRIVATE           = 3     /* 0b11 */
18 };
19 typedef unsigned ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */
20
21 /*
22  * Tag class is encoded together with tag value for optimization purposes.
23  */
24 #define BER_TAG_CLASS(tag)      ((tag) & 0x3)
25 #define BER_TAG_VALUE(tag)      ((tag) >> 2)
26 #define BER_TLV_CONSTRUCTED(tagptr)     (((*(const uint8_t *)tagptr)&0x20)?1:0)
27
28 #define BER_TAGS_EQUAL(tag1, tag2)      ((tag1) == (tag2))
29
30 /*
31  * Several functions for printing the TAG in the canonical form
32  * (i.e. "[PRIVATE 0]").
33  * Return values correspond to their libc counterparts (if any).
34  */
35 ssize_t ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t buflen);
36 ssize_t ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *);
37 char *ber_tlv_tag_string(ber_tlv_tag_t tag);
38
39
40 /*
41  * This function tries to fetch the tag from the input stream.
42  * RETURN VALUES:
43  *       0:     More data expected than bufptr contains.
44  *      -1:     Fatal error deciphering tag.
45  *      >0:     Number of bytes used from bufptr. tag_r will contain the tag.
46  */
47 ssize_t ber_fetch_tag(const void *bufptr, size_t size, ber_tlv_tag_t *tag_r);
48
49 /*
50  * This function serializes the tag (T from TLV) in BER format.
51  * It always returns number of bytes necessary to represent the tag,
52  * it is a caller's responsibility to check the return value
53  * against the supplied buffer's size.
54  */
55 size_t ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufptr, size_t size);
56
57 #ifdef __cplusplus
58 }
59 #endif
60
61 #endif  /* _BER_TLV_TAG_H_ */