Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeUint32(buf []byte) (uint32, int, error)
- func EncodeUint32(buf []byte, value uint32) (int, error)
- func GetETag(r io.ReadSeeker) ([]byte, error)
- func GetPathBufferSize(path string) (int, error)
- func VerifyOptLen(optID OptionID, valueLen int) bool
- type MediaType
- type Message
- type Option
- type OptionDef
- type OptionID
- type Options
- func (options Options) Accept() (MediaType, error)
- func (options Options) Add(opt Option) Options
- func (options Options) AddBytes(buf []byte, id OptionID, data []byte) (Options, int, error)
- func (options Options) AddString(buf []byte, id OptionID, str string) (Options, int, error)
- func (options Options) AddUint32(buf []byte, id OptionID, value uint32) (Options, int, error)
- func (options Options) Clone() (Options, error)
- func (options Options) ContentFormat() (MediaType, error)
- func (options Options) Find(ID OptionID) (int, int, error)
- func (options Options) GetBytes(id OptionID) ([]byte, error)
- func (options Options) GetBytess(id OptionID, r [][]byte) (int, error)
- func (options Options) GetString(id OptionID) (string, error)
- func (options Options) GetStrings(id OptionID, r []string) (int, error)
- func (options Options) GetUint32(id OptionID) (uint32, error)
- func (options Options) GetUint32s(id OptionID, r []uint32) (int, error)
- func (options Options) HasOption(id OptionID) bool
- func (options Options) LocationPath() (string, error)
- func (options Options) Marshal(buf []byte) (int, error)
- func (options Options) Observe() (uint32, error)
- func (options Options) Path() (string, error)
- func (options Options) Queries() ([]string, error)
- func (options Options) Remove(ID OptionID) Options
- func (options Options) ResetOptionsTo(buf []byte, in Options) (Options, int, error)
- func (options Options) Set(opt Option) Options
- func (options Options) SetAccept(buf []byte, contentFormat MediaType) (Options, int, error)
- func (options Options) SetBytes(buf []byte, id OptionID, data []byte) (Options, int, error)
- func (options Options) SetContentFormat(buf []byte, contentFormat MediaType) (Options, int, error)
- func (options Options) SetLocationPath(buf []byte, path string) (Options, int, error)
- func (options Options) SetObserve(buf []byte, observe uint32) (Options, int, error)
- func (options Options) SetPath(buf []byte, path string) (Options, int, error)
- func (options Options) SetString(buf []byte, id OptionID, str string) (Options, int, error)
- func (options Options) SetUint32(buf []byte, id OptionID, value uint32) (Options, int, error)
- func (options *Options) Unmarshal(data []byte, optionDefs map[OptionID]OptionDef) (int, error)
- type Token
- type ValueFormat
Constants ¶
const ( ExtendOptionByteCode = 13 ExtendOptionByteAddend = 13 ExtendOptionWordCode = 14 ExtendOptionWordAddend = 269 ExtendOptionError = 15 )
const MaxTokenSize = 8
MaxTokenSize maximum of token size that can be used in message
Variables ¶
var ( ErrTooSmall = errors.New("too small bytes buffer") ErrInvalidOptionHeaderExt = errors.New("invalid option header ext") ErrInvalidTokenLen = errors.New("invalid token length") ErrInvalidValueLength = errors.New("invalid value length") ErrShortRead = errors.New("invalid short read") ErrOptionTruncated = errors.New("option truncated") ErrOptionUnexpectedExtendMarker = errors.New("option unexpected extend marker") ErrOptionsTooSmall = errors.New("too small options buffer") ErrInvalidEncoding = errors.New("invalid encoding") ErrOptionNotFound = errors.New("option not found") ErrOptionDuplicate = errors.New("duplicated option") )
var CoapOptionDefs = map[OptionID]OptionDef{ IfMatch: {ValueFormat: ValueOpaque, MinLen: 0, MaxLen: 8}, URIHost: {ValueFormat: ValueString, MinLen: 1, MaxLen: 255}, ETag: {ValueFormat: ValueOpaque, MinLen: 1, MaxLen: 8}, IfNoneMatch: {ValueFormat: ValueEmpty, MinLen: 0, MaxLen: 0}, Observe: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 3}, URIPort: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 2}, LocationPath: {ValueFormat: ValueString, MinLen: 0, MaxLen: 255}, URIPath: {ValueFormat: ValueString, MinLen: 0, MaxLen: 255}, ContentFormat: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 2}, MaxAge: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4}, URIQuery: {ValueFormat: ValueString, MinLen: 0, MaxLen: 255}, Accept: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 2}, LocationQuery: {ValueFormat: ValueString, MinLen: 0, MaxLen: 255}, Block2: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 3}, Block1: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 3}, Size2: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4}, ProxyURI: {ValueFormat: ValueString, MinLen: 1, MaxLen: 1034}, ProxyScheme: {ValueFormat: ValueString, MinLen: 1, MaxLen: 255}, Size1: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4}, NoResponse: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 1}, }
Functions ¶
func GetETag ¶
func GetETag(r io.ReadSeeker) ([]byte, error)
GetETag calculates ETag from payload via CRC64
func GetPathBufferSize ¶ added in v2.6.0
GetPathBufferSize gets the size of the buffer required to store path in URI-Path options.
If the path cannot be stored an error is returned.
func VerifyOptLen ¶ added in v2.6.0
VerifyOptLen checks whether valueLen is within (min, max) length limits for given option.
Types ¶
type MediaType ¶
type MediaType uint16
MediaType specifies the content format of a message.
var ( TextPlain MediaType = 0 // text/plain;charset=utf-8 AppCoseEncrypt0 MediaType = 16 // application/cose; cose-type="cose-encrypt0" (RFC 8152) AppCoseMac0 MediaType = 17 // application/cose; cose-type="cose-mac0" (RFC 8152) AppCoseSign1 MediaType = 18 // application/cose; cose-type="cose-sign1" (RFC 8152) 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 AppJSONPatch MediaType = 51 //application/json-patch+json (RFC6902) AppJSONMergePatch MediaType = 52 //application/merge-patch+json (RFC7396) AppCBOR MediaType = 60 //application/cbor (RFC 7049) AppCWT MediaType = 61 //application/cwt AppCoseEncrypt MediaType = 96 //application/cose; cose-type="cose-encrypt" (RFC 8152) AppCoseMac MediaType = 97 //application/cose; cose-type="cose-mac" (RFC 8152) AppCoseSign MediaType = 98 //application/cose; cose-type="cose-sign" (RFC 8152) AppCoseKey MediaType = 101 //application/cose-key (RFC 8152) AppCoseKeySet MediaType = 102 //application/cose-key-set (RFC 8152) AppCoapGroup MediaType = 256 //coap-group+json (RFC 7390) AppOcfCbor MediaType = 10000 //application/vnd.ocf+cbor AppLwm2mTLV MediaType = 11542 //application/vnd.oma.lwm2m+tlv AppLwm2mJSON MediaType = 11543 //application/vnd.oma.lwm2m+json )
Content formats.
func ToMediaType ¶
type Message ¶
type OptionDef ¶
type OptionDef struct { MinLen uint32 MaxLen uint32 ValueFormat ValueFormat }
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 Block2 OptionID = 23 Block1 OptionID = 27 Size2 OptionID = 28 ProxyURI OptionID = 35 ProxyScheme OptionID = 39 Size1 OptionID = 60 NoResponse OptionID = 258 )
Option IDs.
func ToOptionID ¶
type Options ¶
type Options []Option
Options Container of COAP Options, It must be always sort'ed after modification.
func (Options) AddBytes ¶
AddBytes appends bytes of a option option to options.
Returns modified options, number of used buf bytes and error if occurs.
func (Options) AddString ¶
AddString appends string option to options.
Returns modified options, number of used buf bytes and error if occurs.
func (Options) AddUint32 ¶
AddUint32 appends uint32 option to options.
Returns modified options, number of used buf bytes and error if occurs.
func (Options) ContentFormat ¶
ContentFormat gets the content format of body.
func (Options) Find ¶
Find returns range of type options. First number is index and second number is index of next option type.
func (Options) GetStrings ¶
GetStrings gets string array of all options with the given id.
func (Options) GetUint32s ¶
GetUint32s gets all options with same id.
func (Options) LocationPath ¶ added in v2.6.0
LocationPath joins Location-Path options by '/' to the buf.
Returns number of used buf bytes or error when occurs.
func (Options) Path ¶
Path joins URIPath options by '/' to the buf.
Returns number of used buf bytes or error when occurs.
func (Options) ResetOptionsTo ¶
ResetOptionsTo resets options to in options.
Returns modified options, number of used buf bytes and error if occurs.
func (Options) SetBytes ¶
SetBytes replaces/stores bytes of a option to options.
Returns modified options, number of used buf bytes and error if occurs.
func (Options) SetContentFormat ¶
SetContentFormat sets ContentFormat option.
func (Options) SetLocationPath ¶ added in v2.6.0
SetLocationPath splits path by '/' to LocationPath options and copies it to buffer.
Returns modified options, number of used buf bytes and error if occurs.
@note the url encoded into LocationPath is expected to be absolute (https://www.rfc-editor.org/rfc/rfc7252.txt)
func (Options) SetObserve ¶
SetObserve sets ContentFormat option.
func (Options) SetPath ¶
SetPath splits path by '/' to URIPath options and copies it to buffer.
Returns modified options, number of used buf bytes and error if occurs.
@note the url encoded into URIHost, URIPort, URIPath is expected to be absolute (https://www.rfc-editor.org/rfc/rfc7252.txt)
func (Options) SetString ¶
SetString replaces/stores string option to options.
Returns modified options, number of used buf bytes and error if occurs.
type ValueFormat ¶
type ValueFormat uint8
Option value format (RFC7252 section 3.2)
const ( ValueUnknown ValueFormat = iota ValueEmpty ValueOpaque ValueUint ValueString )