secoapcore

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Indicates an Empty message
	Empty Code = 0

	// Request Codes
	GET    Code = 1
	POST   Code = 2
	PUT    Code = 3
	DELETE Code = 4

	// Response Codes
	Created                 Code = 65
	Deleted                 Code = 66
	Valid                   Code = 67
	Changed                 Code = 68
	Content                 Code = 69
	Continue                Code = 95
	BadRequest              Code = 128
	Unauthorized            Code = 129
	BadOption               Code = 130
	Forbidden               Code = 131
	NotFound                Code = 132
	MethodNotAllowed        Code = 133
	NotAcceptable           Code = 134
	RequestEntityIncomplete Code = 136
	PreconditionFailed      Code = 140
	RequestEntityTooLarge   Code = 141
	UnsupportedMediaType    Code = 143
	TooManyRequests         Code = 157
	InternalServerError     Code = 160
	NotImplemented          Code = 161
	BadGateway              Code = 162
	ServiceUnavailable      Code = 163
	GatewayTimeout          Code = 164
	ProxyingNotSupported    Code = 165

	// 6.00-6.31 Reserved
	GiterlabErrnoOk              = 192 // 正常响应  [PV1/PV2]
	GiterlabErrnoParamConfigure  = 193 // 有新的配置参数 [PV2]
	GiterlabErrnoFirmwareUpdate  = 194 // 有新的固件可以更新 [PV2]
	GiterlabErrnoUserCommand     = 195 // 有用户命令需要执行 [PV2]
	GiterlabErrnoEnterFlightMode = 220 // 进入飞行模式[PV2]

	// 7.00-7.31 Reserved
	GiterlabErrnoIllegalKey                  = 224 //    KEY错误,设备激活码错误 [PV1/PV2]
	GiterlabErrnoDataError                   = 225 //    数据错误 [PV1/PV2]
	GiterlabErrnoDeviceNotExist              = 226 //    设备不存在或设备传感器类型匹配错误 [PV1/PV2]
	GiterlabErrnoTimeExpired                 = 227 //    时间过期 [PV1/PV2]
	GiterlabErrnoNotSupportProtocolVersion   = 228 //    不支持的协议版本 [PV1/PV2]
	GiterlabErrnoProtocolParsingErrors       = 229 //    议解析错误 [PV1/PV2]
	GiterlabErrnoRequestTimeout              = 230 // [*]请求超时 [PV1/PV2]
	GiterlabErrnoOptProtocolParsingErrors    = 231 //    可选附加头解析错误 [PV1/PV2]
	GiterlabErrnoNotSupportAnalyticalMethods = 232 //    不支持的可选附加头解析方法 [PV1/PV2]
	GiterlabErrnoNotSupportPacketType        = 233 //    不支持的包类型 [PV1/PV2]
	GiterlabErrnoDataDecodingError           = 234 //    数据解码错误 [PV1/PV2]
	GiterlabErrnoPackageLengthError          = 235 //    数据包长度字段错误 [PV1/PV2]
	GiterlabErrnoDuoxieyunServerRequestBusy  = 236 // [*]多协云服务器请求失败 [PV1过时了]
	GiterlabErrnoSluanServerRequestBusy      = 237 // [*]石峦服务器请求失败 [PV2过时了]
	GiterlabErrnoCacheServiceErrors          = 238 // [*]缓存服务出错 [PV1/PV2]
	GiterlabErrnoTableStoreServiceErrors     = 239 // [*]表格存储服务出错 [PV1/PV2]
	GiterlabErrnoDatabaseServiceErrors       = 240 // [*]数据库存储出错 [PV1/PV2]
	GiterlabErrnoNotSupportEncodingType      = 241 //    不支持的编码类型 [PV1/PV2]
	GiterlabErrnoDeviceRepeatRegistered      = 242 //    设备重复注册 [PV2]
	GiterlabErrnoDeviceSimCardUsed           = 243 //    设备手机卡重复使用 [PV2]
	GiterlabErrnoDeviceSimCardIllegal        = 244 //    设备手机卡未登记,非法的SIM卡 [PV2]
	GiterlabErrnoDeviceUpdateForcedFailed    = 245 //    强制更新设备信息失败 [PV2]
)
View Source
const (
	// EncoderTypeNoneUserDefine none/userdefine
	EncoderTypeNoneUserDefine = "none/userdefine"
	// EncoderTypeTextBase64 text/base64
	EncoderTypeTextBase64 = "text/base64"
	// EncoderTypeTextPlain text/plain
	EncoderTypeTextPlain = "text/plain"
	// EncoderTypeTextHex text/hex
	EncoderTypeTextHex = "text/hex"
	// EncoderTypeApplicationOctetStream application/octet-stream
	EncoderTypeApplicationOctetStream = "application/octet-stream"
	// EncoderTypeApplicationProtobuf application/protobuf
	EncoderTypeApplicationProtobuf = "application/protobuf"
	// EncoderTypeApplicationJson application/json
	EncoderTypeApplicationJson = "application/json"
)
View Source
const (
	ExtendOptionByteCode   = 13
	ExtendOptionByteAddend = 13
	ExtendOptionWordCode   = 14
	ExtendOptionWordAddend = 269
	ExtendOptionError      = 15
)
View Source
const MaxTokenSize = 8

