Help us shape the future of Go! Take the 2026 Go Developer Survey

slip

package module
v0.0.0-...-88dcb78 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2017 License: MIT Imports: 3 Imported by: 7

README

slip & slipmux

Implementation of SLIP (rfc-1055) in GoLang

In addition to the basic SLIP reader and writer there is also a SlipMux implementation, that enables sending different packet types like CoAP and Diagnostic messages over serial line. This is implemented backward compatible to SLIP implementations which support only IP packets.

If needed, further packet types can be implemented by the user of the library.

Install

go get -u github.com/Lobaro/slip

Usage (SLIP)

import github.com/Lobaro/slip

Read Packets

	data := []byte{1, 2, 3, slip.END}
	reader := slip.NewReader(bytes.NewReader(data))
	packet, isPrefix, err := reader.ReadPacket()

	// packet == [1, 2, 3]
	// isPrefix == false
	// err == io.EOF

Write Packets

	buf := &bytes.Buffer{}
	writer := slip.NewWriter(buf)
	err := writer.WritePacket([]byte{1, 2, 3})

	// buf.Bytes() ==  [END, 1, 2, 3, END]

Documentation

Index

Constants

View Source
const (
	END     = 0300 /* 0xC0 indicates end of packet */
	ESC     = 0333 /* 0xDB, indicates byte stuffing */
	ESC_END = 0334 /* 0xDC, ESC ESC_END means END data byte */
	ESC_ESC = 0335 /* 0xDD, ESC ESC_ESC means ESC data byte */
)
View Source
const (
	FRAME_IPV4_START = 0x45
	FRAME_IPV4_END   = 0x4f
	FRAME_IPV6_START = 0x60
	FRAME_IPV6_END   = 0x6f
)
View Source
const (
	FRAME_UNKNOWN    = 0x00
	FRAME_DIAGNOSTIC = 0x0a // New Line Character
	FRAME_COAP       = 0xa9
)
View Source
const FCS_GOOD = 0xf0b8
View Source
const FCS_INITIAL = 0xffff

Variables

This section is empty.

Functions

func AppendFcs16

func AppendFcs16(data []byte, fcs uint16) []byte

append the Fcs value to an existing message

func CalcFcs16

func CalcFcs16(data []byte) uint16

func CalcFcs16WithInit

func CalcFcs16WithInit(initialFcs uint16, data []byte) uint16

Takes a already calculated FCS and adds more data on it

func CheckFsc16

func CheckFsc16(dataWithCrc []byte) bool

func IsIpFrame

func IsIpFrame(frame byte) bool

func IsIpv4Frame

func IsIpv4Frame(frame byte) bool

func IsIpv6Frame

func IsIpv6Frame(frame byte) bool

func RemoveFcs16

func RemoveFcs16(dataWithCrc []byte) []byte

Types

type Reader

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

func NewReader

func NewReader(reader io.Reader) *Reader

func (*Reader) ReadPacket

func (s *Reader) ReadPacket() (p []byte, isPrefix bool, err error)

RECV_PACKET: receives a packet into the buffer located at "p". * If more than len bytes are received, the packet will * be truncated. * Returns the number of bytes stored in the buffer.

type SlipMuxReader

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

func NewSlipMuxReader

func NewSlipMuxReader(reader io.Reader) *SlipMuxReader

func (*SlipMuxReader) ReadPacket

func (s *SlipMuxReader) ReadPacket() ([]byte, byte, error)

ReadPacket reads a packet from the stream. Blocks till packet is complete. Returns the packet, the frameType byte and an optional error

The he packet frame is stripped from the returning byte slice. IPv4 and IPv6 frame identifiers are not stripped to keep backwards compatibility with SLIP

type SlipMuxWriter

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

func NewSlipMuxWriter

func NewSlipMuxWriter(writer io.Writer) *SlipMuxWriter

func (*SlipMuxWriter) WritePacket

func (s *SlipMuxWriter) WritePacket(frame byte, p []byte) error

WritePacket writes a SlipMux packet with the given Frame prefix For registered frames see FRAME_* constants. IPV4 and IPV6 frames are not prepended as specified. To not use any Frame identifiers use SlipWriter directly.

type Writer

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

func NewWriter

func NewWriter(writer io.Writer) *Writer

func (*Writer) WritePacket

func (s *Writer) WritePacket(p []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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