aiocoap.optiontypes module¶
- class aiocoap.optiontypes.OptionType(number, value)¶
Bases:
objectInterface for decoding and encoding option values
Instances of
OptionTypeare collected in a list in aMessage.optOptionsobject, and provide a translation between the CoAP octet-stream (accessed using theencode()/decode()method pair) and the interpreted value (accessed via thevalueattribute).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')).- abstractmethod encode()¶
Return the option’s value in serialized form
- abstractmethod decode(rawdata)¶
Set the option’s value from the bytes in rawdata
- class aiocoap.optiontypes.StringOption(number, value='')¶
Bases:
OptionTypeString CoAP option - used to represent string options. Always encoded in UTF8 per CoAP specification.
- encode()¶
Return the option’s value in serialized form
- decode(rawdata)¶
Set the option’s value from the bytes in rawdata
- class aiocoap.optiontypes.OpaqueOption(number, value=b'')¶
Bases:
OptionTypeOpaque CoAP option - used to represent options that just have their uninterpreted bytes as value.
- encode()¶
Return the option’s value in serialized form
- decode(rawdata)¶
Set the option’s value from the bytes in rawdata
- class aiocoap.optiontypes.UintOption(number, value=0)¶
Bases:
OptionTypeUint CoAP option - used to represent integer options.
- encode()¶
Return the option’s value in serialized form
- decode(rawdata)¶
Set the option’s value from the bytes in rawdata
- class aiocoap.optiontypes.TypedOption(number, value=None)¶
Bases:
OptionType- abstract property type: type¶
Checked type of the option
- property value¶
- class aiocoap.optiontypes.BlockOption(number, value=None)¶
Bases:
TypedOptionBlock 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 implementer 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(block_number, more, size_exponent)¶
Bases:
_BlockwiseTuple- property size¶
- property 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.
- property 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)
- type¶
alias of
BlockwiseTuple
- encode()¶
Return the option’s value in serialized form
- decode(rawdata)¶
Set the option’s value from the bytes in rawdata
- class aiocoap.optiontypes.ContentFormatOption(number, value=None)¶
Bases:
TypedOptionType of numeric options whose number has
ContentFormatsemantics- type¶
alias of
ContentFormat
- encode()¶
Return the option’s value in serialized form
- decode(rawdata)¶
Set the option’s value from the bytes in rawdata