gsf package

Submodules

gsf.binarystream module

class gsf.binarystream.BinaryStream(stream: StreamEncoder)[source]

Bases: object

Establishes buffered I/O around a base stream, e.g., a socket.

IO_BUFFERSIZE = 1420
VALUE_BUFFERSIZE = 16
flush()[source]
read(buffer: bytearray, offset: int, count: int) int[source]
read7bit_int32() int32[source]
read7bit_int64() int64[source]
read7bit_uint32() uint32[source]
read7bit_uint64() uint64[source]
read_all(buffer: bytearray, position: int, length: int)[source]

Reads all of the provided bytes. Will not return prematurely, continues to execute Read operation until the entire length has been read.

read_boolean() bool[source]
read_buffer() bytes[source]
read_byte() uint8[source]
read_bytes(count: int) bytes[source]
read_guid() UUID[source]
read_int16(byteorder: str | None = None) int16[source]
read_int32(byteorder: str | None = None) int32[source]
read_int64(byteorder: str | None = None) int64[source]
read_string() str[source]
read_uint16(byteorder: str | None = None) uint16[source]
read_uint32(byteorder: str | None = None) uint32[source]
read_uint64(byteorder: str | None = None) uint64[source]
write(buffer: bytes, offset: int, count: int) int[source]
write7bit_int32(value: int32) int[source]
write7bit_int64(value: int64) int[source]
write7bit_uint32(value: uint32) int[source]
write7bit_uint64(value: uint64) int[source]
write_boolean(value: bool) int[source]
write_buffer(value: bytes) int[source]
write_byte(value: uint8) int[source]
write_guid(value: UUID) int[source]
write_int16(value: int16, byteorder: str | None = None) int[source]
write_int32(value: int32, byteorder: str | None = None) int[source]
write_int64(value: int64, byteorder: str | None = None) int[source]
write_string(value: str) int[source]
write_uint16(value: uint16, byteorder: str | None = None) int[source]
write_uint32(value: uint32, byteorder: str | None = None) int[source]
write_uint64(value: uint64, byteorder: str | None = None) int[source]

gsf.encoding7bit module

class gsf.encoding7bit.Encoding7Bit[source]

Bases: object

Defines 7-bit encoding/decoding functions.

static read_int16(stream_reader: Callable[[], uint8]) int16[source]

Reads 16-bit signed integer value using 7-bit encoding from the provided stream reader.

Parameters:

stream_reader (function to read a byte value from a stream)

Notes

Call expects one to two bytes to be available in base stream.

static read_int32(stream_reader: Callable[[], uint8]) int32[source]

Reads 32-bit signed integer value using 7-bit encoding from the provided stream reader.

Parameters:

stream_reader (function to read a byte value from a stream)

Notes

Call expects one to five bytes to be available in base stream.

static read_int64(stream_reader: Callable[[], uint8]) int64[source]

Reads 64-bit signed integer value using 7-bit encoding from the provided stream reader.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (64-bit value to write)

Notes

Call expects one to nine bytes to be available in base stream.

static read_uint16(stream_reader: Callable[[], uint8]) uint16[source]

Reads 16-bit unsigned integer value using 7-bit encoding from the provided stream reader.

Parameters:

stream_reader (function to read a byte value from a stream)

Notes

Call expects one to two bytes to be available in base stream.

static read_uint32(stream_reader: Callable[[], uint8]) uint32[source]

Reads 32-bit unsigned integer value using 7-bit encoding from the provided stream reader.

Parameters:

stream_reader (function to read a byte value from a stream)

Notes

Call expects one to five bytes to be available in base stream.

static read_uint64(stream_reader: Callable[[], uint8]) uint64[source]

Reads 64-bit unsigned integer value using 7-bit encoding from the provided stream reader.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (64-bit value to write)

Notes

Call expects one to nine bytes to be available in base stream.

static write_int16(stream_writer: Callable[[uint8], int], value: int16) int[source]

Writes 16-bit signed integer value using 7-bit encoding to the provided stream writer.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (16-bit value to write)

static write_int32(stream_writer: Callable[[uint8], int], value: int32) int[source]

Writes 32-bit signed integer value using 7-bit encoding to the provided stream writer.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (32-bit value to write)

static write_int64(stream_writer: Callable[[uint8], int], value: int64) int[source]

Writes 64-bit signed integer value using 7-bit encoding to the provided stream writer.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (64-bit value to write)

static write_uint16(stream_writer: Callable[[uint8], int], value: uint16) int[source]

Writes 16-bit unsigned integer value using 7-bit encoding to the provided stream writer.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (16-bit value to write)

static write_uint32(stream_writer: Callable[[uint8], int], value: uint32) int[source]

Writes 32-bit unsigned integer value using 7-bit encoding to the provided stream writer.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (32-bit value to write)

static write_uint64(stream_writer: Callable[[uint8], int], value: uint64) int[source]

Writes 64-bit unsigned integer value using 7-bit encoding to the provided stream writer.

Parameters:
  • stream_writer (function to write a byte value to a stream)

  • value (64-bit value to write)

gsf.endianorder module

class gsf.endianorder.BigEndian[source]

Bases: NativeEndian

