Commit b1b0b3d
committed
Add BytesReader to replace BytesIO in decode_message()
Introduce a lightweight BytesReader class that provides the same
read() interface as io.BytesIO but operates directly on the input
bytes/memoryview without internal buffering overhead.
Changes:
- Add BytesReader class with __slots__ for memory efficiency
- Replace io.BytesIO(body) with BytesReader(body) in decode_message()
- BytesReader.read() returns slices directly, converting memoryview
to bytes only when necessary for compatibility
Benefits:
- Eliminates BytesIO's internal buffer allocation and management
- Reduces memory overhead for protocol message decoding
- Works seamlessly with both bytes and memoryview inputs
- Maintains full API compatibility with existing read_* functions
The BytesReader is a minimal implementation focused on the read()
method needed by the protocol decoder. It avoids the overhead of
io.BytesIO's full file-like interface.
Signed-off-by: Yaniv Kaul <ykaul@scylladb.com>1 parent c59934c commit b1b0b3d
1 file changed
Lines changed: 30 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
56 | 84 | | |
57 | 85 | | |
58 | 86 | | |
| |||
1142 | 1170 | | |
1143 | 1171 | | |
1144 | 1172 | | |
1145 | | - | |
| 1173 | + | |
| 1174 | + | |
1146 | 1175 | | |
1147 | 1176 | | |
1148 | 1177 | | |
| |||
0 commit comments