github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-varint.h (about) 1 /* 2 * jit-varint.h - Variable length integer encoding. 3 * 4 * Copyright (C) 2011 Aleksey Demakov 5 * 6 * The libjit library is free software: you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation, either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * The libjit library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with the libjit library. If not, see 18 * <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef _JIT_VARINT_H 22 #define _JIT_VARINT_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define JIT_VARINT_BUFFER_SIZE 500 29 30 typedef struct jit_varint_data *jit_varint_data_t; 31 struct jit_varint_data 32 { 33 jit_varint_data_t next; 34 unsigned char data[]; 35 }; 36 37 typedef struct jit_varint_encoder jit_varint_encoder_t; 38 struct jit_varint_encoder 39 { 40 unsigned char buf[JIT_VARINT_BUFFER_SIZE]; 41 int len; 42 jit_varint_data_t data; 43 jit_varint_data_t last; 44 45 }; 46 47 typedef struct jit_varint_decoder jit_varint_decoder_t; 48 struct jit_varint_decoder 49 { 50 jit_varint_data_t data; 51 int len; 52 int end; 53 }; 54 55 void _jit_varint_init_encoder(jit_varint_encoder_t *encoder); 56 void _jit_varint_init_decoder(jit_varint_decoder_t *decoder, jit_varint_data_t data); 57 int _jit_varint_encode_end(jit_varint_encoder_t *encoder); 58 int _jit_varint_encode_uint(jit_varint_encoder_t *encoder, jit_uint value); 59 jit_varint_data_t _jit_varint_get_data(jit_varint_encoder_t *encoder); 60 void _jit_varint_free_data(jit_varint_data_t data); 61 int _jit_varint_decode_end(jit_varint_decoder_t *decoder); 62 jit_uint _jit_varint_decode_uint(jit_varint_decoder_t *decoder); 63 64 65 #ifdef __cplusplus 66 } 67 #endif 68 69 #endif /* _JIT_VARINT_H */ 70