Documentation
¶
Overview ¶
Package sfs implements encoding and decoding of SmartFoxServer 2X binary protocol data.
The package handles SFSObject and SFSArray structures, which are the primary serialization format used by SmartFoxServer for data exchange between clients and servers over WebSocket connections.
Index ¶
- Variables
- func Encode(obj *Object) ([]byte, error)
- func EncodeArray(arr *Array) ([]byte, error)
- func EncodeFrame(f *Frame) ([]byte, error)
- func Format(v Value) string
- func FormatObject(obj *Object) string
- type Array
- func (a *Array) Add(v Value)
- func (a *Array) AddBool(v bool)
- func (a *Array) AddBoolArray(v []bool)
- func (a *Array) AddByte(v int8)
- func (a *Array) AddByteArray(v []byte)
- func (a *Array) AddDouble(v float64)
- func (a *Array) AddDoubleArray(v []float64)
- func (a *Array) AddFloat(v float32)
- func (a *Array) AddFloatArray(v []float32)
- func (a *Array) AddInt(v int32)
- func (a *Array) AddIntArray(v []int32)
- func (a *Array) AddLong(v int64)
- func (a *Array) AddLongArray(v []int64)
- func (a *Array) AddNull()
- func (a *Array) AddSFSArray(v *Array)
- func (a *Array) AddSFSObject(v *Object)
- func (a *Array) AddShort(v int16)
- func (a *Array) AddShortArray(v []int16)
- func (a *Array) AddText(v string)
- func (a *Array) AddUtfString(v string)
- func (a *Array) AddUtfStringArray(v []string)
- func (a *Array) ForEach(fn func(i int, val Value) bool)
- func (a *Array) Get(i int) Value
- func (a *Array) GetBool(i int) (bool, error)
- func (a *Array) GetBoolArray(i int) ([]bool, error)
- func (a *Array) GetByte(i int) (int8, error)
- func (a *Array) GetByteArray(i int) ([]byte, error)
- func (a *Array) GetDouble(i int) (float64, error)
- func (a *Array) GetDoubleArray(i int) ([]float64, error)
- func (a *Array) GetFloat(i int) (float32, error)
- func (a *Array) GetFloatArray(i int) ([]float32, error)
- func (a *Array) GetInt(i int) (int32, error)
- func (a *Array) GetIntArray(i int) ([]int32, error)
- func (a *Array) GetLong(i int) (int64, error)
- func (a *Array) GetLongArray(i int) ([]int64, error)
- func (a *Array) GetSFSArray(i int) (*Array, error)
- func (a *Array) GetSFSObject(i int) (*Object, error)
- func (a *Array) GetShort(i int) (int16, error)
- func (a *Array) GetShortArray(i int) ([]int16, error)
- func (a *Array) GetText(i int) (string, error)
- func (a *Array) GetUtfString(i int) (string, error)
- func (a *Array) GetUtfStringArray(i int) ([]string, error)
- func (a *Array) IsNull(i int) bool
- func (a *Array) Len() int
- func (a *Array) RemoveAt(i int) error
- func (a *Array) Size() int
- type Frame
- type Object
- func (o *Object) ContainsKey(key string) bool
- func (o *Object) ForEach(fn func(key string, val Value) bool)
- func (o *Object) Get(key string) (Value, bool)
- func (o *Object) GetBool(key string) (bool, error)
- func (o *Object) GetBoolArray(key string) ([]bool, error)
- func (o *Object) GetByte(key string) (int8, error)
- func (o *Object) GetByteArray(key string) ([]byte, error)
- func (o *Object) GetDouble(key string) (float64, error)
- func (o *Object) GetDoubleArray(key string) ([]float64, error)
- func (o *Object) GetFloat(key string) (float32, error)
- func (o *Object) GetFloatArray(key string) ([]float32, error)
- func (o *Object) GetInt(key string) (int32, error)
- func (o *Object) GetIntArray(key string) ([]int32, error)
- func (o *Object) GetLong(key string) (int64, error)
- func (o *Object) GetLongArray(key string) ([]int64, error)
- func (o *Object) GetSFSArray(key string) (*Array, error)
- func (o *Object) GetSFSObject(key string) (*Object, error)
- func (o *Object) GetShort(key string) (int16, error)
- func (o *Object) GetShortArray(key string) ([]int16, error)
- func (o *Object) GetText(key string) (string, error)
- func (o *Object) GetUtfString(key string) (string, error)
- func (o *Object) GetUtfStringArray(key string) ([]string, error)
- func (o *Object) IsNull(key string) bool
- func (o *Object) Keys() []string
- func (o *Object) Len() int
- func (o *Object) Put(key string, v Value)
- func (o *Object) PutBool(key string, v bool)
- func (o *Object) PutBoolArray(key string, v []bool)
- func (o *Object) PutByte(key string, v int8)
- func (o *Object) PutByteArray(key string, v []byte)
- func (o *Object) PutDouble(key string, v float64)
- func (o *Object) PutDoubleArray(key string, v []float64)
- func (o *Object) PutFloat(key string, v float32)
- func (o *Object) PutFloatArray(key string, v []float32)
- func (o *Object) PutInt(key string, v int32)
- func (o *Object) PutIntArray(key string, v []int32)
- func (o *Object) PutLong(key string, v int64)
- func (o *Object) PutLongArray(key string, v []int64)
- func (o *Object) PutNull(key string)
- func (o *Object) PutSFSArray(key string, v *Array)
- func (o *Object) PutSFSObject(key string, v *Object)
- func (o *Object) PutShort(key string, v int16)
- func (o *Object) PutShortArray(key string, v []int16)
- func (o *Object) PutText(key string, v string)
- func (o *Object) PutUtfString(key string, v string)
- func (o *Object) PutUtfStringArray(key string, v []string)
- func (o *Object) RemoveElement(key string)
- func (o *Object) Size() int
- type TypeID
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound is returned when a requested key is not present in the object. ErrKeyNotFound = errors.New("sfs: key not found") // ErrTypeMismatch is returned when a value is not of the expected type. ErrTypeMismatch = errors.New("sfs: type mismatch") // ErrIndexOutOfBounds is returned when an index is outside the range of the array. ErrIndexOutOfBounds = errors.New("sfs: index out of bounds") )
var ErrShortData = errors.New("sfs: short data")
ErrShortData indicates the input data is shorter than expected.
Functions ¶
func EncodeArray ¶
EncodeArray serializes an Array into SFS binary format.
func EncodeFrame ¶
EncodeFrame serializes a Frame into wire bytes. If f.Compressed is true, the payload is zlib-compressed.
func Format ¶
Format renders a Value as a human-readable indented string, similar to the decoded WebSocket traces used in protocol analysis.
func FormatObject ¶
FormatObject renders an Object as a human-readable indented string.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array is an ordered list of Values.
func DecodeArray ¶
DecodeArray reads an SFSArray from binary data.
func (*Array) AddBoolArray ¶
AddBoolArray appends a boolean array to the array.
func (*Array) AddByteArray ¶
AddByteArray appends a byte array to the array.
func (*Array) AddDoubleArray ¶
AddDoubleArray appends a double array to the array.
func (*Array) AddFloatArray ¶
AddFloatArray appends a float array to the array.
func (*Array) AddIntArray ¶
AddIntArray appends an int array to the array.
func (*Array) AddLongArray ¶
AddLongArray appends a long array to the array.
func (*Array) AddSFSArray ¶
AddSFSArray appends a nested SFSArray to the array.
func (*Array) AddSFSObject ¶
AddSFSObject appends a nested SFSObject to the array.
func (*Array) AddShortArray ¶
AddShortArray appends a short array to the array.
func (*Array) AddUtfString ¶
AddUtfString appends a UTF-8 string value to the array.
func (*Array) AddUtfStringArray ¶
AddUtfStringArray appends a string array to the array.
func (*Array) GetBoolArray ¶
GetBoolArray retrieves a boolean array at the given index.
func (*Array) GetByteArray ¶
GetByteArray retrieves a byte array at the given index.
func (*Array) GetDoubleArray ¶
GetDoubleArray retrieves a double array at the given index.
func (*Array) GetFloatArray ¶
GetFloatArray retrieves a float array at the given index.
func (*Array) GetIntArray ¶
GetIntArray retrieves an int array at the given index.
func (*Array) GetLongArray ¶
GetLongArray retrieves a long array at the given index.
func (*Array) GetSFSArray ¶
GetSFSArray retrieves a nested SFSArray at the given index.
func (*Array) GetSFSObject ¶
GetSFSObject retrieves a nested SFSObject at the given index.
func (*Array) GetShortArray ¶
GetShortArray retrieves a short array at the given index.
func (*Array) GetUtfString ¶
GetUtfString retrieves a UTF-8 string value at the given index.
func (*Array) GetUtfStringArray ¶
GetUtfStringArray retrieves a string array at the given index.
type Frame ¶
Frame represents a SmartFoxServer WebSocket frame. The wire format is:
[1 byte: flags] [2 bytes: payload length (big-endian)] [N bytes: payload (optionally zlib-compressed SFSObject)]
func DecodeFrame ¶
DecodeFrame reads a full SFS WebSocket frame from raw bytes.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is an ordered map of string keys to Values. It preserves insertion order, matching the SFS wire format.
func Decode ¶
Decode reads an SFSObject from binary data. The data must start at the beginning of an SFSObject encoding (i.e., the 2-byte entry count).
func (*Object) ContainsKey ¶
ContainsKey returns true if the key exists in the object.
func (*Object) ForEach ¶
ForEach calls fn for each key-value pair in insertion order. If fn returns false, iteration stops.
func (*Object) GetBoolArray ¶
GetBoolArray retrieves a boolean array for the given key.
func (*Object) GetByteArray ¶
GetByteArray retrieves a byte array for the given key.
func (*Object) GetDoubleArray ¶
GetDoubleArray retrieves a double array for the given key.
func (*Object) GetFloatArray ¶
GetFloatArray retrieves a float array for the given key.
func (*Object) GetIntArray ¶
GetIntArray retrieves an int array for the given key.
func (*Object) GetLongArray ¶
GetLongArray retrieves a long array for the given key.
func (*Object) GetSFSArray ¶
GetSFSArray retrieves a nested SFSArray for the given key.
func (*Object) GetSFSObject ¶
GetSFSObject retrieves a nested SFSObject for the given key.
func (*Object) GetShortArray ¶
GetShortArray retrieves a short array for the given key.
func (*Object) GetUtfString ¶
GetUtfString retrieves a UTF-8 string value for the given key.
func (*Object) GetUtfStringArray ¶
GetUtfStringArray retrieves a string array for the given key.
func (*Object) PutBoolArray ¶
PutBoolArray inserts a boolean array for the given key.
func (*Object) PutByteArray ¶
PutByteArray inserts a byte array for the given key.
func (*Object) PutDoubleArray ¶
PutDoubleArray inserts a double array for the given key.
func (*Object) PutFloatArray ¶
PutFloatArray inserts a float array for the given key.
func (*Object) PutIntArray ¶
PutIntArray inserts an int array for the given key.
func (*Object) PutLongArray ¶
PutLongArray inserts a long array for the given key.
func (*Object) PutSFSArray ¶
PutSFSArray inserts a nested SFSArray for the given key.
func (*Object) PutSFSObject ¶
PutSFSObject inserts a nested SFSObject for the given key.
func (*Object) PutShortArray ¶
PutShortArray inserts a short array for the given key.
func (*Object) PutUtfString ¶
PutUtfString inserts a UTF-8 string value for the given key.
func (*Object) PutUtfStringArray ¶
PutUtfStringArray inserts a string array for the given key.
func (*Object) RemoveElement ¶
RemoveElement removes the entry with the given key from the object. If the key does not exist, it does nothing.
type TypeID ¶
type TypeID byte
TypeID identifies the data type of a value in the SFS binary protocol.
const ( TypeNull TypeID = 0 TypeBool TypeID = 1 TypeByte TypeID = 2 TypeShort TypeID = 3 TypeInt TypeID = 4 TypeLong TypeID = 5 TypeFloat TypeID = 6 TypeDouble TypeID = 7 TypeUTFString TypeID = 8 TypeBoolArray TypeID = 9 TypeByteArray TypeID = 10 TypeShortArray TypeID = 11 TypeIntArray TypeID = 12 TypeLongArray TypeID = 13 TypeFloatArray TypeID = 14 TypeDoubleArray TypeID = 15 TypeStringArray TypeID = 16 TypeSFSArray TypeID = 17 TypeSFSObject TypeID = 18 TypeText TypeID = 19 )