message

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package message implements basic types and functionality to handle messages on the Container-Lab's LAN. Basic package except for general utils from package typeconv.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressBytes

type AddressBytes []byte

AddressBytes - the source for Address struct.

func UDPAddrToBytes

func UDPAddrToBytes(addrStrct net.UDPAddr) AddressBytes

UDPAddrToBytes - method of Address struct; cast it to a slice of bytes. Port is represented as UInt16, big endian.

func (AddressBytes) ToAddress

func (b AddressBytes) ToAddress() (result net.UDPAddr)

ToAddress - cast AddressBytes (4 bytes IP + 2 bytes port) to Address struct.

type Bytes

type Bytes []byte

Bytes - the source for Message struct.

func (Bytes) ToMessage

func (msg Bytes) ToMessage() (Message, bool)

ToMessage - parse message bytes to a message struct.

func (Bytes) Validate

func (msg Bytes) Validate(sendAddr net.UDPAddr, recvAddr net.UDPAddr) (Bytes, error)

Validate checks if message contains sender - receiver signature and cuts stuff that doesn't belong to the message.

type Message

type Message struct {
	SendAddr  net.UDPAddr // who sent
	RecvAddr  net.UDPAddr // who received
	PackLen   uint16
	Timestamp time.Time // the moment the message was sent
	MsgType   uint8     // 0 status set, 1 status is, 2 ambient params, 3 measured data
	Data      []byte
	Checksum  uint32 // Adler32 or CRC32
}

Message - a struct to hold all the information of a UDP message.

func New

func New() *Message

New returns the pointer to a new message struct with MsgType set to an undefined value

func ParseOldCarMsg

func ParseOldCarMsg(Bytes []byte) (*Message, error)

ParseOldCarMsg takes old CARIBIC format message and parses it to new Message type. Msg typ must be determined from content (status tag vs. something else)

func (*Message) MakeOldCarMsg

func (msgStrct *Message) MakeOldCarMsg() ([]byte, error)

MakeOldCarMsg makes old CARIBIC format message from Message only applicable to status set messages

func (*Message) String

func (msgStrct *Message) String() string

String a method to print a readable representation of the message struct.

func (*Message) ToBytes

func (msgStrct *Message) ToBytes() Bytes

ToBytes - method of Message; cast it to a slice of bytes. Numbers in big endian byte order.

Jump to

Keyboard shortcuts

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