librlp

C library for the Recursive Length Prefix (RLP) serialization format
git clone git://git.defalsify.org/librlp.git
Log | Files | Refs | LICENSE

commit b300a936f4160a780164f9efd1dc06b2d8136ce6
Author: nolash <dev@holbrook.no>
Date:   Sat, 10 Apr 2021 10:22:04 +0200

Initial commit

Diffstat:
A.gitignore | 1+
ACHANGELOG | 2++
ACONTRIBUTORS | 9+++++++++
AMakefile | 10++++++++++
AVERSION | 1+
Asrc/rlp.c | 13+++++++++++++
Asrc/rlp.h | 21+++++++++++++++++++++
Atests/check_rlp | 0
Atests/check_rlp.c | 42++++++++++++++++++++++++++++++++++++++++++
9 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/CHANGELOG b/CHANGELOG @@ -0,0 +1,2 @@ +- 0.0.1-pending + * encoder for bytes and lists diff --git a/CONTRIBUTORS b/CONTRIBUTORS @@ -0,0 +1,9 @@ +BEGIN:VCARD +VERSION:3.0 +UID:7382e3d8-dc64-4212-9bb2-79c9b8e1d861 +EMAIL;TYPE=home:dev@holbrook.no +FN:Louis Holbrook +N:Holbrook;Louis;;; +REV:20210410075800Z +KEY;TYPE=PGP;ENCODING=BASE64:LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUlOQkZmWDY0TUJFQURWNlBHOVNyM0luRFdxMWJ0WDZJb1FvWG85SkNvN2gzMXd4eGJIRVlpRXlmUG1CcjBpCndRdTl2TGs2Yzl6bW9RY2Y4LzRQQndOWDJjQmdEK3k5SCtNdFFSV0N1MUwyK2U4T0ZmajcweVkwZ3MxeVdNZUoKdHVUNUNqdS9OL2haTkpSL3Q1S3BuZndmbW01cHNTT3ZSc2xpMXl0bFRaTnZNQXlkY2lWVlAyODlQTTVOalFmWQpMeVVoRm43ekxvcHNPRVlwYVBZeit1T2pPanZPVDE1SmpEU0VsYkp0aTZZamh6Y2M5UHN6MnhFMENLMFVJOXFOCkVuRVcxMlhTTzlpQml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TkvUmFuU3AzS1dlMHplekVmUnNtRTFaWk9PbVEwbk5CRgp4NlhVL0JZcG5tZ014UzZuRkFYZmRQbGpoN1lEcHF2Q3NXck1hZkZMdWFjK2NqVC9jd2hUUGN2UC9QSFAxdEJaCnJHNWc4cm5Fd3piVXdvaUFlRjVTdmtSOTVHM1RaUjFmbDFoZHJEVElwdDBlV0o1eUVIcm5aZFc1eDNWQXpzN2EKeTZHT2pQUERPbWF1ak90WHk4Vm9qTUZDMUZxelhCaU0xZFN3Q3E0OXVwa1NRVXRubC82bzJhak1pcUV3ZmhYawowZUcrSUUrSVlrOU5PSnRxazdYcUNQbXU3eWl5WUxIMXhmYnNUSGFTS3FRSQo9VkpLKwotLS0tLUVORCBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCg== +END:VCARD diff --git a/Makefile b/Makefile @@ -0,0 +1,10 @@ +build: + gcc -I./src -g3 -c src/rlp.c -o src/rlp.o + +tests_build: build + gcc -I./src -g3 tests/check_rlp.c src/rlp.o -o tests/check_rlp -lcheck + +check: tests_build + tests/check_rlp + +.PHONY test: check diff --git a/VERSION b/VERSION @@ -0,0 +1 @@ +0.0.1-alpha.1 diff --git a/src/rlp.c b/src/rlp.c @@ -0,0 +1,13 @@ +#include <stdint.h> +#include <stdlib.h> + +#include "rlp.h" + +int rlp_init(rlp_encoder_t *encoder, int buffer_capacity) { + encoder->data_buf = malloc(buffer_capacity); + encoder->depth = 0; +} + +void rlp_free(rlp_encoder_t *encoder) { + free(encoder->data_buf); +} diff --git a/src/rlp.h b/src/rlp.h @@ -0,0 +1,21 @@ +#ifndef RLP_T_ +#define RLP_T_ + +#include <stdint.h> + +#define RLP_MAX_LIST_DEPTH 1024 + +typedef struct rlp_encoder { + uint32_t depth; + uint32_t list_buf[RLP_MAX_LIST_DEPTH]; + char *data_buf; +} rlp_encoder_t; + +int rlp_init(rlp_encoder_t *encoder, int buffer_capacity); +void rlp_free(rlp_encoder_t *encoder); + +int rlp_descend(rlp_encoder_t *encoder, uint32_t num_items); +static int rlp_ascend(rlp_encoder_t *encoder); +int rlp_add(rlp_encoder_t *encoder, int len, char *data); + +#endif diff --git a/tests/check_rlp b/tests/check_rlp Binary files differ. diff --git a/tests/check_rlp.c b/tests/check_rlp.c @@ -0,0 +1,42 @@ +#include <check.h> +#include <stdlib.h> + +#include "rlp.h" + +START_TEST(rlp_init_test) { + rlp_encoder_t encoder; + + rlp_init(&encoder, 1024); + rlp_free(&encoder); + +} +END_TEST + +Suite *rlp_suite(void) { + Suite *s; + TCase *tc; + + s = suite_create("Rlp"); + tc = tcase_create("Init"); + + tcase_add_test(tc, rlp_init_test); + suite_add_tcase(s, tc); + + return s; +} + +int main(void) { + int num_fail; + + Suite *s; + SRunner *sr; + + s = rlp_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_VERBOSE); + num_fail = srunner_ntests_failed(sr); + srunner_free(sr); + + return (num_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +}