class documentation

class CString(Type):

View In Hierarchy

A type constructor for NUL-terminated strings ("C-like" strings).

When reading data as instances of this type, reading will continue until it reaches a NUL character or a fixed maximum character count has been read.

NOTE: the NUL character is b'' for Ascii and Utf8, but b'' for Utf16, and b'' for Utf32

Method __eq__ Compares the instance for equality with an object.
Method __hash__ Returns the hash for this value.
Method __init__ Initialize a new type of CString.
Method __ne__ Compares the instance for equality with an object.
Method __repr__ Undocumented
Method size_bytes The minimal number of bytes necessary to hold an instance of this CString type. Since at most max_size bytes are read (even in the absence of a NUL terminator), it is equal to max_size.
Property max_character_count Property: The maximum number of characters to attempt to read.
Property max_size Property: The maximum number of bytes to attempt to read.
Static Method _validate_arguments Undocumented
Method _construct_type Return the underlying construct instance
Method _decode Parses the value of a string from a raw buffer.
Method _encode Undocumented
Instance Variable _construct Undocumented
Instance Variable _encoding Undocumented
Instance Variable _max_size Undocumented

Inherited from Type:

Method description The short description of this type.
Method is_context_sensitive Whether the context argument needed by some methods actually has an effect.
Method parse Parses the value of an instance of this type from a raw buffer, possibly depending on the context.
Method to_bytes Build a byte buffer from a value of this type.
Method _resolve Uses the resolver to return a resolved version of the type, if possible.
def __eq__(self, o):

Compares the instance for equality with an object.

  • if the object is not a CString, it will never be equal to this instance.
Parameters
o:objectUndocumented
Returns
boolUndocumented
def __hash__(self):

Returns the hash for this value.

Returns
intUndocumented
def __init__(self, encoding=Encoding.Utf8, max_size=None, max_character_count=None):

Initialize a new type of CString.

Information

Parameters
encodingThe encoding of the string. Must be a member of the Encoding enum.
max_sizeThe maximum number of bytes to attempt to read. Must be a multiple of the size of one character (1 for Ascii and Utf8, but 2 and 4 for Utf16 and Utf32)
max_character_countThe maximum number of characters to attempt to read.
Raises
ValueErrorif an encoding which is not a valid encoding is passed
ValueErrorif none of max_size and max_character_count are specified
ValueErrorif both max_size and max_character_count are specified
ValueErrorif max_size is specified but is not a multiple of the character size
ValueErrorif max_size or max_character_count are specified, but negative
def __ne__(self, o):

Compares the instance for equality with an object.

  • if the object is not a CString, it will never be equal to this instance.
Parameters
o:objectUndocumented
Returns
boolUndocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
def size_bytes(self, context=None):

The minimal number of bytes necessary to hold an instance of this CString type. Since at most max_size bytes are read (even in the absence of a NUL terminator), it is equal to max_size.

Information

Returns
An integer.
@property
max_character_count =

Property: The maximum number of characters to attempt to read.

Information

Returns
An integer.
@property
max_size =

Property: The maximum number of bytes to attempt to read.

Information

Returns
An integer.
@staticmethod
def _validate_arguments(encoding, max_size, max_character_count):

Undocumented

def _construct_type(self, context=None):

Return the underlying construct instance

def _decode(self, buf, _):

Parses the value of a string from a raw buffer.

Information

Parameters
buf:bytesUndocumented
_Undocumented
Returns
strA formatted string.
Raises
UnicodeDecodeErrorif decoding in the specified encoding fails
def _encode(self, value, _):

Undocumented

Parameters
value:strUndocumented
_Undocumented
Returns
bytesUndocumented
_construct =

Undocumented

_encoding =

Undocumented

_max_size =

Undocumented