Documentation
¶
Index ¶
- Constants
- Variables
- type Connector
- type Flag
- func (f *Flag) Add(n Flag)
- func (f *Flag) ClearFrag()
- func (f Flag) FragGroup() uint16
- func (f Flag) FragLen() int
- func (f Flag) FragPosition() uint16
- func (f Flag) FragTotal() uint16
- func (f Flag) MarshalStream(w data.Writer) error
- func (f *Flag) SetFragGroup(n uint16)
- func (f *Flag) SetFragPosition(n uint16)
- func (f *Flag) SetFragTotal(n uint16)
- func (f Flag) String() string
- func (f *Flag) UnmarshalStream(r data.Reader) error
- type PPacket
- type Packet
- func (p *Packet) Bool() (bool, error)
- func (p *Packet) Bytes() ([]byte, error)
- func (p *Packet) Check(i device.ID) bool
- func (p *Packet) Clear()
- func (p *Packet) Close() error
- func (p *Packet) Combine(o *Packet) error
- func (p *Packet) Float32() (float32, error)
- func (p *Packet) Float64() (float64, error)
- func (Packet) Flush() error
- func (p *Packet) Grow(n int) error
- func (p *Packet) Int() (int, error)
- func (p *Packet) Int8() (int8, error)
- func (p *Packet) Int16() (int16, error)
- func (p *Packet) Int32() (int32, error)
- func (p *Packet) Int64() (int64, error)
- func (p *Packet) IsEmpty() bool
- func (p Packet) Len() int
- func (p *Packet) MarshalJSON() ([]byte, error)
- func (p *Packet) MarshalStream(w data.Writer) error
- func (p *Packet) Payload() []byte
- func (p *Packet) Read(b []byte) (int, error)
- func (p *Packet) ReadBool(i *bool) error
- func (p *Packet) ReadFloat32(i *float32) error
- func (p *Packet) ReadFloat64(i *float64) error
- func (p *Packet) ReadInt(i *int) error
- func (p *Packet) ReadInt8(i *int8) error
- func (p *Packet) ReadInt16(i *int16) error
- func (p *Packet) ReadInt32(i *int32) error
- func (p *Packet) ReadInt64(i *int64) error
- func (p *Packet) ReadString(i *string) error
- func (p *Packet) ReadUint(i *uint) error
- func (p *Packet) ReadUint8(i *uint8) error
- func (p *Packet) ReadUint16(i *uint16) error
- func (p *Packet) ReadUint32(i *uint32) error
- func (p *Packet) ReadUint64(i *uint64) error
- func (p *Packet) Reset()
- func (p *Packet) Size() int
- func (p *Packet) String() string
- func (p *Packet) StringVal() (string, error)
- func (p *Packet) Uint() (uint, error)
- func (p *Packet) Uint8() (uint8, error)
- func (p *Packet) Uint16() (uint16, error)
- func (p *Packet) Uint32() (uint32, error)
- func (p *Packet) Uint64() (uint64, error)
- func (p *Packet) UnmarshalJSON(b []byte) error
- func (p *Packet) UnmarshalStream(r data.Reader) error
- func (p *Packet) Write(b []byte) (int, error)
- func (p *Packet) WriteBool(n bool) error
- func (p *Packet) WriteBytes(b []byte) error
- func (p *Packet) WriteFloat32(n float32) error
- func (p *Packet) WriteFloat64(n float64) error
- func (p *Packet) WriteInt(n int) error
- func (p *Packet) WriteInt8(n int8) error
- func (p *Packet) WriteInt16(n int16) error
- func (p *Packet) WriteInt32(n int32) error
- func (p *Packet) WriteInt64(n int64) error
- func (p *Packet) WriteString(n string) error
- func (p *Packet) WriteUint(n uint) error
- func (p *Packet) WriteUint8(n uint8) error
- func (p *Packet) WriteUint16(n uint16) error
- func (p *Packet) WriteUint32(n uint32) error
- func (p *Packet) WriteUint64(n uint64) error
- type Provider
- type SPacket
- type Server
- type Stream
- func (s *Stream) Add(p *Packet) error
- func (s *Stream) Clear()
- func (s *Stream) Close() error
- func (s *Stream) Consolidate() *Packet
- func (s *Stream) Flush() error
- func (s Stream) Len() int
- func (s Stream) Less(i, j int) bool
- func (s *Stream) New() *Packet
- func (s *Stream) Read(b []byte) (int, error)
- func (s *Stream) Size() int
- func (s *Stream) Swap(i, j int)
- func (s *Stream) Write(b []byte) (int, error)
- func (s *Stream) WriteAll(w writer) error
- func (s *Stream) WriteBool(n bool) error
- func (s *Stream) WriteBytes(b []byte) error
- func (s *Stream) WriteFloat32(n float32) error
- func (s *Stream) WriteFloat64(n float64) error
- func (s *Stream) WriteInt(n int) error
- func (s *Stream) WriteInt8(n int8) error
- func (s *Stream) WriteInt16(n int16) error
- func (s *Stream) WriteInt32(n int32) error
- func (s *Stream) WriteInt64(n int64) error
- func (s *Stream) WriteString(n string) error
- func (s *Stream) WriteUint(n uint) error
- func (s *Stream) WriteUint8(n uint8) error
- func (s *Stream) WriteUint16(n uint16) error
- func (s *Stream) WriteUint32(n uint32) error
- func (s *Stream) WriteUint64(n uint64) error
- func (s *Stream) Writer(w writer) error
Constants ¶
const (
// PacketHeaderSize is the length of the Packet header in bytes.
PacketHeaderSize = 44
)
Variables ¶
var ( // ErrTooLarge is raised if memory cannot be allocated to store data in a buffer. ErrTooLarge = errors.New("buffer size is too large") // ErrInvalidIndex is raised if a specified Grow or index function is supplied with an // negative or out of bounds number. ErrInvalidIndex = errors.New("buffer index provided is not valid") // ErrMismatchedID is an error that occurs when attempting to combine a Packet with a Packet that does // not match the ID of the parent Packet. ErrMismatchedID = errors.New("packet ID does not match combining packet ID") )
var ( // ErrWriterAttached is an error returned by the Read function // when a Packet Writer is not nil. When a Writer is attached, the Stream // is considered a 'write-only' stream. ErrWriterAttached = errors.New("cannot read while a Packet Writer is attached") // ErrAlreadyAttached is an error returned by the Writer function. This // error is only returned if a Packet Writer is already attached. ErrAlreadyAttached = errors.New("a Packet Writer is already attached") )
var ( // ErrInvalidNetwork is an error returned from the NewStreamConnector function // when a non-stream network is used, or the NewChunkConnector function when a stream // network is used. ErrInvalidNetwork = errors.New("invalid network type") )
Functions ¶
This section is empty.
Types ¶
type Connector ¶
Connector is an interface that passes methods that can be used to form connections between the client and server. Other functions include the process of listening and accepting connections.
type Flag ¶
type Flag uint64
Flag is a bitwise integer that represents important information about the packet that its assigned to.
Mapping 64 56 48 40 32 24 16 8 0
| 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | | Frag Total | Frag Position | Frag Group ID | Flags | | Frag Data | |
const ( // FlagData is a flag used to indicate that Hello/Echo/Sleep packets // also include additional data to be read. FlagData Flag = 1 << iota // FlagFrag is a flag used to indicate that the packet is part of a // fragment group (PacketGroup) and the server should re-assemble the packet // before preforming actions on it. FlagFrag // FlagMulti is a flag used to indicate that the packet is a container // for multiple packets, auto addded by a processing agent. FlagMulti // FlagProxy is a flag used to indicate that the packet was sent from another client // acting as a forwarding proxy. FlagProxy // FlagError is a flag used to indicate that the packet indicates that an error // condition has occurred. The contents of the Packet can be used to understand the error cause. FlagError // FlagIgnore is used to signal to the server or client that this Packet should be dropped and // not processed. Can be used for connectivity checks. FlagIgnore // FlagOneshot is used to signal that the Packet contains information and should not be used to // create or re-establish a session. FlagOneshot // FlagMultiDevice is used to determine if the Multi packet contains Packets with separate device IDs. // This is used to speed up processing and allows packets that are all destined for the same host to be // batch processed. FlagMultiDevice )
func (*Flag) ClearFrag ¶
func (f *Flag) ClearFrag()
ClearFrag clears all Frag and Multi related flags and data.
func (Flag) FragLen ¶
FragLen is similar to the Total function. This returns the total amount of fragmentented packets to expect.
func (Flag) FragPosition ¶
FragPosition represents position of this packet in a fragment group.
func (Flag) FragTotal ¶
FragTotal returns the count of fragmented packets that make up this fragment group.
func (Flag) MarshalStream ¶
MarshalStream writes the data of this Flag to the supplied Writer.
func (*Flag) SetFragGroup ¶
SetFragGroup sets the group ID of the fragment group this packet is part of.
func (*Flag) SetFragPosition ¶
SetFragPosition sets the position this packet is located in the fragment group.
func (*Flag) SetFragTotal ¶
SetFragTotal sets the total count of packets in the fragment group.
type PPacket ¶
type PPacket interface {
Reset()
Clear()
Len() int
Size() int
ID() uint16
Job() uint16
Flags() Flag
IsEmpty() bool
String() string
Payload() []byte
Device() device.ID
MarshalJSON() ([]byte, error)
UnmarshalJSON(b []byte) error
MarshalStream(data.Writer) error
UnmarshalStream(data.Reader) error
data.Writer
data.Reader
io.Closer
}
PPacket is a work in progress interface for a method to combine packets and streams into single
type Packet ¶
type Packet struct {
ID, Job uint16
Flags Flag
Device device.ID
// contains filtered or unexported fields
}
Packet is a struct that is a Reader and Writer that can be generated to be sent, or received from a Connection.
func NewStream ¶
NewStream converts a Packet into a Packet Stream and sets the underlying buffer to a Packet Stream.
func (*Packet) Check ¶
Check is a function that will set any missing Job or device parameters. This function will return true if the Device is nil or matches the specified host ID, false if otherwise.
func (*Packet) Clear ¶
func (p *Packet) Clear()
Clear is similar to Reset, but discards the buffer, which must be allocated again. If using the buffer the Reset function is preferable.
func (*Packet) Close ¶
Close will truncate the writing stream if this Packet has been written to. This will allow the packet payload to be uniform to the data written to it.
func (*Packet) Combine ¶
Combine attempts to append the Payload of the supplied Packet to this Packet's current buffer. Combine fails with the 'ErrMismatchedID' if the ID values are not the same. This function keeps the original Flag, ID and Job values of the parent Packet.
func (*Packet) Grow ¶
Grow grows the payload buffer's capacity, if necessary, to guarantee space for another n bytes.
func (*Packet) IsEmpty ¶
IsEmpty returns true if this packet is nil or does not have any value or data associated with it.
func (*Packet) MarshalJSON ¶
MarshalJSON writes the data of this Packet into JSON format.
func (*Packet) MarshalStream ¶
MarshalStream writes the data of this Packet to the supplied Writer.
func (*Packet) Payload ¶
Payload returns a slice of length p.Len() holding the unread portion of the Packet payload buffer.
func (*Packet) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read.
func (*Packet) ReadBool ¶
ReadBool reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadFloat32 ¶
ReadFloat32 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadFloat64 ¶
ReadFloat64 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadInt ¶
ReadInt reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadInt8 ¶
ReadInt8 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadInt16 ¶
ReadInt16 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadInt32 ¶
ReadInt32 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadInt64 ¶
ReadInt64 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadString ¶
ReadString reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadUint ¶
ReadUint reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadUint8 ¶
ReadUint8 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadUint16 ¶
ReadUint16 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadUint32 ¶
ReadUint32 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) ReadUint64 ¶
ReadUint64 reads the value from the Packet payload buffer into the provided pointer.
func (*Packet) Reset ¶
func (p *Packet) Reset()
Reset resets the payload buffer to be empty, but it retains the underlying storage for use by future writes.
func (*Packet) String ¶
String returns the contents of the unread portion of the buffer as a string.
func (*Packet) UnmarshalJSON ¶
UnmarshalJSON read the data of this Packet from JSON format.
func (*Packet) UnmarshalStream ¶
UnmarshalStream reads the data of this Packet from the supplied Reader.
func (*Packet) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed. If the buffer becomes too large, Write will return ErrTooLarge.
func (*Packet) WriteBytes ¶
WriteBytes writes the supplied value to the Packet payload buffer.
func (*Packet) WriteFloat32 ¶
WriteFloat32 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteFloat64 ¶
WriteFloat64 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteInt16 ¶
WriteInt16 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteInt32 ¶
WriteInt32 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteInt64 ¶
WriteInt64 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteString ¶
WriteString writes the supplied value to the Packet payload buffer.
func (*Packet) WriteUint8 ¶
WriteUint8 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteUint16 ¶
WriteUint16 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteUint32 ¶
WriteUint32 writes the supplied value to the Packet payload buffer.
func (*Packet) WriteUint64 ¶
WriteUint64 writes the supplied value to the Packet payload buffer.
type Provider ¶
Provider is a combined interface that inherits the Server and Connector interfaces. This allows a single struct to provide listening and connection capabilities.
type Server ¶
Server is an interface that is used to Listen on a specific protocol for client connections. The Listener does not take any actions on the clients but transcribes the data into bytes for the Session handler.
type Stream ¶
type Stream struct {
ID, Job uint16
Max int
Flags Flag
Device device.ID
// contains filtered or unexported fields
}
Stream is a struct that can be used to write and fragment large Packets transparently. This struct can be used to write-on-demand the Packet buffer if a Packet Writer is supplied via the Writer function.
func (*Stream) Add ¶
Add adds the supplied Packet to the stream array. This function triggers a sort of the array to ensure the Frags are in the correct position.
func (*Stream) Clear ¶
func (s *Stream) Clear()
Clear discards the underlying buffers, which must be regenerated again.
func (*Stream) Close ¶
Close fulfills the io.Closer interface and will commit all the packets to the assigned Packet Writer (if not nil) and will set the correct position and total Packet Flags.
func (*Stream) Consolidate ¶
Consolidate combines the data in the underling Packet array into a single Packet.
func (*Stream) Flush ¶
Flush will push out any Packets to the underlying Packet Writer (if not nil).
func (Stream) Less ¶
Less returns true if the Frag Position of the Packet is less than the other supplied Packet position.
func (*Stream) New ¶
New creates a new Packet to be added to the underlying Stream. This packet will inherit the ID, Job and Flags of the Parent stream.
func (*Stream) Read ¶
Read fulfills the io.Reader interface. This function will return ErrWriterAttached if a Packet Writer is attached.
func (*Stream) Write ¶
Write fulfills the io.Writer interface. This will generate and allocate new Packets on the fly. This will also send Packets out, if a Packet Session Writer is set.
func (*Stream) WriteAll ¶
WriteAll attempts to flush all the underlying Packets to the provided writer.
func (*Stream) WriteBytes ¶
WriteBytes writes the supplied value to the Stream payload buffer.
func (*Stream) WriteFloat32 ¶
WriteFloat32 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteFloat64 ¶
WriteFloat64 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteInt16 ¶
WriteInt16 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteInt32 ¶
WriteInt32 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteInt64 ¶
WriteInt64 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteString ¶
WriteString writes the supplied value to the Stream payload buffer.
func (*Stream) WriteUint8 ¶
WriteUint8 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteUint16 ¶
WriteUint16 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteUint32 ¶
WriteUint32 writes the supplied value to the Stream payload buffer.
func (*Stream) WriteUint64 ¶
WriteUint64 writes the supplied value to the Stream payload buffer.