MaxTokenSize maximum of token size that can be used in message

Variables

View Source
var (
	ErrTooSmall               = errors.New("too small bytes buffer")
	ErrShortRead              = errors.New("invalid short read")
	ErrInvalidOptionHeaderExt = errors.New("invalid option header ext")
	ErrInvalidTokenLen        = errors.New("invalid token length")
	ErrInvalidValueLength     = errors.New("invalid value length")
	ErrInvalidEncoding        = errors.New("invalid encoding")

	ErrOptionTruncated              = errors.New("option truncated")
	ErrOptionUnexpectedExtendMarker = errors.New("option unexpected extend marker")
	ErrOptionsTooSmall              = errors.New("too small options buffer")
	ErrOptionTooLong                = errors.New("option is too long")
	ErrOptionGapTooLarge            = errors.New("option gap too large")
	ErrOptionNotFound               = errors.New("option not found")
	ErrOptionDuplicate              = errors.New("duplicated option")

	ErrMessageNil            = errors.New("message is nil")
	ErrMessageTruncated      = errors.New("message is truncated")
	ErrMessageInvalidVersion = errors.New("message has invalid version")
	ErrMessageInvalidRSUM8   = errors.New("message has invalid rsum8")
	ErrInvalidRCRC16         = errors.New("message has invalid crc16")
)
View Source
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},

	GiterLabID:    {ValueFormat: ValueString, MinLen: 0, MaxLen: 255},
	GiterLabKey:   {ValueFormat: ValueString, MinLen: 0, MaxLen: 255},
	AccessID:      {ValueFormat: ValueString, MinLen: 0, MaxLen: 255},
	AccessKey:     {ValueFormat: ValueString, MinLen: 0, MaxLen: 255},
	CheckCRC32:    {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4},
	EncoderType:   {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4},
	EncoderID:     {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4},
	PackageNumber: {ValueFormat: ValueUint, MinLen: 0, MaxLen: 4},
}

Functions

func CRC16Bytes

func CRC16Bytes(data []byte) uint16

CRC16Bytes 对数据流进行CRC16校验

func CRC32Bytes

func CRC32Bytes(data []byte) uint32

CRC32Bytes 计算一个数据流的CRC32值

func CRC32String

func CRC32String(str string) uint32

CRC32String 计算一个字符串的CRC32值

func DecodeUint32

func DecodeUint32(buf []byte) (uint32, int, error)

func EncodeUint32

func EncodeUint32(buf []byte, value uint32) (int, error)

func GetEncoder

func GetEncoder(encoderTypeX string) (encoderType int32, encoderID int32)

GetEncoder 根据编码器,获取对应的编码类型

func GetEncoderType

func GetEncoderType(encoderType int32, encoderID int32) string

GetEncoderType 获取协议 Payload 编码类型, coap协议默认是 application/protobuf

func GetMID

func GetMID() int32

GetMID generates a message id for UDP. (0 <= mid <= 65535)

func GetPathBufferSize

func GetPathBufferSize(path string) (int, error)

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 RSUM8 added in v1.0.1

func RSUM8(data []byte) byte

RSUM8 计算一个数据流的RSUM8值

func RandMID

func RandMID() int32

func ValidateEID added in v1.0.1

func ValidateEID(eid int32) bool

ValidateEID validates a message eid for Payload. (0 <= eid <= 15)

