reven2.types._string.CString(Type) class documentationreven2.types._string
(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'\x00' for Ascii and Utf8, but b'\x00\x00' for Utf16, and b'\x00\x00\x00\x00' for Utf32
| Method | __init__ | Initialize a new type of CString. |
| Method | max_size | Property: The maximum number of bytes to attempt to read. |
| Method | max_character_count | Property: The maximum number of characters to attempt to read. |
| 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. |
| Method | parse | Parses the value of a string from a raw buffer. |
| Method | _construct_type | Return the underlying construct instance |
| Static Method | _validate_arguments | Undocumented |
Inherited from Type:
| Method | is_context_sensitive | Whether the context argument needed by some methods actually has an effect. |
Initialize a new type of CString.
| Parameters | encoding | The encoding of the string. Must be a member of the Encoding enum. |
| max_size | 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_character_count | 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 |
Return the underlying construct instance
Property: The maximum number of bytes to attempt to read.
| Returns | An integer. | |
Property: The maximum number of characters to attempt to read.
| Returns | An integer. | |
Parses the value of a string from a raw buffer.
| Parameters | context | The context object. See package documentation. |
| Returns | A formatted string. | |
| Raises | UnicodeDecodeError | if decoding in the specified encoding fails |