message

package
v0.0.0-...-f10b52b Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// random select one pipe to send
	SendTypeToOne uint8 = iota & sendTypeMask
	// send to all pipes
	SendTypeToAll
	// send to a destination
	SendTypeToDest
)

send types, low 2bits

View Source
const (
	// socket internal message, used by socket internal
	MsgFlagInternal uint8 = 1 << (iota + 2)
	// TODO:
	// MsgFlagNoSource, do not record message source
	MsgFlagNoSource
	// MsgFlagRaw is used to indicate the message is from a raw transport
	MsgFlagRaw
	// protocol control message, predefined flag, use by protocols implementations or others.
	MsgFlagControl
)

Msg Flags

View Source
const DefaultMsgTTL = uint8(16)

DefaultMsgTTL is default msg ttl

View Source
const (
	// close peer
	InternalMsgClosePeer uint8 = iota
)

TODO: Internal Messages

View Source
const MetaSize = 8

MetaSize is the Meta data's memory byte size. TODO: update when Meta modifed

Variables

This section is empty.

Functions

This section is empty.

Types

type FreeLevel

type FreeLevel int

FreeLevel defines how to free messages

const (
	// FreeAll free all
	FreeAll FreeLevel = iota
	// FreeMsg free msg
	FreeMsg
	// FreeNone free nothing
	FreeNone
)

msg free levels

type InternalMsg

type InternalMsg struct {
	Type uint8
}

InternalMsg internal message content structure.

type Message

type Message struct {
	Meta
	Source      MsgPath
	Destination MsgPath
	// TODO: support zero copy content
	Content []byte
	// contains filtered or unexported fields
}

Message is a message

func NewMessageFromBytes

func NewMessageFromBytes(pid uint32, buf []byte, maxLength uint32) (msg *Message, err error)

NewMessageFromBytes create a message from bytes

func NewMessageFromMsg

func NewMessageFromMsg(pid uint32, srcMsg *Message, maxLength uint32) (msg *Message, err error)

NewMessageFromMsg create a message from message

func NewMessageFromReader

func NewMessageFromReader(pid uint32, r io.ReadCloser, metaBuf []byte, maxLength uint32) (msg *Message, err error)

NewMessageFromReader create a message from reader

func NewRawRecvMessage

func NewRawRecvMessage(pid uint32, content []byte) (msg *Message)

NewRawRecvMessage create a new raw recv message

func NewSendMessage

func NewSendMessage(flags, sendType uint8, ttl uint8, src, dest MsgPath, content []byte) *Message

NewSendMessage create a message to send

func (*Message) Dup

func (msg *Message) Dup() (dup *Message)

Dup create a duplicated message TODO: try effective way, like reference counting.

func (*Message) Encode

func (msg *Message) Encode() []byte

Encode encode msg'b body parts.

func (*Message) Free

func (msg *Message) Free()

Free put msg to pool

func (*Message) FreeAll

func (msg *Message) FreeAll()

FreeAll put buf and msg to pools

func (*Message) FreeByLevel

func (msg *Message) FreeByLevel(level FreeLevel)

FreeByLevel free message by level

func (*Message) PipeID

func (msg *Message) PipeID() uint32

PipeID get this message's source pipe id.

type Meta

type Meta struct {
	// Flags
	Flags    uint8  // 6:other flags|2:send type to/one,all,dest
	TTL      uint8  // time to live
	Hops     uint8  // node count from origin
	Distance uint8  // node count to destination
	Length   uint32 // content length
}

Meta message's meta data

func (*Meta) ClearFlags

func (m *Meta) ClearFlags(flags uint8) uint8

ClearFlags clear flags

func (*Meta) HasAnyFlags

func (m *Meta) HasAnyFlags() bool

HasAnyFlags check if meta data has any flags setted.

func (*Meta) HasFlags

func (m *Meta) HasFlags(flags uint8) bool

HasFlags check if meta data has flags setted.

func (*Meta) SendType

func (m *Meta) SendType() uint8

SendType get message's send type

type MsgPath

type MsgPath []byte

MsgPath is message's path composed of pipe ids(uint32) traceback.

func (MsgPath) CurID

func (path MsgPath) CurID() uint32

CurID get source's current pipe id.

func (MsgPath) Length

func (path MsgPath) Length() uint8

Length get Path length

func (MsgPath) NextID

func (path MsgPath) NextID() (id uint32, source MsgPath)

NextID get source's next pipe id and remain source.

Jump to

Keyboard shortcuts

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