QCoapMessage Class

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

头: #include <QCoapMessage>
qmake: QT += coap
继承者: QCoapRequest

注意: 此类的所有函数 可重入 .

公共类型

enum class Type { Confirmable, NonConfirmable, Acknowledgment, Reset }

公共函数

  QCoapMessage (const QCoapMessage & other )
  QCoapMessage ()
QCoapMessage & operator= (QCoapMessage && other )
QCoapMessage & operator= (const QCoapMessage & other )
  ~QCoapMessage ()
void addOption (const QCoapOption & option )
void addOption (QCoapOption::OptionName name , const QByteArray & value = QByteArray())
void clearOptions ()
bool hasOption (QCoapOption::OptionName name ) const
quint16 messageId () const
QCoapOption option (QCoapOption::OptionName name ) const
QCoapOption optionAt (int index ) const
int optionCount () const
const QList<QCoapOption> & options () const
QList<QCoapOption> options (QCoapOption::OptionName name ) const
QByteArray payload () const
void removeOption (const QCoapOption & option )
void removeOption (QCoapOption::OptionName name )
void setMessageId (quint16 id )
void setOptions (const QList<QCoapOption> & options )
void setPayload (const QByteArray & payload )
void setToken (const QByteArray & token )
void setType (const QCoapMessage::Type & type )
void setVersion (quint8 version )
void swap (QCoapMessage & other )
QByteArray token () const
quint8 tokenLength () const
QCoapMessage::Type type () const
quint8 version () const

详细描述

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

另请参阅 QCoapOption , QCoapReply ,和 QCoapRequest .

成员类型文档编制

enum class QCoapMessage:: Type

Indicates the type of the message.

常量 描述
QCoapMessage::Type::Confirmable 0 A Confirmable message. The destination endpoint needs to acknowledge the message.
QCoapMessage::Type::NonConfirmable 1 A Non-Confirmable message. The destination endpoint does not need to acknowledge the message.
QCoapMessage::Type::Acknowledgment 2 An Acknowledgment message. A message sent or received in reply to a Confirmable message.
QCoapMessage::Type::Reset 3 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).

成员函数文档编制

QCoapMessage:: QCoapMessage (const QCoapMessage & other )

Constructs a shallow copy of other .

QCoapMessage:: QCoapMessage ()

Constructs a new QCoapMessage.

QCoapMessage &QCoapMessage:: operator= ( QCoapMessage && other )

移动赋值运算符。

QCoapMessage &QCoapMessage:: operator= (const QCoapMessage & other )

Copies the contents of other into this message. Returns a reference to this QCoapMessage .

QCoapMessage:: ~QCoapMessage ()

销毁 QCoapMessage .

void QCoapMessage:: addOption (const QCoapOption & option )

Adds the given CoAP option .

void QCoapMessage:: addOption ( QCoapOption::OptionName name , const QByteArray & value = QByteArray())

这是重载函数。

Adds the CoAP option with the given name and value .

void QCoapMessage:: clearOptions ()

Removes all options.

bool QCoapMessage:: hasOption ( QCoapOption::OptionName name ) const

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

quint16 QCoapMessage:: messageId () const

Returns the message id.

另请参阅 setMessageId ().

QCoapOption QCoapMessage:: option ( QCoapOption::OptionName name ) const

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

QCoapOption QCoapMessage:: optionAt ( int index ) const

Returns the option at index position.

int QCoapMessage:: optionCount () const

Returns the number of options.

const QList < QCoapOption > &QCoapMessage:: options () const

Returns the list of options.

另请参阅 setOptions ().

QList < QCoapOption > QCoapMessage:: options ( QCoapOption::OptionName name ) const

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

QByteArray QCoapMessage:: payload () const

Returns the payload.

另请参阅 setPayload ().

void QCoapMessage:: removeOption (const QCoapOption & option )

移除给定 option .

void QCoapMessage:: removeOption ( QCoapOption::OptionName name )

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

void QCoapMessage:: setMessageId ( quint16 id )

Sets the message ID to id .

另请参阅 messageId ().

void QCoapMessage:: setOptions (const QList < QCoapOption > & options )

Sets the message options to options .

另请参阅 options ().

void QCoapMessage:: setPayload (const QByteArray & payload )

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

注意: 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.

另请参阅 payload (), QCborStreamWriter ,和 QCborStreamReader .

void QCoapMessage:: setToken (const QByteArray & token )

Sets the message token to token .

另请参阅 token ().

void QCoapMessage:: setType (const QCoapMessage::Type & type )

Sets the message type to type .

另请参阅 type ().

void QCoapMessage:: setVersion ( quint8 version )

Sets the CoAP version to version .

另请参阅 version ().

void QCoapMessage:: swap ( QCoapMessage & other )

Swaps this message with other 。此操作非常快且从不失败。

QByteArray QCoapMessage:: token () const

Returns the message token.

另请参阅 setToken ().

quint8 QCoapMessage:: tokenLength () const

Returns the token length.

QCoapMessage::Type QCoapMessage:: type () const

Returns the message type.

另请参阅 setType ().

quint8 QCoapMessage:: version () const

Returns the CoAP version.

另请参阅 setVersion ().