Started implementing varints and zigzag encoding
This commit is contained in:
parent
9039e0e9b4
commit
a0e8c61008
36
bits.h
Normal file
36
bits.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef BITS_H
|
||||
#define BITS_H
|
||||
|
||||
#if defined(TYPES_64) || defined(TYPES_32) || !defined(TYPES_CUSTOM)
|
||||
#define SIZE_LL 64
|
||||
#define SIZE_L 64
|
||||
#define SIZE_I 32
|
||||
#endif
|
||||
|
||||
|
||||
union sig_ll {
|
||||
signed long long value : SIZE_LL;
|
||||
struct {
|
||||
unsigned long long value : SIZE_LL - 1;
|
||||
unsigned char sig : 1;
|
||||
} signature;
|
||||
};
|
||||
|
||||
|
||||
union sig_l {
|
||||
signed long value : SIZE_L;
|
||||
struct {
|
||||
unsigned long value : SIZE_L - 1;
|
||||
unsigned char sig : 1;
|
||||
} signature;
|
||||
};
|
||||
|
||||
union sig_i {
|
||||
signed int value : SIZE_I;
|
||||
struct {
|
||||
unsigned int value : SIZE_I - 1;
|
||||
unsigned char sig : 1;
|
||||
} signature;
|
||||
};
|
||||
|
||||
#endif
|
18
varint.c
Normal file
18
varint.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "varint.h"
|
||||
|
||||
|
||||
varint varint_encode(unsigned long long value){
|
||||
|
||||
}
|
||||
|
||||
unsigned long long varint_decode(varint varint){
|
||||
|
||||
}
|
||||
|
||||
unsigned long long zigzag_encode(signed long long value){
|
||||
return ((unsigned long long)value << 1) ^ (value >> 63);
|
||||
}
|
||||
|
||||
signed long long zigzag_decode(unsigned long long value){
|
||||
|
||||
}
|
13
varint.h
Normal file
13
varint.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef VARINT_H
|
||||
#define VARINT_H
|
||||
|
||||
#include "bits.h"
|
||||
|
||||
typedef char * varint;
|
||||
|
||||
varint varint_encode(unsigned long long);
|
||||
unsigned long long varint_decode(varint);
|
||||
unsigned long long zigzag_encode(long long);
|
||||
long long zigzag_decode(unsigned long long);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user