netbits.buffer.Buffer

class netbits.buffer.Buffer(buffer: bytearray)[source]

Bases: object

A class to handle reading and writing of binary data with support for integers and strings.

Parameters:

buffer (bytearray) – A bytearray to store the binary data.

__init__(buffer: bytearray)[source]

Initialize the Buffer instance.

Parameters:

buffer (bytearray) – A bytearray to store the binary data.

Methods

__init__(buffer)

Initialize the Buffer instance.

read_int()

Read an integer from the buffer.

read_string()

Read a string from the buffer.

write_int(value)

Write an integer to the buffer.

write_string(value)

Write a string to the buffer.

read_int() int[source]

Read an integer from the buffer.

Returns:

The integer value read from the buffer.

Return type:

int

read_string() str[source]

Read a string from the buffer.

Returns:

The string value read from the buffer.

Return type:

str

write_int(value: int)[source]

Write an integer to the buffer.

Parameters:

value (int) – The integer value to write.

write_string(value: str)[source]

Write a string to the buffer.

Parameters:

value (str) – The string value to write.