Documentation ¶
Overview ¶
Package packet provides network messaging protocol and serialization layer.
Packet can be created with shortcut:
senderAddr, _ := host.NewAddress("127.0.0.1:1337") receiverAddr, _ := host.NewAddress("127.0.0.1:1338") sender := host.NewHost(senderAddr) receiver := host.NewHost(receiverAddr) msg := packet.NewPingPacket(sender, receiver) // do something with packet
Or with builder:
builder := packet.NewBuilder() senderAddr, _ := host.NewAddress("127.0.0.1:1337") receiverAddr, _ := host.NewAddress("127.0.0.1:1338") sender := host.NewHost(senderAddr) receiver := host.NewHost(receiverAddr) msg := builder. Sender(sender). Receiver(receiver). Type(packet.TypeFindHost). Request(&packet.RequestDataFindHost{}). Build() // do something with packet
Packet may be serialized:
msg := &packet.Packet{} serialized, err := packet.SerializePacket(msg) if err != nil { panic(err.Error()) } fmt.Println(serialized)
And deserialized therefore:
var buffer bytes.Buffer // Fill buffer somewhere msg, err := packet.DeserializePacket(buffer) if err != nil { panic(err.Error()) } // do something with packet
Index ¶
- Constants
- func SerializePacket(q *Packet) ([]byte, error)
- type Builder
- func (cb Builder) Build() (packet *Packet)
- func (cb Builder) Error(err error) Builder
- func (cb Builder) Receiver(host *host.Host) Builder
- func (cb Builder) Request(request interface{}) Builder
- func (cb Builder) Response(response interface{}) Builder
- func (cb Builder) Type(packetType types.PacketType) Builder
- type Packet
- type RequestGetRandomHosts
- type RequestID
- type RequestPulse
- type RequestTest
- type ResponseGetRandomHosts
- type ResponsePulse
- type ResponseTest
Constants ¶
const (
TestPacket = types.PacketType(1337)
)
Variables ¶
This section is empty.
Functions ¶
func SerializePacket ¶
SerializePacket converts packet to byte slice.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder allows lazy building of packets. Each operation returns new copy of a builder.
func NewBuilder ¶
NewBuilder returns empty packet builder.
type Packet ¶
type Packet struct { Sender *host.Host Receiver *host.Host Type types.PacketType RequestID RequestID RemoteAddress string Data interface{} Error error IsResponse bool }
Packet is DHT packet object.
type RequestGetRandomHosts ¶
type RequestGetRandomHosts struct {
HostsNumber int
}
RequestGetRandomHosts is data for the call that returns random hosts of the Insolar network.
type RequestPulse ¶
RequestPulse is data received from a pulsar.
type RequestTest ¶ added in v0.6.3
type RequestTest struct {
Data []byte
}
type ResponseGetRandomHosts ¶
ResponseGetRandomHosts is the response containing random hosts of the Insolar network.
type ResponsePulse ¶
ResponsePulse is the response for a new pulse from a pulsar.
type ResponseTest ¶ added in v0.6.3
type ResponseTest struct {
Number int
}