func ValidateETP added in v1.0.1

func ValidateETP(etp int32) bool

ValidateETP validates a message etp for Payload. (0 <= etp <= 15)

func ValidateMID

func ValidateMID(mid int32) bool

ValidateMID validates a message id for UDP. (0 <= mid <= 65535)

func ValidateType

func ValidateType(typ Type) bool

ValidateType validates the type for UDP. (0 <= typ <= 255)

func ValidateVer added in v1.0.3

func ValidateVer(typ Ver) bool

ValidateVer validates the ver for UDP. (0 <= typ <= 3)

func VerifyOptLen

func VerifyOptLen(optionDefs map[OptionID]OptionDef, optionID OptionID, valueLen int) bool

VerifyOptLen checks whether valueLen is within (min, max) length limits for given option.

Types

type Code

type Code uint8

Code is the type used for both request and response codes.

func ToCode

func ToCode(v string) (Code, error)

func (Code) String

func (c Code) String() string

type MediaType

type MediaType uint16

MediaType specifies the content type of a message.

const (
	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)
	AppSenmlJSON      MediaType = 110   // application/senml+json
	AppSenmlCbor      MediaType = 112   // application/senml+cbor
	AppCoapGroup      MediaType = 256   // coap-group+json (RFC 7390)
	AppSenmlEtchJSON  MediaType = 320   // application/senml-etch+json
	AppSenmlEtchCbor  MediaType = 322   // application/senml-etch+cbor
	AppOcfCbor        MediaType = 10000 // application/vnd.ocf+cbor
	AppLwm2mTLV       MediaType = 11542 // application/vnd.oma.lwm2m+tlv
	AppLwm2mJSON      MediaType = 11543 // application/vnd.oma.lwm2m+json
	AppLwm2mCbor      MediaType = 11544 // application/vnd.oma.lwm2m+cbor
)

Content types.

func ToMediaType

func ToMediaType(v string) (MediaType, error)

func (MediaType) String

func (c MediaType) String() string

type Message

type Message struct {
	Ver     Ver
	Token   Token
	Opts    Options
	Code    Code
	Payload []byte

	// For DTLS and UDP messages
	MessageID int32 // uint16 is valid, all other values are invalid, -1 is used for unset
	Type      Type  // uint8 is valid, all other values are invalid, -1 is used for unset

	// Additional fields
	EncoderID   int32 // 4 bits is valid, all other values are invalid, -1 is used for unset
	EncoderType int32 // 4 bits is valid, all other values are invalid, -1 is used for unset

	// Checksum
	Crc16 uint16
	Rsum8 uint8
}

Message is a Secoap message.

func (*Message) AddOption

func (m *Message) AddOption(opID OptionID, val interface{})

AddOption adds an option.

func (*Message) Analyse added in v1.0.5

func (m *Message) Analyse() string

Anlayse 协议分析

func (Message) IsConfirmable

func (m Message) IsConfirmable() bool

IsConfirmable returns true if this message is confirmable.

func (Message) Option

func (m Message) Option(o OptionID) interface{}

Option gets the first value for the given option ID.

func (Message) Options

func (m Message) Options(o OptionID) []interface{}

Options gets all the values for the given option.

func (Message) Path

func (m Message) Path() []string

Path gets the Path set on this message if any.

func (Message) PathString

func (m Message) PathString() string

PathString gets a path as a / separated string.

func (*Message) RemoveOption

func (m *Message) RemoveOption(opID OptionID)

RemoveOption removes all references to an option

func (*Message) SetOption

func (m *Message) SetOption(opID OptionID, val interface{})

SetOption sets an option, discarding any previous value

func (*Message) SetPath

func (m *Message) SetPath(s []string)

SetPath updates or adds a URIPath attribute on this message.

func (*Message) SetPathString

func (m *Message) SetPathString(s string)

SetPathString sets a path by a / separated string.

func (*Message) String

func (m *Message) String() string

type Option

type Option struct {
	ID    OptionID
	Value interface{}
}

func (Option) Marshal

func (o Option) Marshal(buf []byte, previousID OptionID) (int, error)

Marshal 将 Option 按照 Option Format 序列化到 buf 中, previousID 为前一个 Option 的 ID, 用于计算 Option Delta

func (Option) MarshalValue

