add functions to encode and decode variable length integers in binary

master
leitner 13 years ago
parent 662cf55fc9
commit ad6c2d9ce7

@ -4,6 +4,8 @@
/* for size_t: */ /* for size_t: */
#include <stddef.h> #include <stddef.h>
/* for uint32_t */
#include <stdint.h>
/* for time_t: */ /* for time_t: */
#include <sys/types.h> #include <sys/types.h>
@ -88,6 +90,12 @@ size_t fmt_humank(char* dest,unsigned long long l);
/* "Sun, 06 Nov 1994 08:49:37 GMT" */ /* "Sun, 06 Nov 1994 08:49:37 GMT" */
size_t fmt_httpdate(char* dest,time_t t); size_t fmt_httpdate(char* dest,time_t t);
#define FMT_UTF8 5
#define FMT_ASN1LENGTH 17 /* enough space to hold 2^128-1 */
/* some variable length encodings for integers */
size_t fmt_utf8(char* dest,uint32_t n); /* can store 0-0x7fffffff */
size_t fmt_asn1derlength(char* dest,unsigned long long l);
/* internal functions, may be independently useful */ /* internal functions, may be independently useful */
char fmt_tohex(char c); char fmt_tohex(char c);

@ -73,6 +73,10 @@ size_t scan_noncharsetnskip(const char *in,const char *charset,size_t limit) __p
*/ */
size_t scan_httpdate(const char *in,time_t *t) __pure__; size_t scan_httpdate(const char *in,time_t *t) __pure__;
/* some variable length encodings for integers */
size_t scan_utf8(const char* in,size_t len,uint32_t* n) __pure__;
size_t scan_asn1derlength(const char* in,size_t len,unsigned long long* n) __pure__;
/* a few internal function that might be useful independently */ /* a few internal function that might be useful independently */
/* convert from hex ASCII, return 0 to 15 for success or -1 for failure */ /* convert from hex ASCII, return 0 to 15 for success or -1 for failure */
int scan_fromhex(unsigned char c); int scan_fromhex(unsigned char c);

Loading…
Cancel
Save