binio

package module
v0.0.0-...-87245cf Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2019 License: MIT Imports: 2 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

About

A package to write structured data to a bytes buffer, which is a technique commonly used in games where text-based protocols such as xml or json carry too much bulk to efficiently transfer data over the wire. The package is similar to Google's protocol buffers in that it is meant to be language agnostic with its intended function, but cuts out the overhead of using protocol buffers and compiling templates for each type.

Installation

go get -u github.com/Zeroeh/binio

Usage

Refer to example/example.go for usage and examples.

Notes

The package was originally developed to be used for a specific game. You may have to change some of the functions to suit your individual needs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Packet

type Packet struct {
	Index  int
	Length int //the len() of Data. Must be explicitly set
	Data   []byte
}

Packet is a struct containing an underlying bytes buffer

func (*Packet) ReadBool

func (p *Packet) ReadBool() bool

func (*Packet) ReadByte

func (p *Packet) ReadByte() byte

ReadByte reads and returns a singular byte

func (*Packet) ReadBytes

func (p *Packet) ReadBytes(amount int) []byte

ReadBytes is experimental and has not been tested

func (*Packet) ReadFloat

func (p *Packet) ReadFloat() float32

ReadFloat reads 4 bytes representing a float

func (*Packet) ReadInt16

func (p *Packet) ReadInt16() int16

func (*Packet) ReadInt32

func (p *Packet) ReadInt32() int32

func (*Packet) ReadInt64

func (p *Packet) ReadInt64() int64

func (*Packet) ReadString

func (p *Packet) ReadString() string

ReadString reads the expected string size (n) and read until n

func (*Packet) ReadUInt16

func (p *Packet) ReadUInt16() uint16

func (*Packet) ReadUInt32

func (p *Packet) ReadUInt32() uint32

func (*Packet) ReadUInt64

func (p *Packet) ReadUInt64() uint64

func (*Packet) ResizeBuffer

func (p *Packet) ResizeBuffer(size, keep, index int)

ResizeBuffer resizes our packet data to the specified size Feel free to customize this function, as it can be tailored to many individual needs

size: the new size of the bytes buffer
keep: the number of bytes to keep in the new buffer. Default: 0
index: the index to start from in the old byte buffer. Default: 0

func (*Packet) WriteBool

func (p *Packet) WriteBool(b bool)

func (*Packet) WriteByte

func (p *Packet) WriteByte(d byte)

WriteByte writes a singular byte to the packet buffer

func (*Packet) WriteFloat

func (p *Packet) WriteFloat(f float32)

WriteFloat writes 4 bytes representing a float

func (*Packet) WriteInt16

func (p *Packet) WriteInt16(i int16)

func (*Packet) WriteInt32

func (p *Packet) WriteInt32(i int32)

func (*Packet) WriteInt64

func (p *Packet) WriteInt64(i int64)

func (*Packet) WriteString

func (p *Packet) WriteString(s string)

WriteString writes int16 (len of string) and then the contents of s as bytes

func (*Packet) WriteUInt16

func (p *Packet) WriteUInt16(i uint16)

func (*Packet) WriteUInt32

func (p *Packet) WriteUInt32(i uint32)

func (*Packet) WriteUInt64

func (p *Packet) WriteUInt64(i uint64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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