Manages conversion of bytes to basic types in big endian order.

classmethod static_init()[source]
swaporder = True
target_byteorder = 'big'
class gsf.endianorder.LittleEndian[source]

Bases: NativeEndian

Manages conversion of bytes to basic types in little endian order.

classmethod static_init()[source]
swaporder = False
target_byteorder = 'little'
class gsf.endianorder.NativeEndian[source]

Bases: object

Manages conversion of bytes to basic types in native endian order.

classmethod from_float16(value: float16) bytes[source]
classmethod from_float32(value: float32) bytes[source]
classmethod from_float64(value: float64) bytes[source]
classmethod from_int16(value: int16) bytes[source]
classmethod from_int32(value: int32) bytes[source]
classmethod from_int64(value: int64) bytes[source]
classmethod from_uint16(value: uint16) bytes[source]
classmethod from_uint32(value: uint32) bytes[source]
classmethod from_uint64(value: uint64) bytes[source]
classmethod static_init()[source]
swaporder = False
target_byteorder = 'little'
classmethod to_float16(buffer: bytes) float16[source]
classmethod to_float32(buffer: bytes) float32[source]
classmethod to_float64(buffer: bytes) float64[source]
classmethod to_int16(buffer: bytes) int16[source]
classmethod to_int32(buffer: bytes) int32[source]
classmethod to_int64(buffer: bytes) int64[source]
classmethod to_uint16(buffer: bytes) uint16[source]
classmethod to_uint32(buffer: bytes) uint32[source]
classmethod to_uint64(buffer: bytes) uint64[source]

gsf.streamencoder module

class gsf.streamencoder.StreamEncoder(read: Callable[[int], bytes], write: Callable[[bytes], int], default_byteorder: str = 'little')[source]

Bases: object

Defines functions for encoding and decoding native types to and from a stream. For this class, a stream is simply an abstract notion based on provided functions that read and write byte buffers as Python bytes objects advancing a position in the base stream. The read/write functions simply wrap a base object that can handle input and output as bytes, e.g., a bytearray or a socket.

property default_byteorder: str
read(target_buffer: bytearray, offset: int, count: int) int[source]
read7bit_uint32() uint32[source]
read7bit_uint64() uint64[source]
read_bool() bool[source]
read_byte() uint8[source]
read_int16(byteorder: str | None = None) int16[source]
read_int32(byteorder: str | None = None) int32[source]
read_int64(byteorder: str | None = None) int64[source]
read_uint16(byteorder: str | None = None) uint16[source]
read_uint32(byteorder: str | None = None) uint32[source]
read_uint64(byteorder: str | None = None) uint64[source]
write(source_buffer: bytes, offset: int, count: int) int[source]
write7bit_uint32(value: uint32) int[source]
write7bit_uint64(value: uint64) int[source]
write_bool(value: bool) int[source]
write_byte(value: uint8) int[source]
write_int16(value: int16, byteorder: str | None = None) int[source]
write_int32(value: int32, byteorder: str | None = None) int[source]
write_int64(value: int64, byteorder: str | None = None) int[source]
write_uint16(value: uint16, byteorder: str | None = None) int[source]
write_uint32(value: uint32, byteorder: str | None = None) int[source]
write_uint64(value: uint64, byteorder: str | None = None) int[source]

Module contents

class gsf.ByteSize[source]

Bases: object

FLOAT16 = 2
FLOAT32 = 4
FLOAT64 = 8
INT16 = 2
INT32 = 4
INT64 = 8
INT8 = 1
UINT16 = 2
UINT32 = 4
UINT64 = 8
UINT8 = 1
class gsf.Convert[source]

Bases: object

static from_str(value: str, dtype: dtype) object[source]

Converts a string value to the specified type.

class gsf.Empty[source]

Bases: object

DATETIME = datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
DECIMAL = Decimal('0')
DOUBLE = np.float64(0.0)
GUID = UUID('00000000-0000-0000-0000-000000000000')
INT16 = np.int16(0)
INT32 = np.int32(0)
INT64 = np.int64(0)
INT8 = np.int8(0)
SINGLE = np.float32(0.0)
STRING = ''
TICKS = np.uint64(0)
UINT16 = np.uint16(0)
UINT32 = np.uint32(0)
UINT64 = np.uint64(0)
UINT8 = np.uint8(0)
class gsf.Limits[source]

Bases: object

MAXBYTE = 255
MAXINT16 = 32767
MAXINT32 = 2147483647
MAXINT64 = 9223372036854775807
MAXTICKS = 3155378975999999999
MAXUINT16 = 65535
MAXUINT32 = 4294967295
MAXUINT64 = 18446744073709551615
MININT16 = -32768
MININT32 = -2147483648
MININT64 = -9223372036854775808
class gsf.Validate[source]

Bases: object

static parameters(array: Sequence, startIndex: int, length: int)[source]

Validates array or buffer parameters.

gsf.normalize_enumname(value: Enum) str[source]
gsf.override(self)[source]

Marks a method as an override (for documentation purposes).

gsf.static_init(cls)[source]

Marks a class as having a static initialization function and executes the function when class is statically constructed.

gsf.virtual(self)[source]

Marks a method as overridable (for documentation purposes).