Implement reader & writer for int8_t type
This commit is contained in:
parent
e3d3d988b7
commit
f2e28edc05
@ -260,6 +260,7 @@ class Struct:
|
|||||||
b"short": endian.read_short,
|
b"short": endian.read_short,
|
||||||
b"uint64_t": endian.read_ulong,
|
b"uint64_t": endian.read_ulong,
|
||||||
b"float": endian.read_float,
|
b"float": endian.read_float,
|
||||||
|
b"int8_t": endian.read_int8,
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
simple_reader = simple_readers[dna_type.dna_type_id]
|
simple_reader = simple_readers[dna_type.dna_type_id]
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import typing
|
|||||||
class EndianIO:
|
class EndianIO:
|
||||||
# TODO(Sybren): note as UCHAR: struct.Struct = None and move actual structs to LittleEndianTypes
|
# TODO(Sybren): note as UCHAR: struct.Struct = None and move actual structs to LittleEndianTypes
|
||||||
UCHAR = struct.Struct(b"<B")
|
UCHAR = struct.Struct(b"<B")
|
||||||
|
SINT8 = struct.Struct(b"<b")
|
||||||
USHORT = struct.Struct(b"<H")
|
USHORT = struct.Struct(b"<H")
|
||||||
USHORT2 = struct.Struct(b"<HH") # two shorts in a row
|
USHORT2 = struct.Struct(b"<HH") # two shorts in a row
|
||||||
SSHORT = struct.Struct(b"<h")
|
SSHORT = struct.Struct(b"<h")
|
||||||
@ -62,6 +63,14 @@ class EndianIO:
|
|||||||
def write_char(cls, fileobj: typing.IO[bytes], value: int):
|
def write_char(cls, fileobj: typing.IO[bytes], value: int):
|
||||||
return cls._write(fileobj, cls.UCHAR, value)
|
return cls._write(fileobj, cls.UCHAR, value)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def read_int8(cls, fileobj: typing.IO[bytes]):
|
||||||
|
return cls._read(fileobj, cls.SINT8)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def write_int8(cls, fileobj: typing.IO[bytes], value: int):
|
||||||
|
return cls._write(fileobj, cls.SINT8, value)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def read_ushort(cls, fileobj: typing.IO[bytes]):
|
def read_ushort(cls, fileobj: typing.IO[bytes]):
|
||||||
return cls._read(fileobj, cls.USHORT)
|
return cls._read(fileobj, cls.USHORT)
|
||||||
@ -207,6 +216,7 @@ class EndianIO:
|
|||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
b"char": cls.write_char,
|
b"char": cls.write_char,
|
||||||
|
b"int8": cls.write_int8,
|
||||||
b"ushort": cls.write_ushort,
|
b"ushort": cls.write_ushort,
|
||||||
b"short": cls.write_short,
|
b"short": cls.write_short,
|
||||||
b"uint": cls.write_uint,
|
b"uint": cls.write_uint,
|
||||||
@ -222,6 +232,7 @@ class LittleEndianTypes(EndianIO):
|
|||||||
|
|
||||||
class BigEndianTypes(LittleEndianTypes):
|
class BigEndianTypes(LittleEndianTypes):
|
||||||
UCHAR = struct.Struct(b">B")
|
UCHAR = struct.Struct(b">B")
|
||||||
|
SINT8 = struct.Struct(b">b")
|
||||||
USHORT = struct.Struct(b">H")
|
USHORT = struct.Struct(b">H")
|
||||||
USHORT2 = struct.Struct(b">HH") # two shorts in a row
|
USHORT2 = struct.Struct(b">HH") # two shorts in a row
|
||||||
SSHORT = struct.Struct(b">h")
|
SSHORT = struct.Struct(b">h")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user