Documentation ¶
Index ¶
- Variables
- type Attribute
- type BinValue
- type BoolValue
- type Encoding
- type Node
- func (n *Node) AppendChild(c *Node) error
- func (n *Node) ArrayLength() int
- func (n *Node) AttributeValue(k string) string
- func (n *Node) AttributeValueNodeName(k *NodeName) string
- func (n *Node) Attributes() []*Attribute
- func (n *Node) BinaryValue() BinValue
- func (n *Node) ChildValue(name string) any
- func (n *Node) ChildValueNodeName(name *NodeName) any
- func (n *Node) Children() []*Node
- func (n *Node) IntValue() int64
- func (n *Node) IsArray() bool
- func (n *Node) Name() *NodeName
- func (n *Node) NewNode(name string) (*Node, error)
- func (n *Node) NewNodeWithValue(name string, value any) (*Node, error)
- func (n *Node) Parent() *Node
- func (n *Node) SearchAttribute(k string) *Attribute
- func (n *Node) SearchAttributeNodeName(k *NodeName) *Attribute
- func (n *Node) SearchChild(name string) *Node
- func (n *Node) SearchChildNodeName(name *NodeName) *Node
- func (n *Node) SearchChildren(name string) []*Node
- func (n *Node) SearchChildrenNodeName(name *NodeName) []*Node
- func (n *Node) SetAttribute(k, v string) error
- func (n *Node) SetValue(v any) error
- func (n Node) ShallowCopy() *Node
- func (n *Node) StringValue() string
- func (n *Node) Traverse(start, end func(*Node) error) error
- func (n *Node) Type() *NodeType
- func (n *Node) UintValue() uint64
- func (n *Node) Value() any
- type NodeName
- type NodeType
- type Property
- type PropertyFormat
- type PropertySettings
- type TimeValue
Constants ¶
This section is empty.
Variables ¶
var ( EncodingNone = &Encoding{ name: "", charset: nil, } EncodingASCII = &Encoding{ codepage: 1, name: "ASCII", charset: nil, } EncodingLatin1 = &Encoding{ codepage: 2, name: "ISO-8859-1", charset: charmap.ISO8859_1, } EncodingEUCJP = &Encoding{ codepage: 3, name: "EUC-JP", charset: japanese.EUCJP, } EncodingSJIS = &Encoding{ codepage: 4, name: "SHIFT_JIS", charset: japanese.ShiftJIS, } EncodingUTF8 = &Encoding{ codepage: 5, name: "UTF-8", charset: nil, } )
var ( VoidNode = &NodeType{ typeVoid, []string{"void"}, -1, -1, nil, nil, nil, nil, } S8Node = &NodeType{ 2, []string{"s8"}, 1, 1, reflect.TypeOf(int8(0)), int8BytesToValue, int8ValueToBytes, intStringToValue[int8], } U8Node = &NodeType{ 3, []string{"u8"}, 1, 1, reflect.TypeOf(uint8(0)), uint8BytesToValue, uint8ValueToBytes, uintStringToValue[uint8], } S16Node = &NodeType{ 4, []string{"s16"}, 2, 1, reflect.TypeOf(int16(0)), int16BytesToValue, int16ValueToBytes, intStringToValue[int16], } U16Node = &NodeType{ 5, []string{"u16"}, 2, 1, reflect.TypeOf(uint16(0)), uint16BytesToValue, uint16ValueToBytes, uintStringToValue[uint16], } S32Node = &NodeType{ 6, []string{"s32"}, 4, 1, reflect.TypeOf(int32(0)), int32BytesToValue, int32ValueToBytes, intStringToValue[int32], } U32Node = &NodeType{ 7, []string{"u32"}, 4, 1, reflect.TypeOf(uint32(0)), uint32BytesToValue, uint32ValueToBytes, uintStringToValue[uint32], } S64Node = &NodeType{ 8, []string{"s64"}, 8, 1, reflect.TypeOf(int64(0)), int64BytesToValue, int64ValueToBytes, intStringToValue[int64], } U64Node = &NodeType{ 9, []string{"u64"}, 8, 1, reflect.TypeOf(uint64(0)), uint64BytesToValue, uint64ValueToBytes, uintStringToValue[uint64], } BinNode = &NodeType{ 10, []string{"bin", "binary"}, 1, 1, reflect.TypeOf(BinValue{}), nil, nil, nil, } StrNode = &NodeType{ 11, []string{"str", "string"}, 1, 1, reflect.TypeOf(""), nil, nil, nil, } IPv4Node = &NodeType{ 12, []string{"ip4"}, 4, 1, reflect.TypeOf(net.IP{}), ip4BytesToValue, ip4ValueToBytes, ip4StringToValue, } TimeNode = &NodeType{ 13, []string{"time"}, 4, 1, reflect.TypeOf(TimeValue(0)), timeBytesToValue, timeValueToBytes, uintStringToValue[TimeValue], } FloatNode = &NodeType{ 14, []string{"float", "f"}, 4, 1, reflect.TypeOf(float32(0)), floatBytesToValue, floatValueToBytes, floatStringToValue[float32], } DoubleNode = &NodeType{ 15, []string{"double", "d"}, 8, 1, reflect.TypeOf(float64(0)), doubleBytesToValue, doubleValueToBytes, floatStringToValue[float64], } Vec2S8Node = &NodeType{ 16, []string{"2s8"}, 2, 2, reflect.TypeOf([2]int8{}), vectorBytesToValue[[2]any](1, int8BytesToValue), vectorValueToBytes(1, int8ValueToBytes), vectorStringToValue[[2]any](intStringToValue[int8]), } Vec2U8Node = &NodeType{ 17, []string{"2u8"}, 2, 2, reflect.TypeOf([2]uint8{}), vectorBytesToValue[[2]any](1, uint8BytesToValue), vectorValueToBytes(1, uint8ValueToBytes), vectorStringToValue[[2]any](uintStringToValue[uint8]), } Vec2S16Node = &NodeType{ 18, []string{"2s16"}, 4, 2, reflect.TypeOf([2]int16{}), vectorBytesToValue[[2]any](2, int16BytesToValue), vectorValueToBytes(2, int16ValueToBytes), vectorStringToValue[[2]any](intStringToValue[int16]), } Vec2U16Node = &NodeType{ 19, []string{"2u16"}, 4, 2, reflect.TypeOf([2]uint16{}), vectorBytesToValue[[2]any](2, uint16BytesToValue), vectorValueToBytes(2, uint16ValueToBytes), vectorStringToValue[[2]any](uintStringToValue[uint16]), } Vec2S32Node = &NodeType{ 20, []string{"2s32"}, 8, 2, reflect.TypeOf([2]int32{}), vectorBytesToValue[[2]any](4, int32BytesToValue), vectorValueToBytes(4, int32ValueToBytes), vectorStringToValue[[2]any](intStringToValue[int32]), } Vec2U32Node = &NodeType{ 21, []string{"2u32"}, 8, 2, reflect.TypeOf([2]uint32{}), vectorBytesToValue[[2]any](4, uint32BytesToValue), vectorValueToBytes(4, uint32ValueToBytes), vectorStringToValue[[2]any](uintStringToValue[uint32]), } Vec2S64Node = &NodeType{ 22, []string{"vs64", "2s64"}, 16, 2, reflect.TypeOf([2]int64{}), vectorBytesToValue[[2]any](8, int64BytesToValue), vectorValueToBytes(8, int64ValueToBytes), vectorStringToValue[[2]any](intStringToValue[int64]), } Vec2U64Node = &NodeType{ 23, []string{"vu64", "2u64"}, 16, 2, reflect.TypeOf([2]uint64{}), vectorBytesToValue[[2]any](8, uint64BytesToValue), vectorValueToBytes(8, uint64ValueToBytes), vectorStringToValue[[2]any](uintStringToValue[uint64]), } Vec2FloatNode = &NodeType{ 24, []string{"2f"}, 8, 2, reflect.TypeOf([2]float32{}), vectorBytesToValue[[2]any](4, floatBytesToValue), vectorValueToBytes(4, floatValueToBytes), vectorStringToValue[[2]any](floatStringToValue[float32]), } Vec2DoubleNode = &NodeType{ 25, []string{"vd", "2d"}, 16, 2, reflect.TypeOf([2]float64{}), vectorBytesToValue[[2]any](8, doubleBytesToValue), vectorValueToBytes(8, doubleValueToBytes), vectorStringToValue[[2]any](floatStringToValue[float64]), } Vec3S8Node = &NodeType{ 26, []string{"3s8"}, 3, 3, reflect.TypeOf([3]int8{}), vectorBytesToValue[[3]any](1, int8BytesToValue), vectorValueToBytes(1, int8ValueToBytes), vectorStringToValue[[3]any](intStringToValue[int8]), } Vec3U8Node = &NodeType{ 27, []string{"3u8"}, 3, 3, reflect.TypeOf([3]uint8{}), vectorBytesToValue[[3]any](1, uint8BytesToValue), vectorValueToBytes(1, uint8ValueToBytes), vectorStringToValue[[3]any](uintStringToValue[uint8]), } Vec3S16Node = &NodeType{ 28, []string{"3s16"}, 6, 3, reflect.TypeOf([3]int16{}), vectorBytesToValue[[3]any](2, int16BytesToValue), vectorValueToBytes(2, int16ValueToBytes), vectorStringToValue[[3]any](intStringToValue[int16]), } Vec3U16Node = &NodeType{ 29, []string{"3u16"}, 6, 3, reflect.TypeOf([3]uint16{}), vectorBytesToValue[[3]any](2, uint16BytesToValue), vectorValueToBytes(2, uint16ValueToBytes), vectorStringToValue[[3]any](uintStringToValue[uint16]), } Vec3S32Node = &NodeType{ 30, []string{"3s32"}, 12, 3, reflect.TypeOf([3]int32{}), vectorBytesToValue[[3]any](4, int32BytesToValue), vectorValueToBytes(4, int32ValueToBytes), vectorStringToValue[[3]any](intStringToValue[int32]), } Vec3U32Node = &NodeType{ 31, []string{"3u32"}, 12, 3, reflect.TypeOf([3]uint32{}), vectorBytesToValue[[3]any](4, uint32BytesToValue), vectorValueToBytes(4, uint32ValueToBytes), vectorStringToValue[[3]any](uintStringToValue[uint32]), } Vec3S64Node = &NodeType{ 32, []string{"3s64"}, 24, 3, reflect.TypeOf([3]int64{}), vectorBytesToValue[[3]any](8, int64BytesToValue), vectorValueToBytes(8, int64ValueToBytes), vectorStringToValue[[3]any](intStringToValue[int64]), } Vec3U64Node = &NodeType{ 33, []string{"3u64"}, 24, 3, reflect.TypeOf([3]uint64{}), vectorBytesToValue[[3]any](8, uint64BytesToValue), vectorValueToBytes(8, uint64ValueToBytes), vectorStringToValue[[3]any](uintStringToValue[uint64]), } Vec3FloatNode = &NodeType{ 34, []string{"3f"}, 12, 3, reflect.TypeOf([3]float32{}), vectorBytesToValue[[3]any](4, floatBytesToValue), vectorValueToBytes(4, floatValueToBytes), vectorStringToValue[[3]any](floatStringToValue[float32]), } Vec3DoubleNode = &NodeType{ 35, []string{"3d"}, 24, 3, reflect.TypeOf([3]float64{}), vectorBytesToValue[[3]any](8, doubleBytesToValue), vectorValueToBytes(8, doubleValueToBytes), vectorStringToValue[[3]any](floatStringToValue[float64]), } Vec4S8Node = &NodeType{ 36, []string{"4s8"}, 4, 4, reflect.TypeOf([4]int8{}), vectorBytesToValue[[4]any](1, int8BytesToValue), vectorValueToBytes(1, int8ValueToBytes), vectorStringToValue[[4]any](intStringToValue[int8]), } Vec4U8Node = &NodeType{ 37, []string{"4u8"}, 4, 4, reflect.TypeOf([4]uint8{}), vectorBytesToValue[[4]any](1, uint8BytesToValue), vectorValueToBytes(1, uint8ValueToBytes), vectorStringToValue[[4]any](uintStringToValue[uint8]), } Vec4S16Node = &NodeType{ 38, []string{"4s16"}, 8, 4, reflect.TypeOf([4]int16{}), vectorBytesToValue[[4]any](2, int16BytesToValue), vectorValueToBytes(2, int16ValueToBytes), vectorStringToValue[[4]any](intStringToValue[int16]), } Vec4U16Node = &NodeType{ 39, []string{"4u16"}, 8, 4, reflect.TypeOf([4]uint16{}), vectorBytesToValue[[4]any](2, uint16BytesToValue), vectorValueToBytes(2, uint16ValueToBytes), vectorStringToValue[[4]any](uintStringToValue[uint16]), } Vec4S32Node = &NodeType{ 40, []string{"vs32", "4s32"}, 16, 4, reflect.TypeOf([4]int32{}), vectorBytesToValue[[4]any](4, int32BytesToValue), vectorValueToBytes(4, int32ValueToBytes), vectorStringToValue[[4]any](intStringToValue[int32]), } Vec4U32Node = &NodeType{ 41, []string{"vu32", "4u32"}, 16, 4, reflect.TypeOf([4]uint32{}), vectorBytesToValue[[4]any](4, uint32BytesToValue), vectorValueToBytes(4, uint32ValueToBytes), vectorStringToValue[[4]any](uintStringToValue[uint32]), } Vec4S64Node = &NodeType{ 42, []string{"4s64"}, 32, 4, reflect.TypeOf([4]int64{}), vectorBytesToValue[[4]any](8, int64BytesToValue), vectorValueToBytes(8, int64ValueToBytes), vectorStringToValue[[4]any](intStringToValue[int64]), } Vec4U64Node = &NodeType{ 43, []string{"4u64"}, 32, 4, reflect.TypeOf([4]uint64{}), vectorBytesToValue[[4]any](8, uint64BytesToValue), vectorValueToBytes(8, uint64ValueToBytes), vectorStringToValue[[4]any](uintStringToValue[uint64]), } Vec4FloatNode = &NodeType{ 44, []string{"vf", "4f"}, 16, 4, reflect.TypeOf([4]float32{}), vectorBytesToValue[[4]any](4, floatBytesToValue), vectorValueToBytes(4, floatValueToBytes), vectorStringToValue[[4]any](floatStringToValue[float32]), } Vec4DoubleNode = &NodeType{ 45, []string{"4d"}, 32, 4, reflect.TypeOf([4]float64{}), vectorBytesToValue[[4]any](8, doubleBytesToValue), vectorValueToBytes(8, doubleValueToBytes), vectorStringToValue[[4]any](floatStringToValue[float64]), } Vec16S8Node = &NodeType{ 48, []string{"vs8", "16s8"}, 16, 16, reflect.TypeOf([16]int8{}), vectorBytesToValue[[16]any](1, int8BytesToValue), vectorValueToBytes(1, int8ValueToBytes), vectorStringToValue[[16]any](intStringToValue[int8]), } Vec16U8Node = &NodeType{ 49, []string{"vu8", "16s8"}, 16, 16, reflect.TypeOf([16]uint8{}), vectorBytesToValue[[16]any](1, uint8BytesToValue), vectorValueToBytes(1, uint8ValueToBytes), vectorStringToValue[[16]any](uintStringToValue[uint8]), } Vec8S16Node = &NodeType{ 50, []string{"vs16", "8s16"}, 16, 8, reflect.TypeOf([8]int16{}), vectorBytesToValue[[8]any](2, int16BytesToValue), vectorValueToBytes(2, int16ValueToBytes), vectorStringToValue[[8]any](intStringToValue[int16]), } Vec8U16Node = &NodeType{ 51, []string{"vu16", "8u16"}, 16, 8, reflect.TypeOf([8]uint16{}), vectorBytesToValue[[8]any](2, uint16BytesToValue), vectorValueToBytes(2, uint16ValueToBytes), vectorStringToValue[[8]any](uintStringToValue[uint16]), } BoolNode = &NodeType{ 52, []string{"bool", "b"}, 1, 1, reflect.TypeOf(BoolValue(false)), boolBytesToValue, boolValueToBytes, boolStringToValue, } Vec2BoolNode = &NodeType{ 53, []string{"2b"}, 2, 2, reflect.TypeOf([2]BoolValue{}), vectorBytesToValue[[2]any](1, boolBytesToValue), vectorValueToBytes(1, boolValueToBytes), vectorStringToValue[[2]any](boolStringToValue), } Vec3BoolNode = &NodeType{ 54, []string{"3b"}, 3, 3, reflect.TypeOf([3]BoolValue{}), vectorBytesToValue[[3]any](1, boolBytesToValue), vectorValueToBytes(1, boolValueToBytes), vectorStringToValue[[3]any](boolStringToValue), } Vec4BoolNode = &NodeType{ 55, []string{"4b"}, 4, 4, reflect.TypeOf([4]BoolValue{}), vectorBytesToValue[[4]any](1, boolBytesToValue), vectorValueToBytes(1, boolValueToBytes), vectorStringToValue[[4]any](boolStringToValue), } Vec16BoolNode = &NodeType{ 56, []string{"vb", "16b"}, 16, 16, reflect.TypeOf([16]BoolValue{}), vectorBytesToValue[[16]any](1, boolBytesToValue), vectorValueToBytes(1, boolValueToBytes), vectorStringToValue[[16]any](boolStringToValue), } )
node types
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute struct { Value string // contains filtered or unexported fields }
Attribute represents an attribute in a property tree
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
func EncodingByName ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Attribute represents a node in a property tree
func NewNodeWithValue ¶
NewNode creates a new Node using the supplied name and value
func (*Node) AppendChild ¶
AppendChild adds c as the last child of the Node.
func (*Node) ArrayLength ¶
ArrayLength returns the length of an array or string value. If the Node does not contain an array or string value, 1 is returned instead.
func (*Node) AttributeValue ¶
AttributeValue returns the value of an attribute with the specified key. If the attribute is not present, an empty string is returned instead
func (*Node) AttributeValueNodeName ¶
AttributeValueNodeName returns the value of an attribute with the specified key. If the attribute is not present, an empty string is returned instead
func (*Node) Attributes ¶
Attributes returns a list of the Node's attributes. The returned slice is owned by the Node and should not be modified in any way. This function may return nil the Node does not have any attributes
func (*Node) BinaryValue ¶
BinaryValue returns the Node's value as a BinValue, or nil if the Node does not contain a BinValue.
func (*Node) ChildValue ¶
ChildValue returns the value of the first child of the Node with the specified name, or nil if no child is found
func (*Node) ChildValueNodeName ¶
ChildValueNodeName returns the value of the first child of the Node with the specified name, or nil if no child is found
func (*Node) Children ¶
Children returns a list of the Node's children. The returned slice is owned by the Node and should not be modified in any way. This function may return nil if the Node does not have any children
func (*Node) IntValue ¶
IntValue returns the Node's value as a signed integer, or 0 if the Node does not contain a signed integer value.
func (*Node) NewNodeWithValue ¶
NewNode creates a new Node with a value, and adds it as the last child of the Node.
func (*Node) SearchAttribute ¶
SearchAttributeNodeName returns an attribute with the specified key, or nil if no attribute is found
func (*Node) SearchAttributeNodeName ¶
SearchAttributeNodeName returns an attribute with the specified key, or nil if no attribute is found
func (*Node) SearchChild ¶
SearchChild returns the first child of the Node with the specified name, or nil if no child is found
func (*Node) SearchChildNodeName ¶
SearchChildNodeName returns the first child of the Node with the specified name, or nil if no child is found
func (*Node) SearchChildren ¶
SearchChildren returns a list of the Node's children with the specified name
func (*Node) SearchChildrenNodeName ¶
SearchChildrenNodeName returns a list of the Node's children with the specified name
func (*Node) SetAttribute ¶
SetAttribute creates an attribute using k and v as the key and value respectively. If an attribute with the same key is already present, its value will be updated with v.
func (*Node) SetValue ¶
SetValue sets the Node's value to v. Refer to type.go to see how Go types are mapped to Property types.
func (Node) ShallowCopy ¶
ShallowCopy creates a shallow copy of the node and its children. Changes made to node names, attribute keys, and mutable values, will be reflected in both copies.
func (*Node) StringValue ¶
StringValue returns the Node's value as a string, or an empty string if the Node does not contain a string value.
type NodeName ¶
type NodeName struct {
// contains filtered or unexported fields
}
func NewNodeName ¶
type Property ¶
type Property struct { // Settings defines how a property should be serialized. // After a read operation (successful or not) this field // is automatically updatedwith the settings of the // property that was read. Settings PropertySettings Root *Node }
Property represents a property tree.
func NewProperty ¶
NewProperty creates a new Property with the default settings and creates a new root Node with the specified name
func (*Property) Encoding ¶
Encoding returns the Property's encoding. If Settings.Encoding is nil, EncodingNone is returned instead
func (*Property) Read ¶
Read reads a document from the Reader into the Property. The format of the document is automatically inferred from the first byte in the stream
func (*Property) ReadFile ¶
Read reads a document from a file at the specified path into the Property. The format of the document is automatically inferred from the first byte in the file
type PropertyFormat ¶
type PropertyFormat int
const ( FormatBinary PropertyFormat = iota FormatXML FormatPrettyXML )
type PropertySettings ¶
type PropertySettings struct { Format PropertyFormat Encoding *Encoding UseLongNodeNames bool }