frameio

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 6 Imported by: 3

README

Frame IO

Go Reference

DoS Safe Frame based IO.

Convert Stream to Frame!

  • Payload Size Verification (Safe from attacks that falsify payload size)
  • Read CallBack (Reduce Memory Allocation)
  • Read To Buffer (Reduce Memory Allocation)
  • Payload maximum size limit

Protocol

frame "N" is set to 1 if it is the last block of that frame If there are additional blocks after that, N is set to 0

Documentation

Index

Constants

View Source
const BLOCK_SIZE = 127

Variables

View Source
var BufioPool *bufiopool.Pool = bufiopool.New(0, 0)
View Source
var ErrFrameTooLarge = errors.New("frame too large")

Frame Size Exceeds MaxSize.

View Source
var ErrInvalidBlockSize = errors.New("invalid block size")

BlockSize is bigger than the maximum BLOCK_SIZE.

View Source
var ErrSizeMismatch = errors.New("size mismatch")

Sum of all block sizes is not equal to TotalSize.

Functions

This section is empty.

Types

type FrameReader

type FrameReader struct {
	R io.Reader
}

ReadFrame read frame from io.Reader

r: io.Reader should be buffered

func NewFrameReader

func NewFrameReader(r io.Reader) FrameReader

Create a new FrameReader

r: io.Reader should be buffered

func (*FrameReader) Read

func (r *FrameReader) Read() (data []byte, err error)

Read one frame from the reader and return it as a byte array. (allocates memory)

func (*FrameReader) ReadCallback

func (r *FrameReader) ReadCallback(cb func([]byte)) (err error)

Read one frame from the reader and call the callback function.

Returned byte slice is not valid after the callback function returns. (due to reusing the buffer)

func (*FrameReader) ReadCallbackMax added in v1.2.0

func (r *FrameReader) ReadCallbackMax(cb func([]byte), maxSize int) (err error)

Read one frame from the reader and call the callback function.

Returned byte slice is not valid after the callback function returns. (due to reusing the buffer)

If the frame is larger than maxSize, ErrFrameTooLarge is returned.

func (*FrameReader) ReadMax added in v1.2.0

func (r *FrameReader) ReadMax(maxSize int) (data []byte, err error)

Read one frame from the reader and return it as a byte array. (allocates memory)

If the frame is larger than maxSize, ErrFrameTooLarge is returned.

func (*FrameReader) ReadToBuffer

func (r *FrameReader) ReadToBuffer(w io.Writer) (err error)

Read one frame from the reader and write it to the buffer.

func (*FrameReader) ReadToBufferMax added in v1.2.0

func (r *FrameReader) ReadToBufferMax(w io.Writer, maxSize int) (err error)

Read one frame from the reader and write it to the writer.

If the frame is larger than maxSize, ErrFrameTooLarge is returned.

type FrameWriter

type FrameWriter struct {
	W io.Writer
}

FrameWriter write frame to io.Writer

w: io.Writer should be buffered

func NewFrameWriter

func NewFrameWriter(w io.Writer) FrameWriter

Create a new FrameWriter

w: io.Writer should be buffered

func (*FrameWriter) Write

func (w *FrameWriter) Write(b []byte) (err error)

Write one frame to the writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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