librfn
An ad-hoc utility library
pack.h
Go to the documentation of this file.
1 /*
2  * pack.h
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2012-2014 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #ifndef RF_PACK_H_
15 #define RF_PACK_H_
16 
17 #include <stdint.h>
18 
30 typedef struct rf_pack {
31  uint8_t *basep;
32  uint8_t *endp;
33  uint8_t *p;
34 } rf_pack_t;
35 
36 void rf_pack_init(rf_pack_t *pack, void *p, unsigned int sz);
37 int rf_pack_remaining(rf_pack_t *pack);
38 
39 
40 void rf_pack_bytes(rf_pack_t *pack, void *p, unsigned int sz);
41 void rf_pack_char(rf_pack_t *pack, char c);
42 void rf_pack_s8(rf_pack_t *pack, int8_t s8);
43 void rf_pack_u8(rf_pack_t *pack, int16_t u8);
44 void rf_pack_s16be(rf_pack_t *pack, int16_t s16);
45 void rf_pack_s16le(rf_pack_t *pack, int16_t s16);
46 void rf_pack_u16be(rf_pack_t *pack, uint16_t u16);
47 void rf_pack_u16le(rf_pack_t *pack, uint16_t u16);
48 void rf_pack_s32be(rf_pack_t *pack, int32_t s32);
49 void rf_pack_s32le(rf_pack_t *pack, int32_t s32);
50 void rf_pack_u32be(rf_pack_t *pack, uint32_t u32);
51 void rf_pack_u32le(rf_pack_t *pack, uint32_t u32);
52 
53 void rf_unpack_bytes(rf_pack_t *pack, void *p, unsigned int sz);
54 char rf_unpack_char(rf_pack_t *pack);
55 int8_t rf_unpack_s8(rf_pack_t *pack);
56 uint8_t rf_unpack_u8(rf_pack_t *pack);
57 int16_t rf_unpack_s16be(rf_pack_t *pack);
58 int16_t rf_unpack_s16le(rf_pack_t *pack);
59 uint16_t rf_unpack_u16be(rf_pack_t *pack);
60 uint16_t rf_unpack_u16le(rf_pack_t *pack);
61 int32_t rf_unpack_s32be(rf_pack_t *pack);
62 int32_t rf_unpack_s32le(rf_pack_t *pack);
63 uint32_t rf_unpack_u32be(rf_pack_t *pack);
64 uint32_t rf_unpack_u32le(rf_pack_t *pack);
65 
67 #endif // RF_PACK_H_
struct charlie c
void rf_pack_u16le(rf_pack_t *pack, uint16_t u16)
Definition: pack.c:68
uint8_t * endp
Definition: pack.h:32
void rf_pack_s16le(rf_pack_t *pack, int16_t s16)
Definition: pack.c:52
void rf_pack_u32le(rf_pack_t *pack, uint32_t u32)
Definition: pack.c:89
int8_t rf_unpack_s8(rf_pack_t *pack)
Definition: pack.c:128
void rf_pack_u16be(rf_pack_t *pack, uint16_t u16)
Definition: pack.c:60
Definition: pack.h:30
void rf_pack_s16be(rf_pack_t *pack, int16_t s16)
uint8_t * p
Definition: pack.h:33
void rf_pack_bytes(rf_pack_t *pack, void *p, unsigned int sz)
Definition: pack.c:38
int16_t rf_unpack_s16le(rf_pack_t *pack)
int16_t rf_unpack_s16be(rf_pack_t *pack)
struct rf_pack rf_pack_t
void rf_pack_char(rf_pack_t *pack, char c)
void rf_pack_s8(rf_pack_t *pack, int8_t s8)
void rf_pack_s32be(rf_pack_t *pack, int32_t s32)
uint16_t rf_unpack_u16be(rf_pack_t *pack)
int rf_pack_remaining(rf_pack_t *pack)
Definition: pack.c:28
uint8_t * basep
Definition: pack.h:31
char rf_unpack_char(rf_pack_t *pack)
Definition: pack.c:120
void rf_pack_u32be(rf_pack_t *pack, uint32_t u32)
void rf_pack_u8(rf_pack_t *pack, int16_t u8)
uint8_t rf_unpack_u8(rf_pack_t *pack)
Definition: pack.c:136
int32_t rf_unpack_s32le(rf_pack_t *pack)
uint32_t rf_unpack_u32be(rf_pack_t *pack)
uint32_t rf_unpack_u32le(rf_pack_t *pack)
Definition: pack.c:159
uint16_t rf_unpack_u16le(rf_pack_t *pack)
Definition: pack.c:148
void rf_pack_init(rf_pack_t *pack, void *p, unsigned int sz)
Definition: pack.c:21
void rf_unpack_bytes(rf_pack_t *pack, void *p, unsigned int sz)
Definition: pack.c:106
void rf_pack_s32le(rf_pack_t *pack, int32_t s32)
Definition: pack.c:78
int32_t rf_unpack_s32be(rf_pack_t *pack)