Example #1
0
	void bit_pack_object_t::test<2>()
	{
		U8 packbuffer[255];
		U8 unpackbuffer[255];
		int pack_bufsize = 0;
		int unpack_bufsize = 0;

		LLBitPack bitpack(packbuffer, 255);

		char str[] = "SecondLife";
		int len = sizeof(str);
		pack_bufsize = bitpack.bitPack((U8*) str, len*8);
		pack_bufsize = bitpack.flushBitPack();

		LLBitPack bitunpack(packbuffer, pack_bufsize*8);
		unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
		ensure("bitPack: individual unpack: 0", unpackbuffer[0] == (U8) str[0]);
		unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
		ensure("bitPack: individual unpack: 1", unpackbuffer[0] == (U8) str[1]);
		unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
		ensure("bitPack: individual unpack: 2", unpackbuffer[0] == (U8) str[2]);
		unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
		ensure("bitPack: individual unpack: 3", unpackbuffer[0] == (U8) str[3]);
		unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
		ensure("bitPack: individual unpack: 4", unpackbuffer[0] == (U8) str[4]);
		unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
		ensure("bitPack: individual unpack: 5", unpackbuffer[0] == (U8) str[5]);
		unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, 8*4); // Life
		ensure_memory_matches("bitPack: 4 bytes unpack:", unpackbuffer, 4, str+6, 4);
	}
Example #2
0
void TxIOPair::unserialize(const BinaryDataRef& val)
{
   BinaryRefReader brr(val);

   BitUnpacker<uint8_t> bitunpack(brr);
   isTxOutFromSelf_  = bitunpack.getBit();
   isFromCoinbase_   = bitunpack.getBit();
   bool isSpent      = bitunpack.getBit();
   isMultisig_       = bitunpack.getBit();
   isUTXO_           = bitunpack.getBit();
   isFromSameBlock_     = bitunpack.getBit();

   // We always include the 8-byte value
   amount_ = brr.get_uint64_t();

   setTxOut(val.getSliceRef(9, 8));
   if (val.getSize() == 25)
      setTxIn(val.getSliceRef(17, 8));

   //the key always carries the full txout ref
   /*if (!isSpent)
      setTxOut(key);
   else
   {
      //spent subssh, txout key      
      setTxOut(val.getSliceRef(9, 8));

      //when keyed by txins, the top bit in the tx index is always flipped
      BinaryData txinKey(key);
      txinKey.getPtr()[4] &= 0x7F;
      
      //last 8 bytes carry the txin key
      setTxIn(txinKey);
   }*/
}
Example #3
0
	void bit_pack_object_t::test<3>()
	{
		U8 packbuffer[255];
		int pack_bufsize = 0;

		LLBitPack bitpack(packbuffer, 255);
		U32 num = 0x41fab67a;
		pack_bufsize = bitpack.bitPack((U8*)&num, 8*sizeof(U32));
		pack_bufsize = bitpack.flushBitPack();

		LLBitPack bitunpack(packbuffer, pack_bufsize*8);
		U32 res = 0;
		// since packing and unpacking is done on same machine in the unit test run, 
		// endianness should not matter
		bitunpack.bitUnpack((U8*) &res, sizeof(res)*8);
		ensure("U32->bitPack->bitUnpack->U32 should be equal", num == res); 
	}
Example #4
0
	void bit_pack_object_t::test<1>()
	{
		U8 packbuffer[255];
		U8 unpackbuffer[255];
		int pack_bufsize = 0;
		int unpack_bufsize = 0;

		LLBitPack bitpack(packbuffer, 255);

		char str[] = "SecondLife is a 3D virtual world";
		int len = sizeof(str);
		pack_bufsize = bitpack.bitPack((U8*) str, len*8);
		pack_bufsize = bitpack.flushBitPack();

		LLBitPack bitunpack(packbuffer, pack_bufsize*8);
		unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, len*8);
		ensure("bitPack: unpack size should be same as string size prior to pack", len == unpack_bufsize);
		ensure_memory_matches("str->bitPack->bitUnpack should be equal to string", str, len, unpackbuffer, unpack_bufsize); 
	}