Path: blob/master/thirdparty/miniupnpc/src/codelength.h
9904 views
/* $Id: codelength.h,v 1.3 2011/07/30 13:10:05 nanard Exp $ */1/* Project : miniupnp2* Author : Thomas BERNARD3* copyright (c) 2005-2015 Thomas Bernard4* This software is subjet to the conditions detailed in the5* provided LICENCE file. */6#ifndef CODELENGTH_H_INCLUDED7#define CODELENGTH_H_INCLUDED89/* Encode length by using 7bit per Byte :10* Most significant bit of each byte specifies that the11* following byte is part of the code */1213/* n : unsigned14* p : unsigned char *15*/16#define DECODELENGTH(n, p) n = 0; \17do { n = (n << 7) | (*p & 0x7f); } \18while((*(p++)&0x80) && (n<(1<<25)));1920/* n : unsigned21* READ : function/macro to read one byte (unsigned char)22*/23#define DECODELENGTH_READ(n, READ) \24n = 0; \25do { \26unsigned char c; \27READ(c); \28n = (n << 7) | (c & 0x07f); \29if(!(c&0x80)) break; \30} while(n<(1<<25));3132/* n : unsigned33* p : unsigned char *34* p_limit : unsigned char *35*/36#define DECODELENGTH_CHECKLIMIT(n, p, p_limit) \37n = 0; \38do { \39if((p) >= (p_limit)) break; \40n = (n << 7) | (*(p) & 0x7f); \41} while((*((p)++)&0x80) && (n<(1<<25)));424344/* n : unsigned45* p : unsigned char *46*/47#define CODELENGTH(n, p) if(n>=268435456) *(p++) = (n >> 28) | 0x80; \48if(n>=2097152) *(p++) = (n >> 21) | 0x80; \49if(n>=16384) *(p++) = (n >> 14) | 0x80; \50if(n>=128) *(p++) = (n >> 7) | 0x80; \51*(p++) = n & 0x7f;5253#endif /* CODELENGTH_H_INCLUDED */545556