File: frame.py

package info (click to toggle)
python-kafka 2.0.2-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 2,740 kB
  • sloc: python: 20,457; makefile: 210; sh: 76
file content (30 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class KafkaBytes(bytearray):
    def __init__(self, size):
        super(KafkaBytes, self).__init__(size)
        self._idx = 0

    def read(self, nbytes=None):
        if nbytes is None:
            nbytes = len(self) - self._idx
        start = self._idx
        self._idx += nbytes
        if self._idx > len(self):
            self._idx = len(self)
        return bytes(self[start:self._idx])

    def write(self, data):
        start = self._idx
        self._idx += len(data)
        self[start:self._idx] = data

    def seek(self, idx):
        self._idx = idx

    def tell(self):
        return self._idx

    def __str__(self):
        return 'KafkaBytes(%d)' % len(self)

    def __repr__(self):
        return str(self)