func (o Option) MarshalValue(buf []byte) (int, error)

func (Option) String

func (o Option) String() string

String 返回 Option 的字符串表示

func (Option) ToBytes

func (o Option) ToBytes() []byte

func (*Option) Unmarshal

func (o *Option) Unmarshal(optionDefs map[OptionID]OptionDef, optionID OptionID, data []byte) (int, error)

Unmarshal 从 data 中反序列化成 Option

func (*Option) UnmarshalValue

func (o *Option) UnmarshalValue(optionDefs map[OptionID]OptionDef, buf []byte) (int, error)

type OptionDef

type OptionDef struct {
	MinLen      int
	MaxLen      int
	ValueFormat ValueFormat
}

type OptionID

type OptionID uint32

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

	// The IANA policy for future additions to this sub-registry is split
	// into three tiers as follows.  The range of 0..255 is reserved for
	// options defined by the IETF (IETF Review or IESG Approval).  The
	// range of 256..2047 is reserved for commonly used options with public
	// specifications (Specification Required).  The range of 2048..64999 is
	// for all other options including private or vendor-specific ones,
	// which undergo a Designated Expert review to help ensure that the
	// option semantics are defined correctly.  The option numbers between
	// 65000 and 65535 inclusive are reserved for experiments.  They are not
	// meant for vendor-specific use of any kind and MUST NOT be used in
	// operational deployments.
	GiterLabID    OptionID = 65000
	GiterLabKey   OptionID = 65001
	AccessID      OptionID = 65002
	AccessKey     OptionID = 65003
	CheckCRC32    OptionID = 65004
	EncoderType   OptionID = 65005
	EncoderID     OptionID = 65006
	PackageNumber OptionID = 65100
)

Option IDs.

func ToOptionID

func ToOptionID(v string) (OptionID, error)

func (OptionID) String

func (o OptionID) String() string

type Options

type Options []Option

func (Options) Accept

func (options Options) Accept() (MediaType, error)

Accept gets accept option.

func (Options) Add

func (options Options) Add(opt Option) Options

Add appends option to options.

func (Options) AddBytes

func (options Options) AddBytes(buf []byte, id OptionID, data []byte) (Options, int, error)

AddBytes appends bytes of a option to options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) AddString

func (options Options) AddString(buf []byte, id OptionID, str string) (Options, int, error)

AddString appends string option to options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) AddUint32

func (options Options) AddUint32(buf []byte, id OptionID, value uint32) (Options, int, error)

AddUint32 appends uint32 option to options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) Clone

func (options Options) Clone() (Options, error)

Clone create duplicates of options.

func (Options) ContentFormat

func (options Options) ContentFormat() (MediaType, error)

ContentFormat gets the content format of body.

func (Options) Find

func (options Options) Find(id OptionID) (int, int, error)

Find returns range of type options. First number is index and second number is index of next option type.

func (Options) GetBytes

func (options Options) GetBytes(id OptionID) ([]byte, error)

GetBytes gets bytes of the first option with given id.

func (Options) GetBytess

func (options Options) GetBytess(id OptionID, r [][]byte) (int, error)

GetBytess gets array of bytes of all options with the same id.

func (Options) GetString

func (options Options) GetString(id OptionID) (string, error)

GetString gets the string value of the first option with the given ID.

func (Options) GetStrings

func (options Options) GetStrings(id OptionID, r []string) (int, error)

GetStrings gets string array of all options with the given id.

func (Options) GetUint32

func (options Options) GetUint32(id OptionID) (uint32, error)

GetUint32 gets the uin32 value of the first option with the given ID.

func (Options) GetUint32s

func (options Options) GetUint32s(id OptionID, r []uint32) (int, error)

GetUint32s gets all options with same id.

func (Options) HasOption

func (options Options) HasOption(id OptionID) bool

HasOption returns true is option exist in options.

func (Options) Len

func (o Options) Len() int

func (Options) Less

func (o Options) Less(i, j int) bool

func (Options) LocationPath

func (options Options) LocationPath() (string, error)

LocationPath joins Location-Path options by '/' to the buf.

Returns number of used buf bytes or error when occurs.

func (Options) Marshal

func (options Options) Marshal(buf []byte) (int, error)

Marshal marshals options to buf.

Returns the number of used buf bytes.

func (Options) Minus

