ROHC compression/decompression library
sdvl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011,2012,2013 Didier Barvaux
3  * Copyright 2007,2009,2010,2013 Viveris Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file sdvl.h
22  * @brief Self-Describing Variable-Length (SDVL) encoding
23  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
24  * @author Didier Barvaux <didier@barvaux.org>
25  */
26 
27 #ifndef ROHC_COMMON_SDVL_H
28 #define ROHC_COMMON_SDVL_H
29 
30 #include <stdlib.h>
31 #include <stdint.h>
32 #ifdef __KERNEL__
33 # include <linux/types.h>
34 #else
35 # include <stdbool.h>
36 #endif
37 
38 
39 /*
40  * Constants related to fields length for SDVL-encoding
41  */
42 
43 /** The maximum numbers of bits that can be SDVL-encoded in 1, 2, 3
44  * and 4 bytes */
45 typedef enum
46 {
47  /** Maximum number of bits in 1 SDVL-encoded byte */
49  /** Maximum number of bits in 2 SDVL-encoded byte */
51  /** Maximum number of bits in 3 SDVL-encoded byte */
53  /** Maximum number of bits in 4 SDVL-encoded byte */
56 
57 
58 /*
59  * Function prototypes.
60  */
61 
62 bool sdvl_can_value_be_encoded(const uint32_t value)
63  __attribute__((warn_unused_result, const));
64 bool sdvl_can_length_be_encoded(const size_t bits_nr)
65  __attribute__((warn_unused_result, const));
66 
67 size_t sdvl_get_min_len(const size_t nr_min_required, const size_t nr_encoded)
68  __attribute__((warn_unused_result, const));
69 
70 size_t sdvl_get_encoded_len(const uint32_t value)
71  __attribute__((warn_unused_result, const));
72 
73 bool sdvl_encode(uint8_t *const packet,
74  const size_t packet_max_len,
75  size_t *const packet_len,
76  const uint32_t value,
77  const size_t bits_nr)
78  __attribute__((warn_unused_result, nonnull(1, 3)));
79 
80 bool sdvl_encode_full(uint8_t *const packet,
81  const size_t packet_max_len,
82  size_t *const packet_len,
83  const uint32_t value)
84  __attribute__((warn_unused_result, nonnull(1, 3)));
85 
86 size_t sdvl_decode(const uint8_t *const data,
87  const size_t length,
88  uint32_t *const value,
89  size_t *const bits_nr)
90  __attribute__((warn_unused_result, nonnull(1, 3, 4)));
91 
92 #endif
93 
Definition: sdvl.h:52
Definition: sdvl.h:50
bool sdvl_encode(uint8_t *const packet, const size_t packet_max_len, size_t *const packet_len, const uint32_t value, const size_t bits_nr)
Encode a value using Self-Describing Variable-Length (SDVL) encoding.
Definition: sdvl.c:180
bool sdvl_encode_full(uint8_t *const packet, const size_t packet_max_len, size_t *const packet_len, const uint32_t value)
Encode a value using Self-Describing Variable-Length (SDVL) encoding.
Definition: sdvl.c:271
rohc_sdvl_max_bits_t
Definition: sdvl.h:45
size_t sdvl_get_min_len(const size_t nr_min_required, const size_t nr_encoded)
Find out how many SDVL bits are needed to represent a value.
Definition: sdvl.c:86
Definition: sdvl.h:48
bool sdvl_can_value_be_encoded(const uint32_t value)
Can the given value be encoded with SDVL?
Definition: sdvl.c:55
Definition: sdvl.h:54
bool sdvl_can_length_be_encoded(const size_t bits_nr)
Is the given length (in bits) compatible with SDVL?
Definition: sdvl.c:69
size_t sdvl_get_encoded_len(const uint32_t value)
Find out how many bytes are needed to represent the value using Self-Describing Variable-Length (SDVL...
Definition: sdvl.c:134
size_t sdvl_decode(const uint8_t *const data, const size_t length, uint32_t *const value, size_t *const bits_nr)
Decode a Self-Describing Variable-Length (SDVL) value.
Definition: sdvl.c:321