blockwise

package
v3.3.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBlockNumberExceedLimit block number exceeded the limit 1,048,576
	ErrBlockNumberExceedLimit = errors.New("block number exceeded the limit 1,048,576")

	// ErrBlockInvalidSize block has invalid size
	ErrBlockInvalidSize = errors.New("block has invalid size")

	// ErrInvalidOptionBlock2 message has invalid value of Block2
	ErrInvalidOptionBlock2 = errors.New("message has invalid value of Block2")

	// ErrInvalidOptionBlock1 message has invalid value of Block1
	ErrInvalidOptionBlock1 = errors.New("message has invalid value of Block1")

	// ErrInvalidResponseCode response code has invalid value
	ErrInvalidResponseCode = errors.New("response code has invalid value")

	// ErrInvalidPayloadSize invalid payload size
	ErrInvalidPayloadSize = errors.New("invalid payload size")

	// ErrInvalidSZX invalid block-wise transfer szx
	ErrInvalidSZX = errors.New("invalid block-wise transfer szx")
)

Functions

func EncodeBlockOption

func EncodeBlockOption(szx SZX, blockNumber int64, moreBlocksFollowing bool) (uint32, error)

EncodeBlockOption encodes block values to coap option.

Types

type BlockWise

type BlockWise[C Client] struct {
	// contains filtered or unexported fields
}

func New

func New[C Client](
	cc C,
	expiration time.Duration,
	errors func(error),
	getSentRequestFromOutside func(token message.Token) (*pool.Message, bool),
) *BlockWise[C]

New provides blockwise. getSentRequestFromOutside must returns a copy of request which will be released after use.

func (*BlockWise[C]) CheckExpirations

func (b *BlockWise[C]) CheckExpirations(now time.Time)

CheckExpirations iterates over caches and remove expired items.

func (*BlockWise[C]) Do

func (b *BlockWise[C]) Do(r *pool.Message, maxSzx SZX, maxMessageSize uint32, do func(req *pool.Message) (*pool.Message, error)) (*pool.Message, error)

Do sends an coap message and returns an coap response via blockwise transfer.

func (*BlockWise[C]) Handle

func (b *BlockWise[C]) Handle(w *responsewriter.ResponseWriter[C], r *pool.Message, maxSZX SZX, maxMessageSize uint32, next func(w *responsewriter.ResponseWriter[C], r *pool.Message))

Handle middleware which constructs COAP request from blockwise transfer and send COAP response via blockwise.

func (*BlockWise[C]) WriteMessage

func (b *BlockWise[C]) WriteMessage(request *pool.Message, maxSZX SZX, maxMessageSize uint32, writeMessage func(r *pool.Message) error) error

WriteMessage sends an coap message via blockwise transfer.

type Client

type Client interface {
	// create message from pool
	AcquireMessage(ctx context.Context) *pool.Message
	// return back the message to the pool for next use
	ReleaseMessage(m *pool.Message)
}

type SZX

type SZX uint8

SZX enum representation for the size of the block: https://tools.ietf.org/html/rfc7959#section-2.2

const (
	// SZX16 block of size 16bytes
	SZX16 SZX = 0
	// SZX32 block of size 32bytes
	SZX32 SZX = 1
	// SZX64 block of size 64bytes
	SZX64 SZX = 2
	// SZX128 block of size 128bytes
	SZX128 SZX = 3
	// SZX256 block of size 256bytes
	SZX256 SZX = 4
	// SZX512 block of size 512bytes
	SZX512 SZX = 5
	// SZX1024 block of size 1024bytes
	SZX1024 SZX = 6
	// SZXBERT block of size n*1024bytes
	SZXBERT SZX = 7
)

func DecodeBlockOption

func DecodeBlockOption(blockVal uint32) (szx SZX, blockNumber int64, moreBlocksFollowing bool, err error)

DecodeBlockOption decodes coap block option to block values.

func (SZX) Size

func (s SZX) Size() int64

Size number of bytes.

Jump to

Keyboard shortcuts

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