Exemplo n.º 1
0
void testVarint(uint64_t val, std::initializer_list<uint8_t> bytes) {
  size_t n = bytes.size();
  ByteRange expected(&*bytes.begin(), n);

  {
    uint8_t buf[kMaxVarintLength64];
    EXPECT_EQ(expected.size(), encodeVarint(val, buf));
    EXPECT_TRUE(ByteRange(buf, expected.size()) == expected);
  }

  {
    ByteRange r = expected;
    uint64_t decoded = decodeVarint(r);
    EXPECT_TRUE(r.empty());
    EXPECT_EQ(val, decoded);
  }

  if (n < kMaxVarintLength64) {
    // Try from a full buffer too, different code path
    uint8_t buf[kMaxVarintLength64];
    memcpy(buf, &*bytes.begin(), n);

    uint8_t fills[] = {0, 0x7f, 0x80, 0xff};

    for (uint8_t fill : fills) {
      memset(buf + n, fill, kMaxVarintLength64 - n);
      ByteRange r(buf, kMaxVarintLength64);
      uint64_t decoded = decodeVarint(r);
      EXPECT_EQ(val, decoded);
      EXPECT_EQ(kMaxVarintLength64 - n, r.size());
    }
  }
}
Exemplo n.º 2
0
void DeltaVarIntEncoder::AppendInt32(int value){
	if (value > 0){
		cout << "value : " << value  << endl;
		char * c;
		int tmp = value - prev;
		prev = tmp;
		uint64_t v = (uint64_t) tmp;
  		uint8_t *output = (uint8_t*) malloc(sizeof(uint8_t)*8);
   		uint8_t *outputSizePtr  = (uint8_t*) malloc(sizeof(uint8_t)*8);
   		encodeVarint(v,output,outputSizePtr);
   		for(int i = 0; i < *outputSizePtr; i ++)
            cout << "output [" << i << "] =" << bitset<8>(output[i]) << endl;
   		c =  (char *)output;
   		data_.append(c);
	}else{
		//rien wht should i do ? ignore or throw.
	}
}