aiocoap.optiontypes module¶
-
class
aiocoap.optiontypes.
OptionType
(number, value)¶ Bases:
object
Interface for decoding and encoding option values
Instances of
OptionType
are collected in a list in aMessage.opt
Options
object, and provide a translation between the CoAP octet-stream (accessed using theencode()
/decode()
method pair) and the interpreted value (accessed via thevalue
attribute).Note that OptionType objects usually don’t need to be handled by library users; the recommended way to read and set options is via the Options object’sproperties (eg.
message.opt.uri_path = ('.well-known', 'core')
).-
encode
()¶ Return the option’s value in serialzied form
-
decode
(rawdata)¶ Set the option’s value from the bytes in rawdata
-
-
class
aiocoap.optiontypes.
StringOption
(number, value='')¶ Bases:
aiocoap.optiontypes.OptionType
String CoAP option - used to represent string options. Always encoded in UTF8 per CoAP specification.
-
encode
()¶ Return the option’s value in serialzied form
-
decode
(rawdata)¶ Set the option’s value from the bytes in rawdata
-
-
class
aiocoap.optiontypes.
OpaqueOption
(number, value=b'')¶ Bases:
aiocoap.optiontypes.OptionType
Opaque CoAP option - used to represent options that just have their uninterpreted bytes as value.
-
encode
()¶ Return the option’s value in serialzied form
-
decode
(rawdata)¶ Set the option’s value from the bytes in rawdata
-
-
class
aiocoap.optiontypes.
UintOption
(number, value=0)¶ Bases:
aiocoap.optiontypes.OptionType
Uint CoAP option - used to represent integer options.
-
encode
()¶ Return the option’s value in serialzied form
-
decode
(rawdata)¶ Set the option’s value from the bytes in rawdata
-
-
class
aiocoap.optiontypes.
BlockOption
(number, value=None)¶ Bases:
aiocoap.optiontypes.OptionType
Block CoAP option - special option used only for Block1 and Block2 options. Currently it is the only type of CoAP options that has internal structure.
That structure (BlockwiseTuple) covers not only the block options of RFC7959, but also the BERT extension of RFC8323. If the reserved size exponent 7 is used for purposes incompatible with BERT, the implementor might want to look at the context dependent option number interpretations which will hopefully be in place for Signaling (7.xx) messages by then.
-
class
BlockwiseTuple
¶ Bases:
aiocoap.optiontypes._BlockwiseTuple
-
size
¶
-
start
¶ The byte offset in the body indicated by block number and size.
Note that this calculation is only valid for descriptive use and Block2 control use. The semantics of block_number and size in Block1 control use are unrelated (indicating the acknowledged block number in the request Block1 size and the server’s preferred block size), and must not be calculated using this property in that case.
-
is_bert
¶ True if the exponent is recognized to signal a BERT message.
-
is_valid_for_payload_size
(payloadsize)¶
-
reduced_to
(maximum_exponent)¶ Return a BlockwiseTuple whose exponent is capped to the given maximum_exponent
>>> initial = BlockOption.BlockwiseTuple(10, 0, 5) >>> initial == initial.reduced_to(6) True >>> initial.reduced_to(3) BlockwiseTuple(block_number=40, more=0, size_exponent=3)
-
-
value
¶
-
encode
()¶ Return the option’s value in serialzied form
-
decode
(rawdata)¶ Set the option’s value from the bytes in rawdata
-
class