Esempio n. 1
0
const_byteptr decode_leb128(Uint& result, const_byteptr p, const_byteptr end) {
  // TODO: test
  Uint x = 0;
  for (;;) {
    byte const c = *p;
    byte const sig = c & 0x7f;
    x <<= 7;
    x |= sig;
    ++p;
    if (c == sig) {
      result = x;
      return p;
    }
    if (p == end) throw leb128error();
  }
}
Esempio n. 2
0
byteptr encode_leb128(byteptr p, byteptr e, Uint x) {
  if (leb128_max_bytes(x) + p > e) throw leb128error();
  return encode_leb128(p, x);
}
Esempio n. 3
0
 virtual byteptr encode(byteptr p, const_byteptr end, Value const& x) const {
   if (max_bytes + p > end) throw leb128error();  /// override this if you want to be more precise
   return encode(p, x);
 }
Esempio n. 4
0
 byteptr encode(byteptr p, const_byteptr end, Uint x) const {
   if (p + fixed_bytes > end) throw leb128error();
   return encode(p, x);
 }
Esempio n. 5
0
 const_byteptr decode(Uint& x, const_byteptr p, const_byteptr end) const {
   if (p + fixed_bytes > end) throw leb128error();
   return decode(x, p);
 }
Esempio n. 6
0
 static byteptr encode(byteptr p, const_byteptr end, Uint x) {
     if (p + sizeof(Uint) > end)
         throw leb128error();
     *(Uint*)p = x;
     return p + sizeof(Uint);
 }
Esempio n. 7
0
 static const_byteptr decode(Uint &x, const_byteptr p, const_byteptr end) {
     if (p + sizeof(Uint) > end)
         throw leb128error();
     x = *(Uint*)p;
     return p + sizeof(Uint);
 }