pub struct Message<PayloadBytes, Options> {
pub id: Id,
pub ty: Type,
pub ver: Version,
pub token: Token,
pub code: Code,
pub opts: Options,
pub payload: Payload<PayloadBytes>,
}Expand description
Message struct
Low-level representation of a message that has been parsed from the raw binary format.
Note that Message is generic over 3 Arrays:
PayloadC: the byte buffer used to store the message’sPayloadOptC: byte buffer used to storeOption values (OptValue)Opts: collection ofOptions in the message
Messages support both serializing to bytes and from bytes, by using the provided TryFromBytes and TryIntoBytes traits.
RFC7252 - CoAP Messaging Model
## Messaging Model [_generated from RFC7252 section 2.1_](https://datatracker.ietf.org/doc/html/rfc7252#section-2.1)The CoAP messaging model is based on the exchange of messages over UDP between endpoints.
CoAP uses a short fixed-length binary header (4 bytes) that may be followed by compact binary options and a payload. This message format is shared by requests and responses. The CoAP message format is specified in Section 3. Each message contains a Message ID used to detect duplicates and for optional reliability. (The Message ID is compact; its 16-bit size enables up to about 250 messages per second from one endpoint to another with default protocol parameters.)
Reliability is provided by marking a message as Confirmable (CON). A Confirmable message is retransmitted using a default timeout and exponential back-off between retransmissions, until the recipient sends an Acknowledgement message (ACK) with the same Message ID (in this example, 0x7d34) from the corresponding endpoint; see Figure 2. When a recipient is not at all able to process a Confirmable message (i.e., not even able to provide a suitable error response), it replies with a Reset message (RST) instead of an Acknowledgement (ACK).
Client Server
| |
| CON [0x7d34] |
+----------------->|
| |
| ACK [0x7d34] |
|<-----------------+
| |
Figure 2: Reliable Message Transmission
A message that does not require reliable transmission (for example, each single measurement out of a stream of sensor data) can be sent as a Non-confirmable message (NON). These are not acknowledged, but still have a Message ID for duplicate detection (in this example, 0x01a0); see Figure 3. When a recipient is not able to process a Non-confirmable message, it may reply with a Reset message (RST).
Client Server
| |
| NON [0x01a0] |
+----------------->|
| |
Figure 3: Unreliable Message Transmission
See Section 4 for details of CoAP messages.
As CoAP runs over UDP, it also supports the use of multicast IP destination addresses, enabling multicast CoAP requests. Section 8 discusses the proper use of CoAP messages with multicast addresses and precautions for avoiding response congestion.
Several security modes are defined for CoAP in Section 9 ranging from no security to certificate-based security. This document specifies a binding to DTLS for securing the protocol; the use of IPsec with CoAP is discussed in [IPsec-CoAP].
RFC7252 - CoAP Message Binary Format
## Message Format [_generated from RFC7252 section 3_](https://datatracker.ietf.org/doc/html/rfc7252#section-3)CoAP is based on the exchange of compact messages that, by default, are transported over UDP (i.e., each CoAP message occupies the data section of one UDP datagram). CoAP may also be used over Datagram Transport Layer Security (DTLS) (see Section 9.1). It could also be used over other transports such as SMS, TCP, or SCTP, the specification of which is out of this document’s scope. (UDP-lite [RFC3828] and UDP zero checksum [RFC6936] are not supported by CoAP.)
CoAP messages are encoded in a simple binary format. The message format starts with a fixed-size 4-byte header. This is followed by a variable-length Token value, which can be between 0 and 8 bytes long.
Following the Token value comes a sequence of zero or more CoAP Options in Type-Length-Value (TLV) format, optionally followed by a payload that takes up the rest of the datagram.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Ver| T | TKL | Code | Message ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Token (if any, TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1| Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 7: Message Format
The fields in the header are defined as follows:
Version (Ver): 2-bit unsigned integer. Indicates the CoAP version number. Implementations of this specification MUST set this field to 1 (01 binary). Other values are reserved for future versions. Messages with unknown version numbers MUST be silently ignored.
Type (T): 2-bit unsigned integer. Indicates if this message is of type Confirmable (0), Non-confirmable (1), Acknowledgement (2), or Reset (3). The semantics of these message types are defined in Section 4.
Token Length (TKL): 4-bit unsigned integer. Indicates the length of the variable-length Token field (0-8 bytes). Lengths 9-15 are reserved, MUST NOT be sent, and MUST be processed as a message format error.
Code: 8-bit unsigned integer, split into a 3-bit class (most significant bits) and a 5-bit detail (least significant bits), documented as “c.dd” where “c” is a digit from 0 to 7 for the 3-bit subfield and “dd” are two digits from 00 to 31 for the 5-bit subfield. The class can indicate a request (0), a success response (2), a client error response (4), or a server error response (5). (All other class values are reserved.) As a special case, Code 0.00 indicates an Empty message. In case of a request, the Code field indicates the Request Method; in case of a response, a Response Code. Possible values are maintained in the CoAP Code Registries (Section 12.1). The semantics of requests and responses are defined in Section 5.
Message ID: 16-bit unsigned integer in network byte order. Used to detect message duplication and to match messages of type Acknowledgement/Reset to messages of type Confirmable/Non- confirmable. The rules for generating a Message ID and matching messages are defined in Section 4.
The header is followed by the Token value, which may be 0 to 8 bytes, as given by the Token Length field. The Token value is used to correlate requests and responses. The rules for generating a Token and correlating requests and responses are defined in Section 5.3.1.
Header and Token are followed by zero or more Options (Section 3.1). An Option can be followed by the end of the message, by another Option, or by the Payload Marker and the payload.
Following the header, token, and options, if any, comes the optional payload. If present and of non-zero length, it is prefixed by a fixed, one-byte Payload Marker (0xFF), which indicates the end of options and the start of the payload. The payload data extends from after the marker to the end of the UDP datagram, i.e., the Payload Length is calculated from the datagram size. The absence of the Payload Marker denotes a zero-length payload. The presence of a marker followed by a zero-length payload MUST be processed as a message format error.
Implementation Note: The byte value 0xFF may also occur within an option length or value, so simple byte-wise scanning for 0xFF is not a viable technique for finding the payload marker. The byte 0xFF has the meaning of a payload marker only where the beginning of another option could occur.
use std::collections::BTreeMap;
use toad_msg::TryFromBytes;
use toad_msg::*;
let packet: Vec<u8> = /* bytes! */
// `toad_msg::alloc::Message` uses `Vec` as the backing structure for byte buffers
let msg = toad_msg::alloc::Message::try_from_bytes(packet.clone()).unwrap();
let mut opts_expected = BTreeMap::from([(OptNumber(12), vec![OptValue(content_format.iter().map(|u| *u).collect())])]);
let expected = toad_msg::alloc::Message {
id: Id(1),
ty: Type::Con,
ver: Version(1),
token: Token(tinyvec::array_vec!([u8; 8] => 254)),
opts: opts_expected,
code: Code {class: 2, detail: 5},
payload: Payload(b"hello, world!".to_vec()),
};
assert_eq!(msg, expected);Fields§
§id: Idsee Id for details
ty: Typesee Type for details
ver: Versionsee Version for details
token: Tokensee Token for details
code: Codesee Code for details
opts: Optionssee opt::Opt for details
payload: Payload<PayloadBytes>see Payload
Implementations§
source§impl<PayloadBytes: Array<Item = u8> + AppendCopy<u8>, Options: OptionMap> Message<PayloadBytes, Options>
impl<PayloadBytes: Array<Item = u8> + AppendCopy<u8>, Options: OptionMap> Message<PayloadBytes, Options>
sourcepub fn ack(&self, id: Id) -> Self
pub fn ack(&self, id: Id) -> Self
Create a new message that ACKs this one.
This needs an Id to assign to the newly created message.
// we are a server
use std::net::SocketAddr;
use toad_msg::alloc::Message;
use toad_msg::Id;
fn server_get_request() -> Option<(SocketAddr, Message)> {
// Servery sockety things...
}
fn server_send_msg(addr: SocketAddr, msg: Message) -> Result<(), ()> {
// Message sendy bits...
}
let (addr, req) = server_get_request().unwrap();
let ack_id = Id(req.id.0 + 1);
let ack = req.ack(ack_id);
server_send_msg(addr, ack).unwrap();sourcepub fn add(
&mut self,
n: OptNumber,
v: OptValue<Options::OptValue>
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn add(
&mut self,
n: OptNumber,
v: OptValue<Options::OptValue>
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Insert a new value for a given option
Errors when there cannot be any more options, or the option cannot be repeated any more (only applies to non-std environments)
Repeatable Options
generated from RFC7252 section 5.4.5
The definition of some options specifies that those options are repeatable. An option that is repeatable MAY be included one or more times in a message. An option that is not repeatable MUST NOT be included more than once in a message.
If a message includes an option with more occurrences than the option is defined for, each supernumerary option occurrence that appears subsequently in the message MUST be treated like an unrecognized option (see Section 5.4.1).
sourcepub fn set(
&mut self,
n: OptNumber,
v: OptValue<Options::OptValue>
) -> Result<Option<Options::OptValues>, SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set(
&mut self,
n: OptNumber,
v: OptValue<Options::OptValue>
) -> Result<Option<Options::OptValues>, SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Replace any / all existing values with a new one, yielding the previous value(s)
sourcepub fn get(&self, n: OptNumber) -> Option<&Options::OptValues>
pub fn get(&self, n: OptNumber) -> Option<&Options::OptValues>
Get the value(s) of an option by number
This just invokes toad_common::Map::get on [Message.opts].
sourcepub fn remove(&mut self, n: OptNumber) -> Option<Options::OptValues>
pub fn remove(&mut self, n: OptNumber) -> Option<Options::OptValues>
Remove all values for the option from this message, returning them if there were any.
sourcepub fn set_host<S>(
&mut self,
host: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn set_host<S>(
&mut self,
host: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Update the value for the Uri-Host option, discarding any existing values.
Uri-Host, Uri-Port, Uri-Path, and Uri-Query
generated from RFC7252 section 5.10.1
The Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options are used to specify the target resource of a request to a CoAP origin server. The options encode the different components of the request URI in a way that no percent-encoding is visible in the option values and that the full URI can be reconstructed at any involved endpoint. The syntax of CoAP URIs is defined in Section 6.
The steps for parsing URIs into options is defined in Section 6.4. These steps result in zero or more Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options being included in a request, where each option holds the following values:
o the Uri-Host Option specifies the Internet host of the resource being requested,
o the Uri-Port Option specifies the transport-layer port number of the resource,
o each Uri-Path Option specifies one segment of the absolute path to the resource, and
o each Uri-Query Option specifies one argument parameterizing the resource.
Note: Fragments ([RFC3986], Section 3.5) are not part of the request URI and thus will not be transmitted in a CoAP request.
The default value of the Uri-Host Option is the IP literal representing the destination IP address of the request message. Likewise, the default value of the Uri-Port Option is the destination UDP port. The default values for the Uri-Host and Uri-Port Options are sufficient for requests to most servers. Explicit Uri-Host and Uri-Port Options are typically used when an endpoint hosts multiple virtual servers.
The Uri-Path and Uri-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Uri-Path Option MUST NOT be “.” or “..” (as the request URI must be resolved before parsing it into options).
The steps for constructing the request URI from the options are defined in Section 6.5. Note that an implementation does not necessarily have to construct the URI; it can simply look up the target resource by examining the individual options.
Examples can be found in Appendix B.
sourcepub fn set_port(
&mut self,
port: u16
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_port(
&mut self,
port: u16
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Update the value for the Uri-Port option, discarding any existing values.
Uri-Host, Uri-Port, Uri-Path, and Uri-Query
generated from RFC7252 section 5.10.1
The Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options are used to specify the target resource of a request to a CoAP origin server. The options encode the different components of the request URI in a way that no percent-encoding is visible in the option values and that the full URI can be reconstructed at any involved endpoint. The syntax of CoAP URIs is defined in Section 6.
The steps for parsing URIs into options is defined in Section 6.4. These steps result in zero or more Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options being included in a request, where each option holds the following values:
o the Uri-Host Option specifies the Internet host of the resource being requested,
o the Uri-Port Option specifies the transport-layer port number of the resource,
o each Uri-Path Option specifies one segment of the absolute path to the resource, and
o each Uri-Query Option specifies one argument parameterizing the resource.
Note: Fragments ([RFC3986], Section 3.5) are not part of the request URI and thus will not be transmitted in a CoAP request.
The default value of the Uri-Host Option is the IP literal representing the destination IP address of the request message. Likewise, the default value of the Uri-Port Option is the destination UDP port. The default values for the Uri-Host and Uri-Port Options are sufficient for requests to most servers. Explicit Uri-Host and Uri-Port Options are typically used when an endpoint hosts multiple virtual servers.
The Uri-Path and Uri-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Uri-Path Option MUST NOT be “.” or “..” (as the request URI must be resolved before parsing it into options).
The steps for constructing the request URI from the options are defined in Section 6.5. Note that an implementation does not necessarily have to construct the URI; it can simply look up the target resource by examining the individual options.
Examples can be found in Appendix B.
sourcepub fn set_path<S>(
&mut self,
path: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn set_path<S>(
&mut self,
path: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Update the value for the Uri-Path option, discarding any existing values.
Uri-Host, Uri-Port, Uri-Path, and Uri-Query
generated from RFC7252 section 5.10.1
The Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options are used to specify the target resource of a request to a CoAP origin server. The options encode the different components of the request URI in a way that no percent-encoding is visible in the option values and that the full URI can be reconstructed at any involved endpoint. The syntax of CoAP URIs is defined in Section 6.
The steps for parsing URIs into options is defined in Section 6.4. These steps result in zero or more Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options being included in a request, where each option holds the following values:
o the Uri-Host Option specifies the Internet host of the resource being requested,
o the Uri-Port Option specifies the transport-layer port number of the resource,
o each Uri-Path Option specifies one segment of the absolute path to the resource, and
o each Uri-Query Option specifies one argument parameterizing the resource.
Note: Fragments ([RFC3986], Section 3.5) are not part of the request URI and thus will not be transmitted in a CoAP request.
The default value of the Uri-Host Option is the IP literal representing the destination IP address of the request message. Likewise, the default value of the Uri-Port Option is the destination UDP port. The default values for the Uri-Host and Uri-Port Options are sufficient for requests to most servers. Explicit Uri-Host and Uri-Port Options are typically used when an endpoint hosts multiple virtual servers.
The Uri-Path and Uri-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Uri-Path Option MUST NOT be “.” or “..” (as the request URI must be resolved before parsing it into options).
The steps for constructing the request URI from the options are defined in Section 6.5. Note that an implementation does not necessarily have to construct the URI; it can simply look up the target resource by examining the individual options.
Examples can be found in Appendix B.
sourcepub fn add_query<S>(
&mut self,
query: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn add_query<S>(
&mut self,
query: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Insert a new value for the Uri-Query option, alongside any existing values.
Uri-Host, Uri-Port, Uri-Path, and Uri-Query
generated from RFC7252 section 5.10.1
The Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options are used to specify the target resource of a request to a CoAP origin server. The options encode the different components of the request URI in a way that no percent-encoding is visible in the option values and that the full URI can be reconstructed at any involved endpoint. The syntax of CoAP URIs is defined in Section 6.
The steps for parsing URIs into options is defined in Section 6.4. These steps result in zero or more Uri-Host, Uri-Port, Uri-Path, and Uri-Query Options being included in a request, where each option holds the following values:
o the Uri-Host Option specifies the Internet host of the resource being requested,
o the Uri-Port Option specifies the transport-layer port number of the resource,
o each Uri-Path Option specifies one segment of the absolute path to the resource, and
o each Uri-Query Option specifies one argument parameterizing the resource.
Note: Fragments ([RFC3986], Section 3.5) are not part of the request URI and thus will not be transmitted in a CoAP request.
The default value of the Uri-Host Option is the IP literal representing the destination IP address of the request message. Likewise, the default value of the Uri-Port Option is the destination UDP port. The default values for the Uri-Host and Uri-Port Options are sufficient for requests to most servers. Explicit Uri-Host and Uri-Port Options are typically used when an endpoint hosts multiple virtual servers.
The Uri-Path and Uri-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Uri-Path Option MUST NOT be “.” or “..” (as the request URI must be resolved before parsing it into options).
The steps for constructing the request URI from the options are defined in Section 6.5. Note that an implementation does not necessarily have to construct the URI; it can simply look up the target resource by examining the individual options.
Examples can be found in Appendix B.
sourcepub fn set_content_format(
&mut self,
format: ContentFormat
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_content_format(
&mut self,
format: ContentFormat
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Update the value for the Content-Format option, discarding any existing values.
Content-Format
generated from RFC7252 section 5.10.3
The Content-Format Option indicates the representation format of the message payload. The representation format is given as a numeric Content-Format identifier that is defined in the “CoAP Content- Formats” registry (Section 12.3). In the absence of the option, no default value is assumed, i.e., the representation format of any representation message payload is indeterminate (Section 5.5).
sourcepub fn set_accept(
&mut self,
format: ContentFormat
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_accept(
&mut self,
format: ContentFormat
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Update the value for the Accept option, discarding any existing values.
Accept
generated from RFC7252 section 5.10.4
The CoAP Accept option can be used to indicate which Content-Format is acceptable to the client. The representation format is given as a numeric Content-Format identifier that is defined in the “CoAP Content-Formats” registry (Section 12.3). If no Accept option is given, the client does not express a preference (thus no default value is assumed). The client prefers the representation returned by the server to be in the Content-Format indicated. The server returns the preferred Content-Format if available. If the preferred Content- Format cannot be returned, then a 4.06 “Not Acceptable” MUST be sent as a response, unless another error code takes precedence for this response.
sourcepub fn set_size1(
&mut self,
size_bytes: u64
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_size1(
&mut self,
size_bytes: u64
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Update the value for the Size1 option, discarding any existing values.
Size1 Option
generated from RFC7252 section 5.10.9
The Size1 option provides size information about the resource representation in a request. The option value is an integer number of bytes. Its main use is with block-wise transfers [BLOCK]. In the present specification, it is used in 4.13 responses (Section 5.9.2.9) to indicate the maximum size of request entity that the server is able and willing to handle.
sourcepub fn set_if_exists(
&mut self
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_if_exists(
&mut self
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Discard all values for If-Match, and replace them with an empty value.
This signals that our request should only be processed if we’re trying to update a resource that exists (e.g. this ensures PUT only updates and will never insert)
If-Match
generated from RFC7252 section 5.10.8.1
The If-Match Option MAY be used to make a request conditional on the current existence or value of an ETag for one or more representations of the target resource. If-Match is generally useful for resource update requests, such as PUT requests, as a means for protecting against accidental overwrites when multiple clients are acting in parallel on the same resource (i.e., the “lost update” problem).
The value of an If-Match option is either an ETag or the empty string. An If-Match option with an ETag matches a representation with that exact ETag. An If-Match option with an empty value matches any existing representation (i.e., it places the precondition on the existence of any current representation for the target resource).
The If-Match Option can occur multiple times. If any of the options match, then the condition is fulfilled.
If there is one or more If-Match Options, but none of the options match, then the condition is not fulfilled.
sourcepub fn set_if_not_exists(
&mut self
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_if_not_exists(
&mut self
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Enable the If-None-Match flag
This signals that our request should only be processed if we’re trying to insert a resource that does not exist (e.g. this ensures PUT only inserts and will never update)
If-None-Match
generated from RFC7252 section 5.10.8.2
The If-None-Match Option MAY be used to make a request conditional on the nonexistence of the target resource. If-None-Match is useful for resource creation requests, such as PUT requests, as a means for protecting against accidental overwrites when multiple clients are acting in parallel on the same resource. The If-None-Match Option carries no value.
If the target resource does exist, then the condition is not fulfilled.
(It is not very useful to combine If-Match and If-None-Match options in one request, because the condition will then never be fulfilled.)
sourcepub fn set_max_age(
&mut self,
max_age_seconds: u32
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
pub fn set_max_age(
&mut self,
max_age_seconds: u32
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>
Update the value for the Max-Age option, discarding any existing values.
Max-Age
generated from RFC7252 section 5.10.5
The Max-Age Option indicates the maximum time a response may be cached before it is considered not fresh (see Section 5.6.1).
The option value is an integer number of seconds between 0 and 2**32-1 inclusive (about 136.1 years). A default value of 60 seconds is assumed in the absence of the option in a response.
The value is intended to be current at the time of transmission. Servers that provide resources with strict tolerances on the value of Max-Age SHOULD update the value before each retransmission. (See also Section 5.7.1.)
sourcepub fn set_proxy_uri<S>(
&mut self,
uri: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn set_proxy_uri<S>(
&mut self,
uri: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Update the value for the Proxy-Uri option, discarding any existing values.
Proxy-Uri and Proxy-Scheme
generated from RFC7252 section 5.10.2
The Proxy-Uri Option is used to make a request to a forward-proxy (see Section 5.7). The forward-proxy is requested to forward the request or service it from a valid cache and return the response.
The option value is an absolute-URI ([RFC3986], Section 4.3).
Note that the forward-proxy MAY forward the request on to another proxy or directly to the server specified by the absolute-URI. In order to avoid request loops, a proxy MUST be able to recognize all of its server names, including any aliases, local variations, and the numeric IP addresses.
An endpoint receiving a request with a Proxy-Uri Option that is unable or unwilling to act as a forward-proxy for the request MUST cause the return of a 5.05 (Proxying Not Supported) response.
The Proxy-Uri Option MUST take precedence over any of the Uri-Host, Uri-Port, Uri-Path or Uri-Query options (each of which MUST NOT be included in a request containing the Proxy-Uri Option).
As a special case to simplify many proxy clients, the absolute-URI can be constructed from the Uri-* options. When a Proxy-Scheme Option is present, the absolute-URI is constructed as follows: a CoAP URI is constructed from the Uri-* options as defined in Section 6.5. In the resulting URI, the initial scheme up to, but not including, the following colon is then replaced by the content of the Proxy- Scheme Option. Note that this case is only applicable if the components of the desired URI other than the scheme component actually can be expressed using Uri-* options; for example, to represent a URI with a userinfo component in the authority, only Proxy-Uri can be used.
sourcepub fn set_proxy_scheme<S>(
&mut self,
scheme: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn set_proxy_scheme<S>(
&mut self,
scheme: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Update the value for the Proxy-Scheme option, discarding any existing values.
Proxy-Uri and Proxy-Scheme
generated from RFC7252 section 5.10.2
The Proxy-Uri Option is used to make a request to a forward-proxy (see Section 5.7). The forward-proxy is requested to forward the request or service it from a valid cache and return the response.
The option value is an absolute-URI ([RFC3986], Section 4.3).
Note that the forward-proxy MAY forward the request on to another proxy or directly to the server specified by the absolute-URI. In order to avoid request loops, a proxy MUST be able to recognize all of its server names, including any aliases, local variations, and the numeric IP addresses.
An endpoint receiving a request with a Proxy-Uri Option that is unable or unwilling to act as a forward-proxy for the request MUST cause the return of a 5.05 (Proxying Not Supported) response.
The Proxy-Uri Option MUST take precedence over any of the Uri-Host, Uri-Port, Uri-Path or Uri-Query options (each of which MUST NOT be included in a request containing the Proxy-Uri Option).
As a special case to simplify many proxy clients, the absolute-URI can be constructed from the Uri-* options. When a Proxy-Scheme Option is present, the absolute-URI is constructed as follows: a CoAP URI is constructed from the Uri-* options as defined in Section 6.5. In the resulting URI, the initial scheme up to, but not including, the following colon is then replaced by the content of the Proxy- Scheme Option. Note that this case is only applicable if the components of the desired URI other than the scheme component actually can be expressed using Uri-* options; for example, to represent a URI with a userinfo component in the authority, only Proxy-Uri can be used.
sourcepub fn add_if_match<B>(
&mut self,
tag: B
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
B: AsRef<[u8]>,
pub fn add_if_match<B>(
&mut self,
tag: B
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
B: AsRef<[u8]>,
Insert a new value for the If-Match option, alongside any existing values.
If-Match
generated from RFC7252 section 5.10.8.1
The If-Match Option MAY be used to make a request conditional on the current existence or value of an ETag for one or more representations of the target resource. If-Match is generally useful for resource update requests, such as PUT requests, as a means for protecting against accidental overwrites when multiple clients are acting in parallel on the same resource (i.e., the “lost update” problem).
The value of an If-Match option is either an ETag or the empty string. An If-Match option with an ETag matches a representation with that exact ETag. An If-Match option with an empty value matches any existing representation (i.e., it places the precondition on the existence of any current representation for the target resource).
The If-Match Option can occur multiple times. If any of the options match, then the condition is fulfilled.
If there is one or more If-Match Options, but none of the options match, then the condition is not fulfilled.
sourcepub fn add_location_path<S>(
&mut self,
path: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn add_location_path<S>(
&mut self,
path: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Insert a new value for the Location-Path option, alongside any existing values.
Location-Path and Location-Query
generated from RFC7252 section 5.10.7
The Location-Path and Location-Query Options together indicate a relative URI that consists either of an absolute path, a query string, or both. A combination of these options is included in a 2.01 (Created) response to indicate the location of the resource created as the result of a POST request (see Section 5.8.2). The location is resolved relative to the request URI.
If a response with one or more Location-Path and/or Location-Query Options passes through a cache that interprets these options and the implied URI identifies one or more currently stored responses, those entries MUST be marked as not fresh.
Each Location-Path Option specifies one segment of the absolute path to the resource, and each Location-Query Option specifies one argument parameterizing the resource. The Location-Path and Location-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Location-Path Option MUST NOT be “.” or “..”.
The steps for constructing the location URI from the options are analogous to Section 6.5, except that the first five steps are skipped and the result is a relative URI-reference, which is then interpreted relative to the request URI. Note that the relative URI- reference constructed this way always includes an absolute path (e.g., leaving out Location-Path but supplying Location-Query means the path component in the URI is “/”).
The options that are used to compute the relative URI-reference are collectively called Location-* options. Beyond Location-Path and Location-Query, more Location-* options may be defined in the future and have been reserved option numbers 128, 132, 136, and 140. If any of these reserved option numbers occurs in addition to Location-Path and/or Location-Query and are not supported, then a 4.02 (Bad Option) error MUST be returned.
sourcepub fn add_location_query<S>(
&mut self,
query: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
pub fn add_location_query<S>(
&mut self,
query: S
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
S: AsRef<str>,
Insert a new value for the Location-Query option, alongside any existing values.
Location-Path and Location-Query
generated from RFC7252 section 5.10.7
The Location-Path and Location-Query Options together indicate a relative URI that consists either of an absolute path, a query string, or both. A combination of these options is included in a 2.01 (Created) response to indicate the location of the resource created as the result of a POST request (see Section 5.8.2). The location is resolved relative to the request URI.
If a response with one or more Location-Path and/or Location-Query Options passes through a cache that interprets these options and the implied URI identifies one or more currently stored responses, those entries MUST be marked as not fresh.
Each Location-Path Option specifies one segment of the absolute path to the resource, and each Location-Query Option specifies one argument parameterizing the resource. The Location-Path and Location-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Location-Path Option MUST NOT be “.” or “..”.
The steps for constructing the location URI from the options are analogous to Section 6.5, except that the first five steps are skipped and the result is a relative URI-reference, which is then interpreted relative to the request URI. Note that the relative URI- reference constructed this way always includes an absolute path (e.g., leaving out Location-Path but supplying Location-Query means the path component in the URI is “/”).
The options that are used to compute the relative URI-reference are collectively called Location-* options. Beyond Location-Path and Location-Query, more Location-* options may be defined in the future and have been reserved option numbers 128, 132, 136, and 140. If any of these reserved option numbers occurs in addition to Location-Path and/or Location-Query and are not supported, then a 4.02 (Bad Option) error MUST be returned.
sourcepub fn add_etag<B>(
&mut self,
tag: B
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
B: AsRef<[u8]>,
pub fn add_etag<B>(
&mut self,
tag: B
) -> Result<(), SetOptionError<OptValue<Options::OptValue>, Options::OptValues>>where
B: AsRef<[u8]>,
Insert a new value for the ETag option, alongside any existing values.
Location-Path and Location-Query
generated from RFC7252 section 5.10.7
The Location-Path and Location-Query Options together indicate a relative URI that consists either of an absolute path, a query string, or both. A combination of these options is included in a 2.01 (Created) response to indicate the location of the resource created as the result of a POST request (see Section 5.8.2). The location is resolved relative to the request URI.
If a response with one or more Location-Path and/or Location-Query Options passes through a cache that interprets these options and the implied URI identifies one or more currently stored responses, those entries MUST be marked as not fresh.
Each Location-Path Option specifies one segment of the absolute path to the resource, and each Location-Query Option specifies one argument parameterizing the resource. The Location-Path and Location-Query Option can contain any character sequence. No percent-encoding is performed. The value of a Location-Path Option MUST NOT be “.” or “..”.
The steps for constructing the location URI from the options are analogous to Section 6.5, except that the first five steps are skipped and the result is a relative URI-reference, which is then interpreted relative to the request URI. Note that the relative URI- reference constructed this way always includes an absolute path (e.g., leaving out Location-Path but supplying Location-Query means the path component in the URI is “/”).
The options that are used to compute the relative URI-reference are collectively called Location-* options. Beyond Location-Path and Location-Query, more Location-* options may be defined in the future and have been reserved option numbers 128, 132, 136, and 140. If any of these reserved option numbers occurs in addition to Location-Path and/or Location-Query and are not supported, then a 4.02 (Bad Option) error MUST be returned.
Trait Implementations§
source§impl<PayloadBytes: Array<Item = u8>, Options: OptionMap> GetSize for Message<PayloadBytes, Options>
impl<PayloadBytes: Array<Item = u8>, Options: OptionMap> GetSize for Message<PayloadBytes, Options>
source§impl<PayloadBytes: Ord, Options: Ord> Ord for Message<PayloadBytes, Options>
impl<PayloadBytes: Ord, Options: Ord> Ord for Message<PayloadBytes, Options>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<PayloadBytes: PartialEq, Options: PartialEq> PartialEq<Message<PayloadBytes, Options>> for Message<PayloadBytes, Options>
impl<PayloadBytes: PartialEq, Options: PartialEq> PartialEq<Message<PayloadBytes, Options>> for Message<PayloadBytes, Options>
source§impl<PayloadBytes: PartialOrd, Options: PartialOrd> PartialOrd<Message<PayloadBytes, Options>> for Message<PayloadBytes, Options>
impl<PayloadBytes: PartialOrd, Options: PartialOrd> PartialOrd<Message<PayloadBytes, Options>> for Message<PayloadBytes, Options>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<Bytes: AsRef<[u8]>, PayloadBytes: Array<Item = u8> + AppendCopy<u8>, Options: OptionMap> TryFromBytes<Bytes> for Message<PayloadBytes, Options>
impl<Bytes: AsRef<[u8]>, PayloadBytes: Array<Item = u8> + AppendCopy<u8>, Options: OptionMap> TryFromBytes<Bytes> for Message<PayloadBytes, Options>
§type Error = MessageParseError
type Error = MessageParseError
source§fn try_from_bytes(bytes: Bytes) -> Result<Self, Self::Error>
fn try_from_bytes(bytes: Bytes) -> Result<Self, Self::Error>
T
into Self