librlp

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

rlp.c (768B)


      1 #include <stdlib.h>
      2 
      3 #include "rlp.h"
      4 
      5 int rlp_init(rlp_encoder_t *encoder, int buffer_capacity, char *content) {
      6 	encoder->depth = 0;
      7 	if (content != NULL) {
      8 		encoder->buf = content;
      9 		encoder->alloc = 0;
     10 		encoder->state = RLP_DECODE;
     11 		encoder->size = buffer_capacity;
     12 		encoder->ptr = encoder->buf;
     13 		encoder->list_ptr[0] = encoder->buf + buffer_capacity;
     14  	} else {
     15 		encoder->buf = malloc(buffer_capacity);
     16 		encoder->alloc = 1;
     17 		encoder->state = RLP_ENCODE;
     18 		encoder->size = 0;
     19 		encoder->ptr = encoder->buf;
     20 	}
     21 }
     22 
     23 void rlp_free(rlp_encoder_t *encoder) {
     24 	if (encoder->alloc) {
     25 		free(encoder->buf);
     26 	}
     27 	encoder->ptr = NULL;
     28 }
     29 
     30 //int rlp_get(rlp_encoder_t *encoder, int *zl, char **zdest) {
     31 //	*zdest = encoder->buf;
     32 //	*zl = encoder->size;
     33 //	return 0;
     34 //}