Package mobi :: Package mtld :: Package da :: Package carrier :: Module byte_reader
[hide private]
[frames] | no frames]

Source Code for Module mobi.mtld.da.carrier.byte_reader

 1  from struct import unpack_from 
 2   
3 -class ByteReader:
4 _buff = "" 5 _position = 0 6
7 - def __init__(self, data):
8 self._buff = data
9
10 - def skip(self, offset):
11 self._position += offset
12
13 - def getShort(self):
14 data = unpack_from("<h", self._buff, self._position)[0] 15 self._position += 2 16 return data
17
18 - def getInt(self):
19 data = unpack_from("<i", self._buff, self._position)[0] 20 self._position += 4 21 return data
22
23 - def getIntUnsigned(self):
24 data = unpack_from("<I", self._buff, self._position)[0] 25 self._position += 4 26 return data
27
28 - def getLong(self):
29 data = unpack_from("<l", self._buff, self._position)[0] 30 self._position += 8 31 return data
32
33 - def getFloat(self):
34 data = unpack_from("<f", self._buff, self._position)[0] 35 self._position += 4 36 return data
37
38 - def getDouble(self):
39 data = unpack_from("<d", self._buff, self._position)[0] 40 self._position += 8 41 return data
42
43 - def getByte(self):
44 data = unpack_from("<B", self._buff, self._position)[0] 45 self._position += 1 46 return data
47
48 - def getBytes(self, length):
49 data = unpack_from(("<%dB" % length), self._buff, self._position) 50 self._position += length 51 return data
52
53 - def getStringAscii(self, length):
54 data = unpack_from(("<%ds" % length), self._buff, self._position)[0] 55 self._position += length 56 return data
57
58 - def getStringUtf8(self, length):
59 data = unpack_from(("<%ds" % length), self._buff, self._position)[0] 60 self._position += length 61 return data
62