codec

package
v0.0.0-...-0379cd4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

README

fesl-codec

FESL Codec is serialization library dedicated for handling exchange of messages between BFHeroes backend and game/server clients.

Data Types

  • string:
key=value
otherKey="value with spaces"
  • integer:
key=123
  • boolean is always represented by an integer value:
truish=1
false=0
  • float is usually represented as 4-digits precision after the decimal point:
foo=1.0000
  • empty values (nil / null):
key=
  • Arrays always adds additonal key (%s.[]) which contains number of declared items (array length).
keys.[]=4
keys.0=foo
keys.1=bar
keys.2=baz
keys.3=qux
  • Maps (dictionaries) uses brackets to define the keys and also uses special key (%s.{}) which contains number of declared items (map capacity).
props.{foo}=0
props.{bar}=baz
props.{}=2
  • Structs:
foo.id=1
foo.bar=baz

Documentation

Index

Constants

View Source
const (
	FeslAccount     = "acct"
	FeslSystem      = "fsys"
	FeslGameSummary = "gsum"
	FeslPlayNow     = "pnow"
	FeslRanking     = "rank"
	FeslAssociation = "asso" // TODO: Not implemented
	FeslBlob        = "blob" // TODO: Not implemented
	FeslFeedback    = "fdbk" // TODO: Not implemented
	FeslFilter      = "fltr" // TODO: Not implemented
	FeslFindPlayer  = "fpla" // TODO: Not implemented
	FeslPresence    = "pres" // TODO: Not implemented
	FeslRecorder    = "recp" // TODO: Not implemented

	ThtrCreateGame           = "CGAM"
	ThtrConnect              = "CONN"
	ThtrEcho                 = "ECHO"
	ThtrEnterGame            = "EGAM"
	ThtrEnterGameEntitleGame = "EGEG"
	ThtrEnterGameRequest     = "EGRQ"
	ThtrEnterGameResponse    = "EGRS"
	ThtrEnterConnectionLost  = "ECNL"
	ThtrGamesData            = "GDAT"
	ThtrGamesList            = "GLST"
	ThtrKickPlayer           = "KICK"
	ThtrLobbyData            = "LDAT"
	ThtrLobbyList            = "LLST"
	ThtrPlayerEnter          = "PENT"
	ThtrPing                 = "PING"
	ThtrPlayerValidator      = "PLVT"
	ThtrUpdateBrokerRating   = "UBRA"
	ThtrUpdatePlayer         = "UPLA"
	ThtrUser                 = "USER"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Type string
	// Destination  [4]byte // DestSingleClient, DestSingleServer...
	PacketNumber uint32
	// PacketHeader
	Payload interface{}
}

type BufWriter

type BufWriter struct {
	// contains filtered or unexported fields
}

func (*BufWriter) Bytes

func (e *BufWriter) Bytes() []byte

func (*BufWriter) Len

func (e *BufWriter) Len() int

func (*BufWriter) WriteByte

func (e *BufWriter) WriteByte(b byte)

func (*BufWriter) WriteString

func (e *BufWriter) WriteString(s string)

type Command

type Command struct {
	Query     string
	Message   Fields
	PayloadID uint32
}

func NewCommand

func NewCommand(pkt *RawPacket) (*Command, error)

func ParseCommands

func ParseCommands(data []byte) ([]*Command, error)

type EncOptions

type EncOptions struct {
	OmitEmpty bool
}

type EncWriter

type EncWriter interface {
	WriteString(string)
	WriteByte(byte)
	Len() int
	Bytes() []byte
}

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) (err error)

func (*Encoder) EncodePacket

func (e *Encoder) EncodePacket(packet *Answer) (*bytes.Buffer, error)

type Fields

type Fields map[string]string

Fields contains payload of FESL response converted as a go-lang friendly map

func DecodeFESL

func DecodeFESL(data []byte) Fields

func (Fields) ArrayStrings

func (m Fields) ArrayStrings(prefix string) []string

ArrayStrings scraps all items in specified key as a array

func (Fields) Exists

func (m Fields) Exists(key string) bool

Exists checks if specified key was defined

func (Fields) FloatAsInt

func (m Fields) FloatAsInt(key string) (int, int, error)

FloatAsInt attempts to guess precision and cast float as an integer. It allows to take care of floating point math inaccuracy (0.1+0.2 != 0.3)

func (Fields) FloatVal

func (m Fields) FloatVal(key string) (float64, error)

FloatVal tries to cast specified value as a float

func (Fields) Get

func (m Fields) Get(key string) string

Get returns string value Note: String() in somehow reserved in golang (like toString() in C#)

func (Fields) IntArr

func (m Fields) IntArr(key, sep string) []int

IntArr explodes an encoded array which is separated by commas

func (Fields) IntVal

func (m Fields) IntVal(key string) (int, error)

IntVal tries to cast specified value as an integer

func (Fields) StrArr

func (m Fields) StrArr(key, sep string) []string

StrArr explodes an encoded array which is separated by semicolons

type RawPacket

type RawPacket struct {
	// Query first 4 bytes
	// i.e. "fsys", "acct" "CONN", "UPLA"
	Query []byte

	// Broadcast, next 4 bytes
	// TOOD: Use enumerator
	Broadcast []byte

	// Length, next 4 bytes
	Length []byte

	// Payload
	Payload []byte
}

func ExtractPacket

func ExtractPacket(buf *bytes.Buffer) (*RawPacket, error)

Jump to

Keyboard shortcuts

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