Пример #1
0
 def uncompact_uint32(self):
     if self.pos == self.size(): raise MarshalException()
     x = ord(self.getbyte(self.pos)) & 0xe0
     if x == 0xe0:
         self.unmarshal_uint8()
         return self.unmarshal_uint32()
     if x == 0xc0:
         return self.unmarshal_uint32() & ~0xc0000000L
     if x == 0xa0 or x == 0x80:
         return self.unmarshal_uint16() & ~0x8000
     return self.unmarshal_uint8()
Пример #2
0
 def uncompact_sint32(self):
     if self.pos == self.size(): raise MarshalException()
     x = ord(self.getbyte(self.pos)) & 0xf0
     if x == 0xf0:
         self.unmarshal_uint8()
         return -(self.unmarshal_uint32())
     if x == 0xe0:
         self.unmarshal_uint8()
         return self.unmarshal_uint32()
     if x == 0xd0:
         return -(self.unmarshal_uint32() & ~0xd0000000L)
     if x == 0xc0:
         return self.unmarshal_uint32() & ~0xc0000000L
     if x == 0xb0 or x == 0xa0:
         return -(self.unmarshal_uint16() & ~0xa000)
     if x == 0x90 or x == 0x80:
         return self.unmarshal_uint16() & ~0x8000
     if x == 0x70 or x == 0x60 or x == 0x50 or x == 0x40:
         return -(self.unmarshal_uint8() & ~0x40)
     return self.unmarshal_uint8()
Пример #3
0
 def unmarshal_uint8(self):
     if self.pos + 1 > self.size(): raise MarshalException()
     self.pos += 1
     return unpack('!B', self.getstr(self.pos - 1, self.pos))[0]
Пример #4
0
 def unmarshal_os(self):
     size = self.uncompact_uint32()
     if self.pos + size > self.size(): raise MarshalException()
     os = Octets().replace2(self, self.pos, size)
     self.pos = self.pos + size
     return os
Пример #5
0
 def unmarshalos(self, o):
     size = self.uncompact_uint32()
     if self.pos + size > self.size(): raise MarshalException()
     o.replace2(self, self.pos, size)
     self.pos = self.pos + size
     return self
Пример #6
0
 def unmarshal_double(self):
     if self.pos + 8 > self.size(): raise MarshalException()
     self.pos += 8
     return unpack('!d', self.getstr(self.pos - 8, self.pos))[0]
Пример #7
0
 def unmarshal_float(self):
     if self.pos + 4 > self.size(): raise MarshalException()
     self.pos += 4
     return unpack('!f', self.getstr(self.pos - 4, self.pos))[0]
Пример #8
0
 def unmarshal_uint16(self):
     if self.pos + 2 > self.size(): raise MarshalException()
     self.pos += 2
     return unpack('!H', self.getstr(self.pos - 2, self.pos))[0]