class documentation
class CString(Type):
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 |
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 |
Property: The maximum number of characters to attempt to read. |
Property | max |
Property: The maximum number of bytes to attempt to read. |
Static Method | _validate |
Undocumented |
Method | _construct |
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 |
Undocumented |
Inherited from Type
:
Method | description |
The short description of this type. |
Method | is |
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 |
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:object | Undocumented |
Returns | |
bool | Undocumented |
Initialize a new type of CString.
Information
Parameters | |
encoding | The encoding of the string. Must be a member of the Encoding enum. |
max | The 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 | The maximum number of characters to attempt to read. |
Raises | |
ValueError | if an encoding which is not a valid encoding is passed |
ValueError | if none of max_size and max_character_count are specified |
ValueError | if both max_size and max_character_count are specified |
ValueError | if max_size is specified but is not a multiple of the character size |
ValueError | if 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:object | Undocumented |
Returns | |
bool | Undocumented |
@property
max_character_count =
max_character_count =
Property: The maximum number of characters to attempt to read.
Information
Returns | |
An integer. |
@property
max_size =
max_size =
Property: The maximum number of bytes to attempt to read.
Information
Returns | |
An integer. |
def _construct_type(self, context=None):
overrides
reven2.types._type.Type._construct_type
Return the underlying construct instance
def _decode(self, buf, _):
Parses the value of a string from a raw buffer.
Information
Parameters | |
buf:bytes | Undocumented |
_ | Undocumented |
Returns | |
str | A formatted string. |
Raises | |
UnicodeDecodeError | if decoding in the specified encoding fails |