Download Latest Version BitBuffer_01_1.zip (142.6 kB)
Email in envelope

Get an email when there's a new version of BitBuffer

Home
Name Modified Size InfoDownloads / Week
1.1 2011-06-04
Readme 2011-06-04 1.7 kB
Totals: 2 Items   1.7 kB 0
Package:	Bit Buffer
Author:		Keshav Channa
Version:	1.1
Date:		31-05-2011
License:	zlib/libpng  (free to use in commercial applications also)
Credits:	Would be much appreciated :)


=====================================================
What is it?
=====================================================
A buffer which works at both bit and byte levels.
You can use this class to 'accumulate' data. It is important to read in the same order that you wrote. Otherwise it's useless.
Possible modules where it'll be really useful:
1.	Networking (to construct/decipher messages).
	a.	For heaven's sake don't use 'struct' to send your data over the network.
2.	To stream in/out of files.
3.	Any other module where you need to accumulate data.


=====================================================
Example:
=====================================================

Writing to the buffer
{
	kbc::Utils::BitBuffer	bbuffer ;

	bbuffer.Write(100) ;			// int = 4 bytes
	bbuffer.Write((uint16_t)303) ;	// short = 2 bytes
	bbuffer.Write((uint8_t)23) ;	// byte = 1 byte
	bbuffer.Write0() ;			// 1 bit
	bbuffer.Write(1244565.0f) ;		// float = 4 bytes
}
	
Reading from the buffer
{
	kbc::Utils::BitBuffer	readbuffer ;
	uint32_t			read32 ;
	uint16_t			read16 ;
	uint8_t			read8 ;
	float				readf ;


	// ‘pDataReceivedFromNetwork’ is the data we received from the network.
	readbuffer.AssignMemory(const_cast<void*>(pDataReceivedFromNetwork), data_size, false) ;

	bbuffer.Read(read32) ;			// will read '100'
	bbuffer.Read(read16) ;			// will read '303'
	bbuffer.Read(read8) ;			// will read '23'
	bbuffer.ReadBit() ;				// will read 'false'
	bbuffer.Read(readf) ;			// will read '1244565.0f'
}
Source: Readme, updated 2011-06-04