summaryrefslogtreecommitdiff
path: root/include/ser.h
blob: c1f207d85f5b62ef22fcfe8371b29845d91859bf (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
// SPDX-FileCopyrightText: 2024 Lizzy Fleckenstein <lizzy@vlhl.dev>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

#ifndef SER_H
#define SER_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "str.h"

// ser

void ser_bytes(strbuf *w, size_t len, uint8_t *x);

void ser_str(strbuf *w, str x);

void ser_u8(strbuf *w, uint8_t x);
void ser_i8(strbuf *w, int8_t x);

void ser_u16(strbuf *w, uint16_t x);
void ser_i16(strbuf *w, int16_t x);

void ser_u32(strbuf *w, uint32_t x);
void ser_i32(strbuf *w, int32_t x);

void ser_u64(strbuf *w, uint64_t x);
void ser_i64(strbuf *w, int64_t x);

// deser

bool deser_bytes(str *r, size_t len, uint8_t *buf);

bool deser_str(str *r, str *buf); // returns slice!

bool deser_u8(str *r, uint8_t *buf);
bool deser_i8(str *r, int8_t *buf);

bool deser_u16(str *r, uint16_t *buf);
bool deser_i16(str *r, int16_t *buf);

bool deser_u32(str *r, uint32_t *buf);
bool deser_i32(str *r, int32_t *buf);

bool deser_u64(str *r, uint64_t *buf);
bool deser_i64(str *r, int64_t *buf);

#endif