avsproperty

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 17 Imported by: 6

README

avsproperty

A library and tool for working with AVS2 property files

CLI

A simple CLI tool for converting between file formats is included

Usage: avsproperty FILENAME 

Property format conversion tool

List of available options:
  -u    Set output encoding to UTF-8

Library

Read the code

Documentation

Index

Constants

This section is empty.

Variables

View Source
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,
	}
)
View Source
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

func (Attribute) Key

func (a Attribute) Key() *NodeName

type BinValue

type BinValue []byte

BinValue represents the value of a binary node.

type BoolValue

type BoolValue bool

BoolValue represents the value of a bool node

func (BoolValue) String

func (bv BoolValue) String() string

type Encoding

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

func EncodingByName

func EncodingByName(name string) *Encoding

func (*Encoding) String

func (e *Encoding) String() string

type Node

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

Attribute represents a node in a property tree

func NewNode

func NewNode(name string) (*Node, error)

NewNode creates a new Node using the supplied name

func NewNodeWithValue

func NewNodeWithValue(name string, value any) (*Node, error)

NewNode creates a new Node using the supplied name and value

func (*Node) AppendChild

func (n *Node) AppendChild(c *Node) error

AppendChild adds c as the last child of the Node.

func (*Node) ArrayLength

func (n *Node) ArrayLength() int

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

func (n *Node) AttributeValue(k string) string

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

func (n *Node) AttributeValueNodeName(k *NodeName) string

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

func (n *Node) Attributes() []*Attribute

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

func (n *Node) BinaryValue() BinValue

BinaryValue returns the Node's value as a BinValue, or nil if the Node does not contain a BinValue.

func (*Node) ChildValue

func (n *Node) ChildValue(name string) any

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

func (n *Node) ChildValueNodeName(name *NodeName) any

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

func (n *Node) Children() []*Node

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

func (n *Node) IntValue() int64

IntValue returns the Node's value as a signed integer, or 0 if the Node does not contain a signed integer value.

func (*Node) IsArray

func (n *Node) IsArray() bool

func (*Node) Name

func (n *Node) Name() *NodeName

func (*Node) NewNode

func (n *Node) NewNode(name string) (*Node, error)

NewNode creates a new Node, and adds it as the last child of the Node.

func (*Node) NewNodeWithValue

func (n *Node) NewNodeWithValue(name string, value any) (*Node, error)

NewNode creates a new Node with a value, and adds it as the last child of the Node.

func (*Node) Parent

func (n *Node) Parent() *Node

func (*Node) SearchAttribute

func (n *Node) SearchAttribute(k string) *Attribute

SearchAttributeNodeName returns an attribute with the specified key, or nil if no attribute is found

func (*Node) SearchAttributeNodeName

func (n *Node) SearchAttributeNodeName(k *NodeName) *Attribute

SearchAttributeNodeName returns an attribute with the specified key, or nil if no attribute is found

func (*Node) SearchChild

func (n *Node) SearchChild(name string) *Node

SearchChild returns the first child of the Node with the specified name, or nil if no child is found

func (*Node) SearchChildNodeName

func (n *Node) SearchChildNodeName(name *NodeName) *Node

SearchChildNodeName returns the first child of the Node with the specified name, or nil if no child is found

func (*Node) SearchChildren

func (n *Node) SearchChildren(name string) []*Node

SearchChildren returns a list of the Node's children with the specified name

func (*Node) SearchChildrenNodeName

func (n *Node) SearchChildrenNodeName(name *NodeName) []*Node

SearchChildrenNodeName returns a list of the Node's children with the specified name

func (*Node) SetAttribute

func (n *Node) SetAttribute(k, v string) error

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

func (n *Node) SetValue(v any) error

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

func (n Node) ShallowCopy() *Node

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

func (n *Node) StringValue() string

StringValue returns the Node's value as a string, or an empty string if the Node does not contain a string value.

func (*Node) Traverse

func (n *Node) Traverse(start, end func(*Node) error) error

func (*Node) Type

func (n *Node) Type() *NodeType

func (*Node) UintValue

func (n *Node) UintValue() uint64

IntValue returns the Node's value as an unsigned integer, or 0 if the Node does not contain an unsigned integer value.

func (*Node) Value

func (n *Node) Value() any

type NodeName

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

func NewNodeName

func NewNodeName(name string) (*NodeName, error)

func (*NodeName) Equals

func (a *NodeName) Equals(b *NodeName) bool

func (*NodeName) Length

func (n *NodeName) Length() int

func (*NodeName) Set

func (n *NodeName) Set(s string) error

func (*NodeName) String

func (n *NodeName) String() string

type NodeType

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

func (NodeType) Name

func (t NodeType) Name() string

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

func NewProperty(root string) (*Property, error)

NewProperty creates a new Property with the default settings and creates a new root Node with the specified name

func (*Property) Encoding

func (p *Property) Encoding() *Encoding

Encoding returns the Property's encoding. If Settings.Encoding is nil, EncodingNone is returned instead

func (*Property) Read

func (p *Property) Read(rd io.Reader) error

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

func (p *Property) ReadFile(filename string) error

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

func (*Property) Write

func (p *Property) Write(wr io.Writer) error

Write serializes and writes the property to the Writer. The way in which the Property is serialized is defined by its Settings field.

func (*Property) WriteFile

func (p *Property) WriteFile(filename string) error

Write serializes and writes the property to a file at the specified path. The way in which the Property should be serialized is defined by its Settings field.

type PropertyFormat

type PropertyFormat int
const (
	FormatBinary PropertyFormat = iota
	FormatXML
	FormatPrettyXML
)

type PropertySettings

type PropertySettings struct {
	Format           PropertyFormat
	Encoding         *Encoding
	UseLongNodeNames bool
}

type TimeValue

type TimeValue uint32

TimeValue represents the value of a time node

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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