mirror of
https://github.com/iKarith/cppo-ng.git
synced 2024-06-01 06:41:27 +00:00
Change ByteBuffer reads on one byte
If you read one index from a bytes or bytearray, you get an int, not a single character bytes object. Originally I didn't want to mimic that feature because it's actually somewhat annoying at times. Realizing it was done that way for a reason, and not doing it in ByteBuffer is gonna be even more annoying.
This commit is contained in:
parent
ed6156c3c6
commit
2c44e50316
|
@ -16,9 +16,9 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
from typing import Optional, Union
|
from typing import Dict, List, Optional, Union
|
||||||
from .buffertype import BufferType
|
from .buffertype import BufferType
|
||||||
from ..util import gen_hexdump
|
from .. import util
|
||||||
|
|
||||||
class ByteBuffer(BufferType):
|
class ByteBuffer(BufferType):
|
||||||
"""ByteBuffer(bytes_or_int[, changed[, locked]]) -> ByteBuffer
|
"""ByteBuffer(bytes_or_int[, changed[, locked]]) -> ByteBuffer
|
||||||
|
@ -45,7 +45,7 @@ class ByteBuffer(BufferType):
|
||||||
def read(
|
def read(
|
||||||
self,
|
self,
|
||||||
start: int = 0,
|
start: int = 0,
|
||||||
count: Optional[int] = None,
|
count: int = 1,
|
||||||
limit: bool = True
|
limit: bool = True
|
||||||
) -> bytearray:
|
) -> bytearray:
|
||||||
"""Return bytearray of count bytes from buffer beginning at start
|
"""Return bytearray of count bytes from buffer beginning at start
|
||||||
|
@ -63,7 +63,8 @@ class ByteBuffer(BufferType):
|
||||||
assert(start + count <= len(self._buf))
|
assert(start + count <= len(self._buf))
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise IndexError('buffer read with index out of range')
|
raise IndexError('buffer read with index out of range')
|
||||||
return bytes(self._buf[start:start + count])
|
ret = self._buf[start:start + count]
|
||||||
|
return bytes(ret) if count != 1 else int(ret[0])
|
||||||
|
|
||||||
def write(
|
def write(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user