From 96fe10d7898a254b8519ec1a0dc048e41ee6b859 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Fri, 16 Oct 2026 14:41:09 +0200 Subject: [PATCH] varint header --- src/wire/varint.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/wire/varint.h diff --git a/src/wire/varint.h b/src/wire/varint.h new file mode 100644 index 0000000..a1da93d --- /dev/null +++ b/src/wire/varint.h @@ -0,0 +1,30 @@ +// varint.h +// QUIC variable-length integers, according to RFC 9000 Section 16. +// +// The top two bits of the first byte indicate the length of the integer in bytes: +// 00: 1 byte (6 bits of data) +// 01: 2 bytes (14 bits of data) +// 10: 4 bytes (30 bits of data) +// 11: 8 bytes (62 bits of data) +// The remaining bits of the first byte, along with the subsequent bytes, contain the integer value in big-endian order. +// Values above BRAVAIS_VARINT_MAX are not able to be incoded. + +#ifndef BRAVAIS_VARINT_H +#define BRAVAIS_VARINT_H + +#include +#include + +#include "util/buf.h" + +#define BRAVAIS_VARINT_MAX UINT64_C(0x3FFFFFFFFFFFFFFF) + +// Bytes needed to encode *val*, or 0 if *val* is too large to encode (>BRAVAIS_VARINT_MAX). +size_t bravais_varint_len(uint64_t val); + +uint64_t bravais_rcur_varint(bravais_rcur_buf_t* buf); + +// Always uses the shortest encoding. Fails the cursor if value is too large. +void bravais_wcur_varint(bravais_wcur_t* cur, uint64_t val); + +#endif // BRAVAIS_VARINT_H