aboutsummaryrefslogtreecommitdiffstats
path: root/pack.h
blob: daf069996fb36b4db3c4e3ef3cdc52c84d98c056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright (C) 2020  Tomasz Kramkowski <tk@the-tk.com>
 * SPDX-License-Identifier: MIT
 */
#ifndef PACK_H
#define PACK_H

#include <stddef.h>

enum pack_status {
	PACK_OK,
	PACK_FMTINVAL,
	PACK_TOOSMALL,
};

extern enum pack_trace {
	PACK_TRACE_OFF,
	PACK_TRACE_CALL,
	PACK_TRACE_DEBUG,
	PACK_TRACE_ALL,
} pack_trace;

enum pack_type {
	PACK_TYPE_SCHAR   = 'b',
	PACK_TYPE_UCHAR   = 'B',
	PACK_TYPE_SHORT   = 'h',
	PACK_TYPE_USHORT  = 'H',
	PACK_TYPE_INT     = 'i',
	PACK_TYPE_UINT    = 'I',
	PACK_TYPE_LONG    = 'l',
	PACK_TYPE_ULONG   = 'L',
	PACK_TYPE_LLONG   = 'q',
	PACK_TYPE_ULLONG  = 'Q',
	PACK_TYPE_FLOAT   = 'f',
	PACK_TYPE_DOUBLE  = 'd',
	PACK_TYPE_PADDING = 'x',
};

enum pack_endian {
	PACK_ENDIAN_BIG,
	PACK_ENDIAN_LITTLE
};

enum pack_status pack(void *dest, size_t size, const char *fmt, ...);
enum pack_status unpack(const void *buf, size_t size, const char *fmt, ...);

const char *pack_strerror(enum pack_status status);

#endif // !PACK_H