chopper

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: Apache-2.0, BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package chopper helps splitting messages into smaller pieces and reassemble them

Index

Constants

View Source
const (

	// MaxNChunks maximum number of chunks
	MaxNChunks = math.MaxUint16
)

Variables

This section is empty.

Functions

func NumChunks

func NumChunks(dataLen, maxMsgSize, includingChoppingOverhead int) (uint16, int, error)

NumChunks returns the expected amount of chunks for the given data length

Types

type Chopper

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

Chopper handles the splitting and joining of large messages

func NewChopper

func NewChopper() *Chopper

NewChopper creates a new chopper instance

func (*Chopper) ChopData

func (c *Chopper) ChopData(data []byte, maxMsgSize, includingChoppingOverhead int) ([][]byte, bool, error)

ChopData chops data into pieces (not more than 255) and adds chopper header to each piece for IncomingChunk function to reassemble it

func (*Chopper) Close

func (c *Chopper) Close()

Close stops the internal cleanup goroutine

func (*Chopper) IncomingChunk

func (c *Chopper) IncomingChunk(data []byte, maxMsgSize, includingChoppingOverhead int) ([]byte, error)

IncomingChunk collects all incoming chunks. Returned != nil value of the reassembled data maxChunkSize parameter must be the same on both sides

Jump to

Keyboard shortcuts

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