class QCoapMessage

The QCoapMessage class holds information about a CoAP message that can be a request or a reply. More

Inherited by: QCoapRequest

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

It holds information such as the message type, message id, token and other ancillary data.

class Type

Indicates the type of the message.

Constant

Description

QCoapMessage.Type.Confirmable

A Confirmable message. The destination endpoint needs to acknowledge the message.

QCoapMessage.Type.NonConfirmable

A Non-Confirmable message. The destination endpoint does not need to acknowledge the message.

QCoapMessage.Type.Acknowledgment

An Acknowledgment message. A message sent or received in reply to a Confirmable message.

QCoapMessage.Type.Reset

A Reset message. This message type is used in case of errors or to stop the ongoing transmission. (For example, it is used to cancel an observation).

__init__()

Constructs a new QCoapMessage .

__init__(other)
Parameters:

otherQCoapMessage

Constructs a shallow copy of other.

addOption(option)
Parameters:

optionQCoapOption

Adds the given CoAP option.

addOption(name[, value=QByteArray()])
Parameters:

This is an overloaded function.

Adds the CoAP option with the given name and value.

clearOptions()

Removes all options.

hasOption(name)
Parameters:

nameOptionName

Return type:

bool

Returns true if the message contains at last one option with name.

messageId()
Return type:

int

Returns the message id.

See also

setMessageId()

option(name)
Parameters:

nameOptionName

Return type:

QCoapOption

Finds and returns the first option with the given name. If there is no such option, returns an invalid QCoapOption with an empty value.

optionAt(index)
Parameters:

index – int

Return type:

QCoapOption

Returns the option at index position.

optionCount()
Return type:

int

Returns the number of options.

options()
Return type:

.list of QCoapOption

Returns the list of options.

See also

setOptions()

options(name)
Parameters:

nameOptionName

Return type:

.list of QCoapOption

Finds and returns the list of options with the given name.

payload()
Return type:

QByteArray

Returns the payload.

See also

setPayload()

removeOption(name)
Parameters:

nameOptionName

Removes all options with the given name. The CoAP protocol allows for the same option to repeat.

removeOption(option)
Parameters:

optionQCoapOption

Removes the given option.

setMessageId(arg__1)
Parameters:

arg__1 – int

Sets the message ID to id.

See also

messageId()

setOptions(options)
Parameters:

options – .list of QCoapOption

Sets the message options to options.

See also

options()

setPayload(payload)
Parameters:

payloadQByteArray

Sets the message payload to payload. The payload can be represented in one of the content formats defined in CoAP Content-Formats Registry .

Note

CoAP supports common content formats such as XML, JSON, and so on, but these are text based and consequently heavy both in payload and in processing. One of the recommended content formats to use with CoAP is CBOR, which is designed to be used in such contexts.

See also

payload() QCborStreamWriterQCborStreamReader

setToken(token)
Parameters:

tokenQByteArray

Sets the message token to token.

See also

token()

setType(type)
Parameters:

typeType

Sets the message type to type.

See also

type()

setVersion(version)
Parameters:

version – int

Sets the CoAP version to version.

See also

version()

swap(other)
Parameters:

otherQCoapMessage

Swaps this message with other. This operation is very fast and never fails.

token()
Return type:

QByteArray

Returns the message token.

See also

setToken()

tokenLength()
Return type:

int

Returns the token length.

type()
Return type:

Type

Returns the message type.

See also

setType()

version()
Return type:

int

Returns the CoAP version.

See also

setVersion()