pak.types.string¶
Types for strings.
- class PrefixedString(prefix, *, encoding=None, errors=None)¶
Bases:
TypeA string prefixed by the length of its encoded data.
- Parameters:
prefix (typelike) –
The
Typewhich prefixes the string data and represents the length of the string.The prefixed length represents the amount of bytes the string data takes up.
Note
This does not include terminator characters such as a null-terminator.
encoding (
strorNone) –The encoding to encode/decode the data.
If
None, then the value of theencodingattribute is used.errors (
str) –The error handling scheme for encoding/decoding errors.
If
None, then the value of theerrorsattribute is used.
- encoding = 'utf-8'¶
- errors = 'replace'¶
- prefix = None¶
- class TerminatedString(*, encoding=None, terminator=None, errors=None)¶
Bases:
TypeA string that is read until a terminator character is reached.
By default the terminator character is a null-terminator.
A
util.BufferOutOfDataErroris raised when unpacking if no terminator can be found.- Parameters:
encoding (
str) –The encoding to encode/decode the data.
If
None, then the value of theencodingattribute is used.terminator (
str) –A single character indicating when string data has concluded.
If
Nonethe value of theterminatorattribute is used.errors (
str) –The error handling scheme for encoding/decoding errors.
If
None, then the value of theerrorsattribute is used.
- encoding = 'utf-8'¶
- errors = 'replace'¶
- terminator = '\x00'¶
- class StaticTerminatedString(size, *, encoding=None, terminator=None, errors=None, alignment=None)¶
Bases:
TypeA string with a static size, terminated by a certain character.
By default the terminator character is a null-terminator.
A
ValueErroris raised when unpacking if no terminator is found in the data. Additionally autil.BufferOutOfDataErroris raised if the buffer doesn’t contain the static size.Additionally, a
ValueErroris raised when packing if the to-be-packed value is too long for the static size.- Parameters:
size (
int) –The static size of the raw data containing the string.
This size is in bytes.
Warning
The size should contain the terminator.
encoding (
strorNone) –The encoding to use to encode/decode the data.
If
None, then the value of theencodingattribute is used.terminator (
str) –A single character indicating when string data has concluded.
If
Nonethe value of theterminatorattribute is used.errors (
str) –The error handling scheme for encoding/decoding errors.
If
None, then the value of theerrorsattribute is used.alignment (
intorNone) –The alignment of the string data.
If
NoneandencodingisNoneor the original encoding,alignmentwill be assumed to be the same as the original alignment.
- encoding = 'utf-8'¶
- errors = 'replace'¶
- terminator = '\x00'¶