protocols

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// STypeArc arc type
	STypeArc byte = 10

	// ItemSampleRate  -
	ItemSampleRate = 1
)
View Source
const DefaultHeadLength = 8

DefaultHeadLength head + size

View Source
const LengthWithoutData uint32 = 17

LengthWithoutData ... Timestamp + ID + Crc + End

Variables

View Source
var (
	//Head ...
	Head = []byte{0xFC, 0xFC, 0xFC, 0xFC}

	//End ...
	End uint8 = 0xFD

	// MaxSize -
	MaxSize uint32 = 1024 * 6
)

Functions

func ArcSegmentValidate added in v1.0.6

func ArcSegmentValidate(srcData []byte) error

ArcSegmentValidate - validation

func ConfigFrame

func ConfigFrame(maxSize uint32) error

ConfigFrame -

func FrameValidate

func FrameValidate(srcData []byte) error

FrameValidate - 包格式检查

Types

type ArcItem added in v1.0.6

type ArcItem struct {
	Ts   int64
	Data []byte
}

ArcItem is the ArcItem at a time point

type ArcItemArray added in v1.0.6

type ArcItemArray struct {
	CollectorID   []byte
	CollectorType string
	Items         []ArcItem
}

ArcItemArray is an array of arc item

type ArcItemRaw added in v1.0.6

type ArcItemRaw struct {
	CollectorID   []byte
	CollectorType string
	Ts            int64
	Data          []byte
}

ArcItemRaw include raw data of ArcItem value

type Coder

type Coder struct {
	IsCrcCheck bool
}

Coder -

func (*Coder) Decode

func (coder *Coder) Decode(c gnet.Conn) ([]byte, error)

Decode decodes frames from TCP stream via specific implementation.

func (*Coder) Encode

func (coder *Coder) Encode(c gnet.Conn, buf []byte) ([]byte, error)

Encode encodes frames upon server responses into TCP stream.

type CountItem

type CountItem struct {
	CollectorID   []byte
	CollectorType string
	Ts            int64
	Count         int
	Size          int
}

CountItem contains count of messages from collector

type DataGroup

type DataGroup struct {
	Count    byte       //1 segment count
	Sizes    []uint32   //4 each segment size
	STypes   []byte     // segment type
	Segments []ISegment //n data
}

DataGroup Protocol=2 CType 1:GetCollector2Structure.Size()

func NewDefaultDataGroup

func NewDefaultDataGroup() *DataGroup

NewDefaultDataGroup -

func (*DataGroup) AppendSegment

func (d *DataGroup) AppendSegment(segment ISegment)

AppendSegment - AppendSegment

func (*DataGroup) Decode

func (d *DataGroup) Decode(data []byte) error

Decode - Decode

func (*DataGroup) Dump

func (d *DataGroup) Dump()

Dump -

func (*DataGroup) Encode

func (d *DataGroup) Encode(buf []byte) (int, error)

Encode - encode

func (*DataGroup) GetArcSegment added in v1.0.6

func (d *DataGroup) GetArcSegment() (*SegmentArc, error)

GetArcSegment - GetArcSegment

func (*DataGroup) GetSegment

func (d *DataGroup) GetSegment(SType byte) (ISegment, error)

GetSegment - GetSegment

func (*DataGroup) Validate

func (d *DataGroup) Validate() error

Validate - Validate

type Frame

type Frame struct {
	Head      [4]byte   //4 Head 0xFC 0xFC 0xFC 0xFC
	Size      uint32    //4 Package size  [Timestamp, End] = 17+n BigEndian
	Timestamp int64     //8 timestamp ms BigEndian
	ID        [6]byte   //6 machin id (Mac Address)
	DataGroup DataGroup //n data
	Crc       uint16    //2 crc [Timestamp, Data], CRC-16 BigEndian
	End       byte      //1 End 0xFD
}

Frame package size 25+n

func NewDefaultFrame

func NewDefaultFrame() *Frame

NewDefaultFrame -

func (*Frame) Decode

func (f *Frame) Decode(srcData []byte) error

Decode 当前流中读取字节

func (*Frame) Dump

func (f *Frame) Dump()

Dump -

func (*Frame) Encode

func (f *Frame) Encode(buf []byte) (int, error)

Encode 字节数组写入当前流, 直接对buf操作

func (*Frame) GetID

func (f *Frame) GetID() uint64

GetID - get ID

func (*Frame) SetDataGroup

func (f *Frame) SetDataGroup(dg *DataGroup) *Frame

SetDataGroup -

func (*Frame) SetID

func (f *Frame) SetID(id uint64) *Frame

SetID - set machin id for simulate client

type IProto

type IProto interface {
	Encode([]byte) (int, error)
}

IProto -

type ISegment

type ISegment interface {
	Encode([]byte) (int, error)
	Type() byte
	Size() uint32
	Dump()
}

ISegment -

type SegmentArc added in v1.0.6

type SegmentArc struct {
	SType byte //1 segment type
	Data  []byte
}

SegmentArc arc

func NewDefaultSegmentArc added in v1.0.6

func NewDefaultSegmentArc() *SegmentArc

NewDefaultSegmentArc -

func (*SegmentArc) Decode added in v1.0.6

func (s *SegmentArc) Decode(srcData []byte) error

Decode - decode

func (*SegmentArc) Dump added in v1.0.6

func (s *SegmentArc) Dump()

Dump -

func (*SegmentArc) Encode added in v1.0.6

func (s *SegmentArc) Encode(buf []byte) (int, error)

Encode - encode

func (*SegmentArc) GetData added in v1.0.6

func (s *SegmentArc) GetData() []byte

GetData - get data

func (*SegmentArc) GetType added in v1.0.6

func (s *SegmentArc) GetType() byte

GetType - get type

func (*SegmentArc) SetData added in v1.0.6

func (s *SegmentArc) SetData(data []byte)

SetData - set data

func (*SegmentArc) Size added in v1.0.6

func (s *SegmentArc) Size() uint32

Size - encode size

func (*SegmentArc) Type added in v1.0.6

func (s *SegmentArc) Type() byte

Type - segment type

func (*SegmentArc) Validate added in v1.0.6

func (s *SegmentArc) Validate() error

Validate -

Jump to

Keyboard shortcuts

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