Previous topic

spinnman.data package

Next topic

spinnman.data.abstract_byte_writer module

This Page

spinnman.data.abstract_byte_reader module

class spinnman.data.abstract_byte_reader.AbstractByteReader[source]

Bases: object

An abstract reader of bytes. Note that due to endianness concerns, the methods of this reader should be used directly for the appropriate data type being read; e.g. an int should be written using read_int rather than calling read_byte 4 times unless a specific endianness is being achieved.

Abstract Methods

is_at_end() returns true if the reader is currently at the end of the byte
read_byte() Reads the next byte
read_int() Read the next four bytes as in int value
read_long() Reads the next eight bytes as a long value
read_short() Reads the next two bytes as a short value

Methods

read_bytes([size]) Reads an array of bytes

Detailed Methods

is_at_end()[source]

returns true if the reader is currently at the end of the byte reader

Returns:returns true if the reader is currently at the end of the byte

reader false otherwise :rtype: bool

read_byte()[source]

Reads the next byte

Returns:

A byte

Return type:

int

Raises:
  • IOError – If there is an error reading from the stream
  • EOFError – If there are no more bytes to read
read_bytes(size=None)[source]

Reads an array of bytes

Parameters:

size (int) – The number of bytes to read, or None to read all of the remaining bytes

Returns:

An array of bytes

Return type:

bytearray

Raises:
  • IOError – If there is an error reading from the stream
  • EOFError – If there are too few bytes to read the requested size. Note that if there are no more bytes and size is None, an empty array will be returned
read_int()[source]

Read the next four bytes as in int value

Returns:

An int

Return type:

int

Raises:
  • IOError – If there is an error reading from the stream
  • EOFError – If there are too few bytes to read an int
read_long()[source]

Reads the next eight bytes as a long value

Returns:

A long

Return type:

long

Raises:
  • IOError – If there is an error reading from the stream
  • EOFError – If there are too few bytes to read a long
read_short()[source]

Reads the next two bytes as a short value

Returns:

A short

Return type:

int

Raises:
  • IOError – If there is an error reading from the stream
  • EOFError – If there are too few bytes to read a short