PythonStructs

Documentation for PythonStructs.

PythonStructs.ModifierType
Modifier{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 :bigendian
  • size is either :native (default) or :standard
  • alignment 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 as BigEndianModifier

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, or Int64 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.
source
PythonStructs.PythonStructType
PythonStruct{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.

source
Base.stringMethod
string(s::Type{<: PythonStruct})

Convert a PythonStruct to a Python struct format string. The conversion is done with standard types.

source
PythonStructs.calcsizeMethod
calcsize(::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.
source
PythonStructs.modifierFunction
modifier(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 to Modifier(:native, :standard, :none)
  • < corresponds to Modifier(:little_endian, :standard, :none)
  • > corresponds to Modifier(:big_endian, :standard, :none)
  • ! corresponds to Modifier(:big_endian, :standard, :none)
source
PythonStructs.packMethod
pack([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}.

source
PythonStructs.python_struct_to_typeMethod
python_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

source