PythonStructs
Documentation for PythonStructs.
PythonStructs.PythonStructs
PythonStructs.BigEndianModifier
PythonStructs.LittleEndianModifier
PythonStructs.Modifier
PythonStructs.NativeModifier
PythonStructs.NativeStandardModifier
PythonStructs.NetworkModifier
PythonStructs.NullByte
PythonStructs.PythonStruct
PythonStructs.ZeroCount
Base.string
PythonStructs.calcsize
PythonStructs.modifier
PythonStructs.modifier_char
PythonStructs.pack
PythonStructs.python_struct_lower_to_tuple_type
PythonStructs.python_struct_to_native_type
PythonStructs.python_struct_to_standard_type
PythonStructs.python_struct_to_type
PythonStructs.@pystruct_str
PythonStructs.PythonStructs
— ModulePythonStructs
The PythonStructs package implements the Python structs
standard library in Julia.
PythonStructs.BigEndianModifier
— TypeBigEndianModifier = Modifier{:big_endian, :standard, :none}
byte_order
:big_endiansize
:standardalignment
:none
PythonStructs.LittleEndianModifier
— TypeLittleEndianModifier = Modifier{:little_endian, :standard, :none}
byte_order
:little_endiansize
:standardalignment
:none
PythonStructs.Modifier
— TypeModifier{byte_order, size, alignment}()
Modifier indicates how a Python struct string is interpreted. It is usually determined by the first character of the string.
Arguments
byte_order
is either :native (default), :littleendian, or :bigendiansize
is either :native (default) or :standardalignment
is either :native (default) or :none
Accessing Parameters
Modifier parameters can be accessed via the following access methods applied to either the Modifier
type or an instance.
byte_order_param
size_param
alignment_param
Modifier parameters can also be accessed via the following properties of a Modifier
instance.
.byte_order
.size
.alignment
Constants
NativeModifier
,'@'
, corresponds to Modifier{:native, :native, :native}NativeStandardModifier
,'='
, corresponds to Modifier{:native, :standard, :none}LittleEndianModifier
,<
, corresponds to Modifier{:little_endian, :standard, :none}BigEndianModifier
,<
, corresponds to Modifier{:big_endian, :standard, :none}NetworkModifier
,!
, is the same asBigEndianModifier
Examples
julia> LittleEndianModifier
LittleEndianModifier (alias for PythonStructs.Modifier{:little_endian, :standard, :none})
julia> m = LittleEndianModifier()
LittleEndianModifier()
julia> m.byte_order
:little_endian
julia> m.size
:standard
julia> m.alignment
:none
julia> PythonStructs.byte_order_param(PythonStructs.NativeModifier)
:native
Extended Help
Endianness
Endianness indicates the order of the bytes for multiple byte number types.
- Little endian order has the least significant byte (LSB) come first.
- Big endian order has the most significant byte (MSB) come first.
Size
Size influences how the type characters are mapped to machine types.
- Native size corresponds to C types on the current system. For example, 'l' corresponds to
Clong
, orInt64
on 64-bit systems. - Standard size corresponds to fixed-size machine types that may differ from their native size counterparts. For example, 'l' corresponds to
Int32
.
Alignment
Alignment influences whether padding bytes are employed or not.
- Native alignment corresponds with how C and Julia use padding bytes.
- No alignment (none) does not use padding bytes.
PythonStructs.NativeModifier
— TypeNativeModifier = Modifier{:native, :native, :native}
This constant is the default Modifier
.
byte_order
:nativesize
:nativealignment
:native
PythonStructs.NativeStandardModifier
— TypeNativeStandardModifier = Modifier{:native, :standard, :none}}
byte_order
:nativesize
:standardalignment
:none
PythonStructs.NetworkModifier
— TypeNetworkModifier = BigEndianModifier
Alias for BigEndianModifier
PythonStructs.NullByte
— TypeNullByte
Represents 0x00
corresponding with 'x'
.
PythonStructs.PythonStruct
— TypePythonStruct{T, M <: Modifier}(arg::T)
PythonStruct{T, M <: Modifier}(args...)
PythonStruct(string::AbstractString)
Wrap a type T
with Modifier
parameters or construct a PythonStruct
type from an AbstractString
.
PythonStructs.ZeroCount
— TypeZeroCount{T}
Represents a 0
count of a type, which has some special meanings.
Base.string
— Methodstring(s::Type{<: PythonStruct})
Convert a PythonStruct
to a Python struct format string. The conversion is done with standard types.
PythonStructs.calcsize
— Methodcalcsize(::Type{<: PythonStruct})
Calculate the size of a PythonStruct
type. This differs from sizeof
in the following ways.
- The inclusion of padding bytes depends on the
Modifier
alignment
. - Trailing padding bytes are not included.
PythonStructs.modifier
— Functionmodifier(c::Char)
modifier(str::AbstractString)
Obtain the Modifier
from a character. If an AbstractString
is provided, the first character is sued.
- '@' corresponds to
Modifier(:native, :native, :native)
=
corresponds toModifier(:native, :standard, :none)
<
corresponds toModifier(:little_endian, :standard, :none)
>
corresponds toModifier(:big_endian, :standard, :none)
!
corresponds toModifier(:big_endian, :standard, :none)
PythonStructs.modifier_char
— Methodmodifier_char(s::Type{<: PythonStruct})
Get the modifier character for a particular Modifier
constant.
PythonStructs.pack
— Methodpack([io::IO], s::PS) where PS <: PythonStruct
pack(PythonStruct{T,M}, [io::IO], args...)
pack(s::AbstractString, [io::IO], args...)
Pack a PythonStruct
into bytes. If io
is provided, the bytes are written the IO
object. Otherwise, the bytes are returned as a Vector{UInt8}
.
PythonStructs.python_struct_lower_to_tuple_type
— Methodpython_struct_lower_to_tuple_type(pystruct_string::AbstractString, dict::AbstractDict)
Convert python struct string to a Tuple{...} type by encoding each character or string as a component type.
PythonStructs.python_struct_to_native_type
— Methodpython_struct_to_native_type(pystruct_string::AbstractString)
Use python_struct_to_type
with the native format dictionary.
Private API
PythonStructs.python_struct_to_standard_type
— Methodpython_struct_to_standard_type(pystruct_string::AbstractString)
Use python_struct_to_type
with the standard format dictionary.
Private API
PythonStructs.python_struct_to_type
— Methodpython_struct_to_type(pystruct_string::AbstractString)
python_struct_to_type(pystruct_string::AbstractString, m::Modifier)
python_struct_to_type(pystruct_symbol::Symbol, modifier = default_modifier)
Convert a Python struct string to a PythonStruct
type.
Private API
PythonStructs.@pystruct_str
— Macropystruct""
Create a PythonStruct
type from type characters.