func (o Options) Minus(oid OptionID) Options

Minus returns a new Options with the given OptionID removed.

func (Options) Observe

func (options Options) Observe() (uint32, error)

Observe gets Observe option.

func (Options) Path

func (options Options) Path() (string, error)

Path joins URIPath options by '/' to the buf.

Returns number of used buf bytes or error when occurs.

func (Options) Queries

func (options Options) Queries() ([]string, error)

Queries gets URIQuery parameters.

func (Options) Remove

func (options Options) Remove(id OptionID) Options

Remove removes all options with ID.

func (Options) ResetOptionsTo

func (options Options) ResetOptionsTo(buf []byte, in Options) (Options, int, error)

ResetOptionsTo resets options to in options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) Set

func (options Options) Set(opt Option) Options

Set replaces/stores option at options.

Returns modified options.

func (Options) SetAccept

func (options Options) SetAccept(buf []byte, contentFormat MediaType) (Options, int, error)

SetAccept sets accept option.

func (Options) SetBytes

func (options Options) SetBytes(buf []byte, id OptionID, data []byte) (Options, int, error)

SetBytes replaces/stores bytes of a option to options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) SetContentFormat

func (options Options) SetContentFormat(buf []byte, contentFormat MediaType) (Options, int, error)

SetContentFormat sets ContentFormat option.

func (Options) SetLocationPath

func (options Options) SetLocationPath(buf []byte, path string) (Options, int, error)

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

func (options Options) SetObserve(buf []byte, observe uint32) (Options, int, error)

SetObserve sets Observe option.

func (Options) SetPath

func (options Options) SetPath(buf []byte, path string) (Options, int, error)

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

func (options Options) SetString(buf []byte, id OptionID, str string) (Options, int, error)

SetString replaces/stores string option to options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) SetUint32

func (options Options) SetUint32(buf []byte, id OptionID, value uint32) (Options, int, error)

SetUint32 replaces/stores uint32 option to options.

Returns modified options, number of used buf bytes and error if occurs.

func (Options) String added in v1.0.5

func (options Options) String(sep string) string

func (Options) Swap

func (o Options) Swap(i, j int)

func (Options) URL added in v1.0.5

func (options Options) URL() string

URL returns the URL of the options.

func (*Options) Unmarshal

func (options *Options) Unmarshal(data []byte, optionDefs map[OptionID]OptionDef) (int, error)

Unmarshal unmarshals data bytes to options and returns the number of consumed bytes.

type Rand

type Rand struct {
	// contains filtered or unexported fields
}

func NewRand

func NewRand(seed int64) *Rand

func (*Rand) Int63

func (l *Rand) Int63() int64

func (*Rand) Uint32

func (l *Rand) Uint32() uint32

type Token

type Token []byte

func GetToken

func GetToken() (Token, error)

GetToken generates a random token by a given length

func (Token) Hash

func (t Token) Hash() uint64

func (Token) String

func (t Token) String() string

type Type

type Type int16

Type represents the message type. It's only part of Secoap UDP messages. Reliable transports like TCP do not have a type.

const (
	// Used for unset
	Unset Type = -1
	// Confirmable messages require acknowledgements.
	Confirmable Type = 0
	// NonConfirmable messages do not require acknowledgements.
	NonConfirmable Type = 1
	// Acknowledgement is a message indicating a response to confirmable message.
	Acknowledgement Type = 2
	// Reset indicates a permanent negative acknowledgement.
	Reset Type = 3
)

func ToType

func ToType(v string) (Type, error)

func (Type) String

func (c Type) String() string

type ValueFormat

type ValueFormat uint8

Option value format (RFC7252 section 3.2)

const (
	ValueUnknown ValueFormat = iota
	ValueEmpty
	ValueOpaque
	ValueUint
	ValueString
)

type Ver added in v1.0.3

type Ver int8

Ver represents the message ver. It's only part of Secoap UDP messages.

const (
	// Version0
	Version0 Ver = 0
	// Version1
	Version1 Ver = 1
	// Version2
	Version2 Ver = 2
)

func GetVersion added in v1.0.5

func GetVersion(payload []byte) (ver Ver, err error)

GetVersion gets the version from the payload.

func ToVer added in v1.0.3

func ToVer(v string) (Ver, error)

func (Ver) String added in v1.0.3

func (c Ver) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL