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 #include <stdbool.h>
33 
34 
35 /*
36  * Constants related to fields length for SDVL-encoding
37  */
38 
39 /** The maximum numbers of bits that can be SDVL-encoded in 1, 2, 3
40  * and 4 bytes */
41 typedef enum
42 {
43  /** Maximum number of bits in 1 SDVL-encoded byte */
45  /** Maximum number of bits in 2 SDVL-encoded byte */
47  /** Maximum number of bits in 3 SDVL-encoded byte */
49  /** Maximum number of bits in 4 SDVL-encoded byte */
52 
53 
54 /*
55  * Function prototypes.
56  */
57 
58 bool sdvl_can_value_be_encoded(const uint32_t value)
59  __attribute__((warn_unused_result, const));
60 bool sdvl_can_length_be_encoded(const size_t bits_nr)
61  __attribute__((warn_unused_result, const));
62 
63 size_t sdvl_get_min_len(const size_t nr_min_required, const size_t nr_encoded)
64  __attribute__((warn_unused_result, const));
65 
66 size_t sdvl_get_encoded_len(const uint32_t value)
67  __attribute__((warn_unused_result, const));
68 
69 bool sdvl_encode(uint8_t *const packet,
70  const size_t packet_max_len,
71  size_t *const packet_len,
72  const uint32_t value,
73  const size_t bits_nr)
74  __attribute__((warn_unused_result, nonnull(1, 3)));
75 
76 bool sdvl_encode_full(uint8_t *const packet,
77  const size_t packet_max_len,
78  size_t *const packet_len,
79  const uint32_t value)
80  __attribute__((warn_unused_result, nonnull(1, 3)));
81 
82 size_t sdvl_decode(const uint8_t *const data,
83  const size_t length,
84  uint32_t *const value,
85  size_t *const bits_nr)
86  __attribute__((warn_unused_result, nonnull(1, 3, 4)));
87 
88 #endif
89 
Definition: sdvl.h:48
Definition: sdvl.h:46
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:41
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:44
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:50
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