lob

package
v0.0.0-...-c0ffc74 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2015 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package lob implemnets the Length-Object-Binary encoding (Packet Format).

Reference

https://github.com/telehash/telehash.org/blob/v3/v3/lob/README.md

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPacket = errors.New("lob: invalid packet")

ErrInvalidPacket is returned by Decode

Functions

func Encode

func Encode(pkt *Packet) (*bufpool.Buffer, error)

Encode a packet

Types

type Header struct {
	Bytes []byte `json:"-"`

	C       uint32   `json:"c,omitempty"`
	Type    string   `json:"type,omitempty"`
	End     bool     `json:"end,omitempty"`
	Seq     uint32   `json:"seq,omitempty"`
	Ack     uint32   `json:"ack,omitempty"`
	Miss    []uint32 `json:"miss,omitempty"`
	HasC    bool     `json:"-"`
	HasType bool     `json:"-"`
	HasEnd  bool     `json:"-"`
	HasSeq  bool     `json:"-"`
	HasAck  bool     `json:"-"`
	HasMiss bool     `json:"-"`

	Extra map[string]interface{} `json:"extra,omitempty"`
}

Header represents a packet header.

func (*Header) Get

func (h *Header) Get(k string) (v interface{}, found bool)

Get the value for key k. found is false if k is not present.

func (*Header) GetBool

func (h *Header) GetBool(k string) (v bool, found bool)

GetBool returns the bool value for key k. found is false if k is not present.

func (*Header) GetInt

func (h *Header) GetInt(k string) (v int, found bool)

GetInt returns the int value for key k. found is false if k is not present.

func (*Header) GetString

func (h *Header) GetString(k string) (v string, found bool)

GetString returns the string value for key k. found is false if k is not present.

func (*Header) GetUint32

func (h *Header) GetUint32(k string) (v uint32, found bool)

GetUint32 returns the uint32 value for key k. found is false if k is not present.

func (*Header) GetUint32Slice

func (h *Header) GetUint32Slice(k string) (v []uint32, found bool)

GetUint32Slice returns the []uint32 value for key k. found is false if k is not present.

func (*Header) IsBinary

func (h *Header) IsBinary() bool

func (*Header) IsZero

func (h *Header) IsZero() bool

IsZero returns true when the header is the zero value or equivalent.

func (*Header) Set

func (h *Header) Set(k string, v interface{})

Set a the header k to v.

func (*Header) SetBool

func (h *Header) SetBool(k string, v bool)

SetBool a the header k to v.

func (*Header) SetInt

func (h *Header) SetInt(k string, v int)

SetInt a the header k to v.

func (*Header) SetString

func (h *Header) SetString(k string, v string)

SetString a the header k to v.

func (*Header) SetUint32

func (h *Header) SetUint32(k string, v uint32)

SetUint32 a the header k to v.

func (*Header) SetUint32Slice

func (h *Header) SetUint32Slice(k string, v []uint32)

SetUint32Slice a the header k to v.

type Packet

type Packet struct {
	TID tracer.ID
	// contains filtered or unexported fields
}

Packet represents a packet.

func Decode

func Decode(p *bufpool.Buffer) (*Packet, error)

Decode a packet

func New

func New(body []byte) *Packet

func (*Packet) Body

func (p *Packet) Body(buf []byte) []byte

func (*Packet) BodyLen

func (p *Packet) BodyLen() int

func (*Packet) Free

func (p *Packet) Free()

Free the packets backing buffer back to the buffer pool.

func (*Packet) GoString

func (p *Packet) GoString() string

func (*Packet) Header

func (p *Packet) Header() *Header

Header returns the packet JSON header if present.

func (*Packet) SetHeader

func (p *Packet) SetHeader(header Header) *Packet

func (*Packet) String

func (p *Packet) String() string

Jump to

Keyboard shortcuts

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