c/flit.h
// Decodes buf into v and returns the serial octet size.
Decodes buf into v and returns the serial octet size.
Decodes buf into v and returns the serial octet size .
size_t flit64_dec(uint64_t* v, const void* buf) {
	uint64_t x = *(uint64_t*)buf;
	int tzc = 8;
	if (x) tzc = __builtin_ctzll(x);
	if (tzc > 7) {
		uint8_t* cp = (uint8_t*)buf;
		*v = *(uint64_t*)++cp;
		return 9;
	}
	static const uint64_t mask[8] = {
		0xff,
		0xffff,
		0xffffff,
		0xffffffff,
		0xffffffffff,
		0xffffffffffff,
		0xffffffffffffff,
		0xffffffffffffffff,
	};
	x &= mask[tzc];
	const size_t size = tzc + 1;
	*v = x >> size;
	return size;
}
size_t flit64_dec ( uint64_t * v , const void * buf ) { uint64_t x = * ( uint64_t * ) buf ; int tzc = 8 ; if ( x ) tzc = __builtin_ctzll ( x ) ; if ( tzc > 7 ) { uint8_t * cp = ( uint8_t * ) buf ; * v = * ( uint64_t * ) ++ cp ; return 9 ; } static const uint64_t mask [ 8 ] = { 0xff , 0xffff , 0xffffff , 0xffffffff , 0xffffffffff , 0xffffffffffff , 0xffffffffffffff , 0xffffffffffffffff , } ; x &= mask [ tzc ] ; const size_t size = tzc + 1 ; * v = x >> size ; return size ; }
Decodes buf into v and returns the serial octet size.
Decodes buf into v and returns the serial octet size .
// const here seems to ensure that 'size' is not aliased by '*v'