message: github.com/dist-ribut-us/message Index | Files

package message

import "github.com/dist-ribut-us/message"

Package message provides a common messaging header for IPC and Network communication. The body of the message can be used to hold raw data or can hold a marshalled protobuf.

Package message is a generated protocol buffer package.

It is generated from these files:

message/message.proto

It has these top-level messages:

Header
Addrpb

Index

Package Files

doc.go header.go message.pb.go

Constants

const (
    QueryFlag = BitFlag(1 << (iota))
    ResponseFlag
    FromNet
    ToNet
)

Flag masks Flags field

const (
    Undefined = Type(iota)
    GetPort
    GetIP
    RegisterService
    Test
    Ping
    NetSend
    NetReceive
    AddBeacon
    GetPubKey
    Die
    SessionData
    StaticKey
    RandomKey
)

Types for messages

const (
    BeaconService uint32 = 19860714
    PoolService   uint32 = 1111111111
)

Services

const ServiceTypeOffset = 1024

ServiceTypeOffset claims the first 1024 values are reserved, after that, values are specific to the service handling them.

type Addrpb Uses

type Addrpb struct {
    Ip   []byte `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
    Port uint32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
    Zone string `protobuf:"bytes,3,opt,name=zone" json:"zone,omitempty"`
}

func FromAddr Uses

func FromAddr(addr *rnet.Addr) *Addrpb

FromAddr creates and Addrpb from an rnet.Addr

func UnmarshalAddrpb Uses

func UnmarshalAddrpb(buf []byte) *Addrpb

UnmarshalAddrpb unmarshals a buffer to an Addrpb. If there is an error it is logged and a nil value is returned.

func (*Addrpb) Descriptor Uses

func (*Addrpb) Descriptor() ([]byte, []int)

func (*Addrpb) GetAddr Uses

func (a *Addrpb) GetAddr() *rnet.Addr

GetAddr returns the Addrpb as an rnet.Addr

func (*Addrpb) GetIp Uses

func (m *Addrpb) GetIp() []byte

func (*Addrpb) GetPort Uses

func (m *Addrpb) GetPort() uint32

func (*Addrpb) GetZone Uses

func (m *Addrpb) GetZone() string

func (*Addrpb) Marshal Uses

func (a *Addrpb) Marshal() []byte

Marshal a header to a buffer. If there is an error it is logged and nil is returned.

func (*Addrpb) ProtoMessage Uses

func (*Addrpb) ProtoMessage()

func (*Addrpb) Reset Uses

func (m *Addrpb) Reset()

func (*Addrpb) String Uses

func (m *Addrpb) String() string

type BitFlag Uses

type BitFlag uint32

BitFlag is used to set flags on the header flag field

type Header struct {
    Type32  uint32  `protobuf:"varint,1,opt,name=type32" json:"type32,omitempty"`
    Service uint32  `protobuf:"varint,2,opt,name=service" json:"service,omitempty"`
    Flags   uint32  `protobuf:"varint,3,opt,name=flags" json:"flags,omitempty"`
    Body    []byte  `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
    Id      uint32  `protobuf:"varint,5,opt,name=id" json:"id,omitempty"`
    NodeID  []byte  `protobuf:"bytes,6,opt,name=nodeID,proto3" json:"nodeID,omitempty"`
    Addrpb  *Addrpb `protobuf:"bytes,7,opt,name=Addrpb" json:"Addrpb,omitempty"`
}

func NewHeader Uses

func NewHeader(t Type, body interface{}) *Header

NewHeader takes a type and a body. See SetBody for valid body types

func Unmarshal Uses

func Unmarshal(buf []byte) *Header

Unmarshal a buffer to a header. If there is an error it is logged and a nil value is returned.

func (*Header) BodyString Uses

func (h *Header) BodyString() string

BodyString returns the body as a string

func (*Header) BodyToUint32 Uses

func (h *Header) BodyToUint32() uint32

BodyToUint32 uses dist.ribut.us/serial to Unmarshal the body.

func (*Header) CheckFlag Uses

func (h *Header) CheckFlag(flag BitFlag) bool

CheckFlag checks if a bit flag is set

func (*Header) Descriptor Uses

func (*Header) Descriptor() ([]byte, []int)

func (*Header) GetAddr Uses

func (h *Header) GetAddr() *rnet.Addr

GetAddr returns the Addrpb as an rnet.Addr

func (*Header) GetAddrpb Uses

func (m *Header) GetAddrpb() *Addrpb

func (*Header) GetBody Uses

func (m *Header) GetBody() []byte

func (*Header) GetFlags Uses

func (m *Header) GetFlags() uint32

func (*Header) GetId Uses

func (m *Header) GetId() uint32

func (*Header) GetNodeID Uses

func (m *Header) GetNodeID() []byte

func (*Header) GetService Uses

func (m *Header) GetService() uint32

func (*Header) GetType Uses

func (h *Header) GetType() Type

GetType returns the Type

func (*Header) GetType32 Uses

func (m *Header) GetType32() uint32

func (*Header) IsFromNet Uses

func (h *Header) IsFromNet() bool

IsFromNet checks if the FromNet flag is set

func (*Header) IsQuery Uses

func (h *Header) IsQuery() bool

IsQuery checks if the underlying type is a query

func (*Header) IsResponse Uses

func (h *Header) IsResponse() bool

IsResponse checks if the underlying type is a query

func (*Header) IsToNet Uses

func (h *Header) IsToNet() bool

IsToNet checks if the FromNet flag is set

func (*Header) Marshal Uses

func (h *Header) Marshal() []byte

Marshal a header to a buffer. If there is an error it is logged and nil is returned.

func (*Header) ProtoMessage Uses

func (*Header) ProtoMessage()

func (*Header) Reset Uses

func (m *Header) Reset()

func (*Header) SetAddr Uses

func (h *Header) SetAddr(addr *rnet.Addr) *Header

SetAddr sets the underlying Addrpb struct in the Header

func (*Header) SetBody Uses

func (h *Header) SetBody(body interface{}) *Header

SetBody takes various types and tries to set the Body field. If body is nil, that will set the body to nil. If body is a []byte, that will be set on the body. If it is a string, it will be cast to []byte. If the body is a proto.Message it will be marshalled and the serialized data will be used. If it is a uint32, dist.ribut.us/serial will be used to marshal the value into body.

func (*Header) SetFlag Uses

func (h *Header) SetFlag(flag BitFlag)

SetFlag sets a bit in the flag field

func (*Header) SetType Uses

func (h *Header) SetType(t Type)

SetType sets the Type

func (*Header) String Uses

func (m *Header) String() string

func (*Header) Unmarshal Uses

func (h *Header) Unmarshal(pb proto.Message) error

Unmarshal the body of the header

func (*Header) UnsetFlag Uses

func (h *Header) UnsetFlag(flag BitFlag)

UnsetFlag removes a flag

type Type Uses

type Type uint32

Type for message header

Package message imports 7 packages (graph) and is imported by 4 packages. Updated 2018-08-08. Refresh now. Tools for package owners.