class Type(object):
Known subclasses: reven2.types._array.Array
, reven2.types._declaration.UnresolvedDeclaration
, reven2.types._enum.Enumeration
, reven2.types._error.ErrorType
, reven2.types._integer.Integer
, reven2.types._pointer.Pointer
, reven2.types._primitive.Primitive
, reven2.types._primitive.PrimitiveBool
, reven2.types._string.CString
, reven2.types._struct.Struct
, reven2.types._void.VoidType
An abstract class whose instances represent a type. Refer to the module documentation for details.
Implementers must provide the _construct_type method.
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 | size |
The minimal number of bytes necessary to hold an instance of this type, possibly depending on the context. |
Method | to |
Build a byte buffer from a value of this type. |
Method | _construct |
Return the underlying construct instance |
Method | _resolve |
Uses the resolver to return a resolved version of the type, if possible. |
reven2.types._declaration.UnresolvedDeclaration
, reven2.types._enum.Enumeration
, reven2.types._error.ErrorType
, reven2.types._struct.Struct
The short description of this type.
For named types, it is the name of the type. For other types, it is generally __str__.
Returns | |
str | Undocumented |
reven2.types._array.Array
, reven2.types._enum.Enumeration
, reven2.types._integer.ArchDependentInteger
, reven2.types._integer.BigEndian
, reven2.types._integer.LittleEndian
, reven2.types._pointer.Pointer
, reven2.types._struct.Struct
Whether the context argument needed by some methods actually has an effect.
Types that return False to this method are context-insensitive types. You can safely pass any object as context parameter (including None) to the methods of such type.
Note that the context-sensitivity of a type may change in the future.
Examples
Getting the size of a type without needing a context for context-insensitive types: >>> types.U32.is_context_sensitive() False >>> types.U32.size_bytes(context=None) 4 >>> array32_12 = types.Array(types.U32, 12) >>> array32_12.is_context_sensitive() False >>> array32_12.size_bytes() # context=None by default 48
Context-sensitive types may raise errors when attempting to get the size without a context: >>> types.USize.is_context_sensitive() True >>> types.USize.size_bytes(context=None) ValueError: Please provide a context when using a context-sensitive type
Returns | |
bool | Undocumented |
reven2.types._declaration.UnresolvedDeclaration
Parses the value of an instance of this type from a raw buffer, possibly depending on the context.
Information
Parameters | |
buf:bytes | Undocumented |
context:_Optional[ | The context object. See package documentation. |
Returns | |
_Any | Undocumented |
reven2.types._declaration.UnresolvedDeclaration
, reven2.types._integer.Integer
, reven2.types._pointer.Pointer
, reven2.types._string.CString
The minimal number of bytes necessary to hold an instance of this type, possibly depending on the context.
Parameters | |
context:_Optional[ | Undocumented |
Returns | |
int | Undocumented |
reven2.types._declaration.UnresolvedDeclaration
Build a byte buffer from a value of this type.
Examples
Converting some values to their byte representation.
>>> F32.to_bytes(0.222) b'øSc>' >>> Array(U16, 2).to_bytes([0xfe, 0xfeff]) b'þÿþ' >>> BigEndian(U16).to_bytes(0xfffe) b'ÿþ' >>> U16.to_bytes(0xfffe) b'þÿ'
Information
Parameters | |
value:_Any | Undocumented |
context:_Optional[ | The context object. See package documentation. |
Returns | |
bytes | Undocumented |
reven2.types._array.Array
, reven2.types._declaration.UnresolvedDeclaration
, reven2.types._enum.Enumeration
, reven2.types._error.ErrorType
, reven2.types._integer.Integer
, reven2.types._pointer.Pointer
, reven2.types._primitive.Primitive
, reven2.types._primitive.PrimitiveBool
, reven2.types._string.CString
, reven2.types._struct.Struct
, reven2.types._void.VoidType
Return the underlying construct instance
Parameters | |
context:_Optional[ | Undocumented |
Returns | |
_construct.core.Construct | Undocumented |
reven2.types._array.Array
, reven2.types._declaration.UnresolvedDeclaration
, reven2.types._pointer.Pointer
Uses the resolver to return a resolved version of the type, if possible.
Parameters | |
resolver:BaseTypeResolver | Undocumented |
Returns | |
Type | Undocumented |