Documentation ¶
Overview ¶
Package kv implements encoding and decoding of Valve's KeyValue format.
Index ¶
- type BinaryDecoder
- type BinaryEncoder
- type KeyValue
- func NewKeyValue(t Type, key, value string, parent KeyValue) KeyValue
- func NewKeyValueColor(key, value string, parent KeyValue) KeyValue
- func NewKeyValueEmpty() KeyValue
- func NewKeyValueFloat32(key, value string, parent KeyValue) KeyValue
- func NewKeyValueInt32(key, value string, parent KeyValue) KeyValue
- func NewKeyValueInt64(key, value string, parent KeyValue) KeyValue
- func NewKeyValueObject(key string, parent KeyValue) KeyValue
- func NewKeyValuePointer(key, value string, parent KeyValue) KeyValue
- func NewKeyValueRoot(key string) KeyValue
- func NewKeyValueString(key, value string, parent KeyValue) KeyValue
- func NewKeyValueUint64(key, value string, parent KeyValue) KeyValue
- type TextDecoder
- type TextEncoder
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryDecoder ¶
type BinaryDecoder struct {
// contains filtered or unexported fields
}
BinaryDecoder reads and decodes binary-encoded KeyValue nodes from an input stream.
func NewBinaryDecoder ¶
func NewBinaryDecoder(r io.Reader) *BinaryDecoder
NewBinaryDecoder returns a new binary decoder that reads from r.
func (*BinaryDecoder) Decode ¶
func (d *BinaryDecoder) Decode(kv KeyValue) error
Decode reads the next binary-encoded KeyValue node from its input and stores it in the value pointed to by kv.
type BinaryEncoder ¶
type BinaryEncoder struct {
// contains filtered or unexported fields
}
BinaryEncoder writes binary-encoded KeyValue nodes to an output stream.
func NewBinaryEncoder ¶
func NewBinaryEncoder(w io.Writer) *BinaryEncoder
NewBinaryEncoder returns a new binary encoder that writes to w.
func (*BinaryEncoder) Encode ¶
func (e *BinaryEncoder) Encode(kv KeyValue) error
Encode writes the KeyValue binary encoding of kv to the stream.
type KeyValue ¶
type KeyValue interface { // Type returns the node's Type. Type() Type // SetType sets the node's Type and returns the receiver. SetType(Type) KeyValue // Key returns the node's Key. Key() string // SetKey sets the node's Key and returns the receiver. SetKey(key string) KeyValue // Value returns the node's Value. Value() string // AsString returns Value as string if Type is TypeString, otherwise returns an error. AsString() (string, error) // AsInt32 returns Value as int32 if Type is TypeInt32, otherwise returns an error. AsInt32() (int32, error) // AsInt64 returns Value as int64 if Type is TypeInt64, otherwise returns an error. AsInt64() (int64, error) // AsUint64 returns Value as uint64 if Type is TypeUint64, otherwise returns an error. AsUint64() (uint64, error) // AsFloat32 returns Value as float32 if Type is TypeFloat32, otherwise returns an error. AsFloat32() (float32, error) // AsColor returns Value as int32 if Type is TypeColor, otherwise returns an error. AsColor() (int32, error) // AsPointer returns Value as int32 if Type is TypePointer, otherwise returns an error. AsPointer() (int32, error) // SetValue sets the node's Value and returns the receiver. SetValue(value string) KeyValue // SetString sets Value to given string value if Type is TypeString, otherwise returns an error. SetString(string) error // SetInt32 sets Value to given int32 value if Type is TypeInt32, otherwise returns an error. SetInt32(int32) error // SetInt64 sets Value to given int64 value if Type is TypeInt64, otherwise returns an error. SetInt64(int64) error // SetUint64 sets Value to given uint64 value if Type is TypeUint64, otherwise returns an error. SetUint64(uint64) error // SetFloat32 sets Value to given float32 value if Type is TypeFloat32, otherwise returns an error. SetFloat32(float32) error // SetColor sets Value to given int32 value if Type is TypeColor, otherwise returns an error. SetColor(int32) error // SetPointer sets Value to given int32 value if Type is TypePointer, otherwise returns an error. SetPointer(int32) error // Parent returns the parent node. Parent() KeyValue // SetParent sets the node's parent node and returns the receiver. SetParent(KeyValue) KeyValue // Children returns all child nodes Children() []KeyValue // SetChildren sets the node's children and returns the receiver. SetChildren(...KeyValue) KeyValue // Child finds a child node with the given key. Child(key string) KeyValue // NewChild creates an empty child node and returns the child node. NewChild() KeyValue // AddChild adds a child node and returns the receiver. AddChild(KeyValue) KeyValue // AddObject adds an Object child node and returns the receiver. AddObject(key string) KeyValue // AddString adds a String child node and returns the receiver. AddString(key, value string) KeyValue // AddInt32 adds an Int32 child node and returns the receiver. AddInt32(key, value string) KeyValue // AddInt64 adds an Int64 child node and returns the receiver. AddInt64(key, value string) KeyValue // AddUint64 adds an Uint64 child node and returns the receiver. AddUint64(key, value string) KeyValue // AddFloat32 adds a Float32 child node and returns the receiver. AddFloat32(key, value string) KeyValue // AddColor adds a Color child node and returns the receiver. AddColor(key, value string) KeyValue // AddPointer adds a Pointer child node and returns the receiver. AddPointer(key, value string) KeyValue encoding.BinaryMarshaler encoding.BinaryUnmarshaler encoding.TextMarshaler encoding.TextUnmarshaler }
KeyValue represents a node in a KeyValue tree.
func NewKeyValue ¶
NewKeyValue creates a KeyValue node.
func NewKeyValueColor ¶
NewKeyValueColor creates a KeyValue node with TypeColor type.
func NewKeyValueEmpty ¶
func NewKeyValueEmpty() KeyValue
NewKeyValueEmpty creates an empty KeyValue node.
func NewKeyValueFloat32 ¶
NewKeyValueFloat32 creates a KeyValue node with TypeFloat32 type.
func NewKeyValueInt32 ¶
NewKeyValueInt32 creates a KeyValue node with TypeInt32 type.
func NewKeyValueInt64 ¶
NewKeyValueInt64 creates a KeyValue node with TypeInt64 type.
func NewKeyValueObject ¶
NewKeyValueObject creates a KeyValue node with TypeObject type.
func NewKeyValuePointer ¶
NewKeyValuePointer creates a KeyValue node with TypePointer type.
func NewKeyValueRoot ¶
NewKeyValueRoot creates a root KeyValue node.
func NewKeyValueString ¶
NewKeyValueString creates a KeyValue node with TypeString type.
func NewKeyValueUint64 ¶
NewKeyValueUint64 creates a KeyValue node with TypeUint64 type.
type TextDecoder ¶
type TextDecoder struct {
// contains filtered or unexported fields
}
TextDecoder reads and decodes text-encoded KeyValue nodes from an input stream.
func NewTextDecoder ¶
func NewTextDecoder(r io.Reader) *TextDecoder
NewTextDecoder returns a new text decoder that reads from r.
func (*TextDecoder) Decode ¶
func (d *TextDecoder) Decode(kv KeyValue) error
Decode reads the next text-encoded KeyValue node from its input and stores it in the value pointed to by kv.
The parser makes no assumptions regarding field types, so all fields are of type TypeString.
type TextEncoder ¶
type TextEncoder struct {
// contains filtered or unexported fields
}
TextEncoder writes text-encoded KeyValue nodes to an output stream.
func NewTextEncoder ¶
func NewTextEncoder(w io.Writer) *TextEncoder
NewTextEncoder returns a new text encoder that writes to w.
func (*TextEncoder) Encode ¶
func (e *TextEncoder) Encode(kv KeyValue) error
Encode writes the KeyValue text encoding of kv to the stream.
type Type ¶
type Type int8
Type represents a KeyValue's node type.
const ( TypeInvalid Type = iota - 1 // -1 TypeObject // 0x00 TypeString // 0x01 TypeInt32 // 0x02 TypeFloat32 // 0x03 TypePointer // 0x04 TypeWString // 0x05 TypeColor // 0x06 TypeUint64 // 0x07 TypeEnd // 0x08 TypeInt64 // 0x0a )
KeyValue types.
func TypeFromByte ¶
TypeFromByte converts a byte from binary format to a Type.
Returns TypeInvalid if the given byte is not a valid Type.