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.h (791B)


      1 #ifndef RLP_T_
      2 #define RLP_T_
      3 
      4 #include <stdlib.h>
      5 
      6 #ifndef RLP_MAX_LIST_DEPTH
      7 #define RLP_MAX_LIST_DEPTH 1024
      8 #endif
      9 
     10 #define RLP_SUCCESS 0
     11 #define RLP_FAILURE -1
     12 
     13 
     14 enum rlp_state {
     15 	RLP_DECODE,
     16 	RLP_ENCODE,
     17 	RLP_LIST_ASCEND,
     18 	RLP_LIST_DESCEND,
     19 	RLP_STRING,
     20 	RLP_END,
     21 };
     22 
     23 
     24 typedef struct rlp_encoder {
     25 	char *buf;
     26 	char alloc;
     27 	int depth;
     28 	int size;
     29 	enum rlp_state state;
     30 	char *list_ptr[RLP_MAX_LIST_DEPTH];
     31 	char *ptr;
     32 } rlp_encoder_t;
     33 
     34 
     35 int rlp_init(rlp_encoder_t *encoder, int buffer_capacity, char *content);
     36 void rlp_free(rlp_encoder_t *encoder);
     37 
     38 // encode
     39 int rlp_descend(rlp_encoder_t *encoder);
     40 int rlp_ascend(rlp_encoder_t *encoder);
     41 int rlp_add(rlp_encoder_t *encoder, int len, const char *data);
     42 
     43 // decode
     44 int rlp_next(rlp_encoder_t *encoder, int *zl, char **zdest);
     45 
     46 #endif