API Reference
ProtocolDataUnits.PDU
— TypeParent data type for all PDUs.
ProtocolDataUnits.byteorder
— Functionbyteorder(::Type{T})
Byte order used for PDUs of type T
. Defaults to BIG_ENDIAN
. To change byte order, define a method for this function.
Example:
ProtocolDataUnits.byteorder(::Type{MyPDU}) = LITTLE_ENDIAN
byteorder(::Type{T}, ::Val{s})
Byte order used for PDUs of type T
for field s
. Defaults to the same byte order as the PDU. To change byte order, define a method for this function.
Example:
ProtocolDataUnits.byteorder(::Type{MyPDU}, ::Val{:myfield}) = LITTLE_ENDIAN
Base.length
— Methodlength(::Type{T}, ::Val{s}, info::PDUInfo)
Length of field s
in PDU of type T
. Defaults to nothing
, which indicates that the length is not known, and wire-encoding is used to store length as part of PDU. The length is specified in number of elements for vectors, and number of bytes for strings.
Examples:
# length of field x is 4 bytes less than length of PDU
+API Reference · ProtocolDataUnits.jl API Reference
ProtocolDataUnits.PDU
— TypeParent data type for all PDUs.
sourceProtocolDataUnits.byteorder
— Functionbyteorder(::Type{T})
Byte order used for PDUs of type T
. Defaults to BIG_ENDIAN
. To change byte order, define a method for this function.
Example:
ProtocolDataUnits.byteorder(::Type{MyPDU}) = LITTLE_ENDIAN
sourcebyteorder(::Type{T}, ::Val{s})
Byte order used for PDUs of type T
for field s
. Defaults to the same byte order as the PDU. To change byte order, define a method for this function.
Example:
ProtocolDataUnits.byteorder(::Type{MyPDU}, ::Val{:myfield}) = LITTLE_ENDIAN
sourceBase.length
— Methodlength(::Type{T}, ::Val{s}, info::PDUInfo)
Length of field s
in PDU of type T
. Defaults to nothing
, which indicates that the length is not known, and wire-encoding is used to store length as part of PDU. The length is specified in number of elements for vectors, and number of bytes for strings.
Examples:
# length of field x is 4 bytes less than length of PDU
Base.length(::Type{MyPDU}, ::Val{:x}, info) = info.length - 4
# length of field x is given by the value of field n in the PDU
-Base.length(::Type{MyPDU}, ::Val{:x}, info) = info.get(:n)
sourceProtocolDataUnits.fieldtype
— Functionfieldtype(::Type{T}, ::Val{s}, info::PDUInfo)
Concrete type of field s
in PDU of type T
. Defaults to the type of the field in the PDU. To specialize the type based on auxillary information in the PDU, define a method for this function.
Example:
# field x::Union{Int32,Int64} is Int32 if xtype is 4, Int64 otherwise
-ProtocolDataUnits.fieldtype(::Type{MyPDU}, ::Val{:x}, info) = info.get(:xtype) == 4 ? Int32 : Int64
sourceProtocolDataUnits.PDUInfo
— TypePDU information with fields:
length
: length of PDU in bytes, if known, missing
otherwiseget
: function that returns value of field s
in the PDU
sourceBase.read
— Methodread(io::IO, T::PDU; hooks=true)
-read(io::IO, T::PDU; nbytes, hooks=true)
Decodes a vector of bytes from stream io
to give a PDU. If nbytes
is specified, the PDU is assumed to be of length nbytes
bytes. If hooks
is true
, the post-decode hook is called after decoding the PDU.
sourceBase.write
— Methodwrite(io::IO, pdu::PDU; hooks=true)
Encodes a PDU into a vector of bytes written to stream io
. If hooks
is true
, the pre-encode hook is called before encoding the PDU.
sourceBase.Vector
— MethodVector{UInt8}(pdu::PDU; hooks=true)
Encodes a PDU into a vector of bytes. If hooks
is true
, the pre-encode hook is called before encoding the PDU.
sourceProtocolDataUnits.preencode
— Functionpreencode(pdu::PDU)
Pre-encode hook. This function is called before encoding a PDU into a vector of bytes. It may return a new PDU, which is then encoded instead of the original PDU. The pre-encode hook should not change the type of the PDU.
Example:
using Accessors, CRC32
+Base.length(::Type{MyPDU}, ::Val{:x}, info) = info.get(:n)
sourceProtocolDataUnits.fieldtype
— Functionfieldtype(::Type{T}, ::Val{s}, info::PDUInfo)
Concrete type of field s
in PDU of type T
. Defaults to the type of the field in the PDU. To specialize the type based on auxillary information in the PDU, define a method for this function.
Example:
# field x::Union{Int32,Int64} is Int32 if xtype is 4, Int64 otherwise
+ProtocolDataUnits.fieldtype(::Type{MyPDU}, ::Val{:x}, info) = info.get(:xtype) == 4 ? Int32 : Int64
sourceProtocolDataUnits.PDUInfo
— TypePDU information with fields:
length
: length of PDU in bytes, if known, missing
otherwiseget
: function that returns value of field s
in the PDU
sourceBase.read
— Methodread(io::IO, T::PDU; hooks=true)
+read(io::IO, T::PDU; nbytes, hooks=true)
Decodes a vector of bytes from stream io
to give a PDU. If nbytes
is specified, the PDU is assumed to be of length nbytes
bytes. If hooks
is true
, the post-decode hook is called after decoding the PDU.
sourceBase.write
— Methodwrite(io::IO, pdu::PDU; hooks=true)
Encodes a PDU into a vector of bytes written to stream io
. If hooks
is true
, the pre-encode hook is called before encoding the PDU.
sourceBase.Vector
— MethodVector{UInt8}(pdu::PDU; hooks=true)
Encodes a PDU into a vector of bytes. If hooks
is true
, the pre-encode hook is called before encoding the PDU.
sourceProtocolDataUnits.preencode
— Functionpreencode(pdu::PDU)
Pre-encode hook. This function is called before encoding a PDU into a vector of bytes. It may return a new PDU, which is then encoded instead of the original PDU. The pre-encode hook should not change the type of the PDU.
Example:
using Accessors, CRC32
# assumes MyPDU has field crc::UInt32 as the last field
function ProtocolDataUnits.preencode(pdu::MyPDU)
bytes = Vector{UInt8}(pdu; hooks=false)
crc = crc32(bytes[1:end-4])
@set pdu.crc = crc
-end
sourceProtocolDataUnits.postdecode
— Functionpostdecode(pdu::PDU)
Post-decode hook. This function is called after decoding a PDU from a vector of bytes. It may return a new PDU, which is then returned instead of the original PDU. The post-decode hook should not change the type of the PDU. The post-decode hook may also be used to validate the PDU, and throw an error if the PDU is invalid.
Example:
using CRC32
+end
sourceProtocolDataUnits.postdecode
— Functionpostdecode(pdu::PDU)
Post-decode hook. This function is called after decoding a PDU from a vector of bytes. It may return a new PDU, which is then returned instead of the original PDU. The post-decode hook should not change the type of the PDU. The post-decode hook may also be used to validate the PDU, and throw an error if the PDU is invalid.
Example:
using CRC32
# assumes MyPDU has field crc::UInt32 as the last field
function ProtocolDataUnits.postdecode(pdu::MyPDU)
bytes = Vector{UInt8}(pdu; hooks=false)
pdu.crc == crc32(bytes[1:end-4]) || throw(ErrorException("CRC check failed"))
pdu
-end
sourceSettings
This document was generated with Documenter.jl version 1.1.0 on Saturday 30 September 2023. Using Julia version 1.6.7.
+end