Documentation ¶
Overview ¶
We use this options outside of the package. It's more similar to the http Header API
Index ¶
- Variables
- type COAPCode
- type COAPType
- type CoapOptions
- type MediaType
- type Message
- func (m *Message) IsConfirmable() bool
- func (m *Message) IsNonConfirmable() bool
- func (m *Message) MarshalBinary() ([]byte, error)
- func (m *Message) MustMarshalBinary() []byte
- func (m *Message) Options() CoapOptions
- func (m *Message) Path() []string
- func (m *Message) PathString() string
- func (m *Message) SetOptions(o CoapOptions)
- func (m *Message) SetPath(s []string)
- func (m *Message) SetPathString(s string)
- func (m *Message) String() string
- func (m *Message) UnmarshalBinary(data []byte) error
- type Option
- func (o Option) AsBytes() []byte
- func (o Option) AsString() string
- func (o Option) AsUInt16() uint16
- func (o Option) AsUInt32() uint32
- func (o Option) AsUInt64() uint64
- func (o Option) AsUInt8() uint8
- func (o Option) IsNotSet() bool
- func (o Option) IsSet() bool
- func (o Option) Len() int
- func (o Option) String() string
- type OptionDef
- type OptionId
- type OptionValue
- type ValueFormat
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidTokenLen = errors.New("invalid token length") ErrOptionTooLong = errors.New("option is too long") ErrOptionGapTooLarge = errors.New("option gap too large") )
Message encoding errors.
Functions ¶
This section is empty.
Types ¶
type COAPCode ¶
type COAPCode uint8
COAPCode is the type used for both request and response codes.
const ( GET COAPCode = 1 // 0.01 POST COAPCode = 2 // 0.02 PUT COAPCode = 3 // 0.03 DELETE COAPCode = 4 // 0.04 )
Request Codes
const ( Empty COAPCode = 0 // 0.00 Created COAPCode = 65 // 2.01 Deleted COAPCode = 66 // 2.02 Valid COAPCode = 67 // 2.03 Changed COAPCode = 68 // 2.04 Content COAPCode = 69 // 2.05 BadRequest COAPCode = 128 // 4.00 BadOption COAPCode = 130 // 4.02 Forbidden COAPCode = 131 // 4.03 NotFound COAPCode = 132 // 4.04 MethodNotAllowed COAPCode = 133 // 4.05 NotAcceptable COAPCode = 134 // 4.06 PreconditionFailed COAPCode = 140 // 4.12 RequestEntityTooLarge COAPCode = 141 // 4.13 UnsupportedMediaType COAPCode = 143 // 4.15 InternalServerError COAPCode = 160 // 5.00 NotImplemented COAPCode = 161 // 5.01 BadGateway COAPCode = 162 // 5.02 GatewayTimeout COAPCode = 164 // 5.04 ProxyingNotSupported COAPCode = 165 // 5.05 )
Response Codes
type COAPType ¶
type COAPType uint8
COAPType represents the message type.
const ( // Confirmable messages require acknowledgements. Confirmable COAPType = 0 // NonConfirmable messages do not require acknowledgements. NonConfirmable COAPType = 1 // Acknowledgement is a message indicating a response to confirmable message. Acknowledgement COAPType = 2 // Reset indicates a permanent negative acknowledgement. Reset COAPType = 3 )
type CoapOptions ¶
A CoapOptions represents a option mapping keys to sets of values.
func (CoapOptions) Add ¶
func (h CoapOptions) Add(key OptionId, value interface{}) error
Add adds the key, value pair to the header. It appends to any existing values associated with key.
func (CoapOptions) Del ¶
func (h CoapOptions) Del(key OptionId)
Del deletes the values associated with key.
func (CoapOptions) Get ¶
func (h CoapOptions) Get(key OptionId) Option
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns NilOptionValue. Get is a convenience method. For more complex queries, access the map directly.
func (CoapOptions) Set ¶
func (h CoapOptions) Set(key OptionId, value interface{}) error
Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.
func (CoapOptions) String ¶
func (h CoapOptions) String() string
type MediaType ¶
type MediaType byte
MediaType specifies the content type of a message.
const ( TextPlain MediaType = 0 // text/plain;charset=utf-8 AppLinkFormat MediaType = 40 // application/link-format AppXML MediaType = 41 // application/xml AppOctets MediaType = 42 // application/octet-stream AppExi MediaType = 47 // application/exi AppJSON MediaType = 50 // application/json )
Content types.
type Message ¶
type Message struct { Type COAPType Code COAPCode MessageID uint16 Token, Payload []byte // contains filtered or unexported fields }
Message is a CoAP message.
func NewMessage ¶
func NewMessage() Message
func ParseMessage ¶
func (*Message) IsConfirmable ¶
IsConfirmable returns true if this message is confirmable.
func (*Message) IsNonConfirmable ¶
IsConfirmable returns true if this message is confirmable.
func (*Message) MarshalBinary ¶
Fulfill the encoding.BinaryMarshaler interface
func (*Message) MustMarshalBinary ¶
MarshalBinary produces the binary form of this Message.
func (*Message) Options ¶
func (m *Message) Options() CoapOptions
func (*Message) PathString ¶
PathString gets a path as a / separated string.
func (*Message) SetOptions ¶
func (m *Message) SetOptions(o CoapOptions)
func (*Message) SetPathString ¶
SetPathString sets a path by a / separated string.
func (*Message) UnmarshalBinary ¶
UnmarshalBinary parses the given binary slice as a Message.
type Option ¶
type Option struct { Id OptionId // contains filtered or unexported fields }
type OptionDef ¶
type OptionDef struct { Number OptionId MinLength int MaxLength int DefaultValue []byte // Or interface{} or OptionValue? Repeatable bool Format ValueFormat }
Currently only used in tests to find options
type OptionId ¶
type OptionId uint16
OptionID identifies an option in a message.
const ( IfMatch OptionId = 1 URIHost OptionId = 3 ETag OptionId = 4 IfNoneMatch OptionId = 5 Observe OptionId = 6 URIPort OptionId = 7 LocationPath OptionId = 8 URIPath OptionId = 11 ContentFormat OptionId = 12 MaxAge OptionId = 14 URIQuery OptionId = 15 Accept OptionId = 17 LocationQuery OptionId = 20 ProxyURI OptionId = 35 ProxyScheme OptionId = 39 Size1 OptionId = 60 )
Option IDs.
func (OptionId) NoCacheKey ¶
NoCacheKey only has a meaning for options that are Safe-to-Forward
type OptionValue ¶
type OptionValue struct {
// contains filtered or unexported fields
}
var NilOptionValue OptionValue = OptionValue{/* contains filtered or unexported fields */}
func (OptionValue) AsBytes ¶
func (v OptionValue) AsBytes() []byte
func (OptionValue) AsString ¶
func (v OptionValue) AsString() string
func (OptionValue) AsUInt16 ¶
func (v OptionValue) AsUInt16() uint16
For signed values just convert the result
func (OptionValue) AsUInt32 ¶
func (v OptionValue) AsUInt32() uint32
For signed values just convert the result
func (OptionValue) AsUInt64 ¶
func (v OptionValue) AsUInt64() uint64
For signed values just convert the result
func (OptionValue) AsUInt8 ¶
func (v OptionValue) AsUInt8() uint8
For signed values just convert the result
func (OptionValue) Len ¶
func (v OptionValue) Len() int
type ValueFormat ¶
type ValueFormat uint8
Option value format (RFC7252 section 3.2) Defines the option format inside the packet
const ( ValueUnknown ValueFormat = iota ValueEmpty // A zero-length sequence of bytes. ValueOpaque // An opaque sequence of bytes. // A non-negative integer that is represented in network byte // order using the number of bytes given by the Option Length // field. ValueUint // A Unicode string that is encoded using UTF-8 [RFC3629] in // Net-Unicode form [RFC5198]. ValueString )
func (ValueFormat) PrettyPrint ¶
func (f ValueFormat) PrettyPrint(val OptionValue) string