Documentation
¶
Index ¶
- Constants
- Variables
- func Decode(code []byte, format string, locate bool) (Value, Locator, error)
- func DecodeTemplate(template string, data any, format string, locate bool) (Value, Locator, error)
- func DecodeYAML(code []byte, locate bool) (Value, Locator, error)
- func Equals(a Value, b Value) bool
- func FindYAMLNode(node *yaml.Node, path ...PathElement) *yaml.Node
- func IsBoolean(value Value) bool
- func IsBytes(value Value) bool
- func IsList(value Value) bool
- func IsMap(value Value) bool
- func IsNull(value Value) bool
- func IsPrimitiveType(value Value) bool
- func IsString(value Value) bool
- func IsTimestamp(value Value) bool
- func MapKeyToString(key any) string
- func MarshalMessagePack(value any) ([]byte, error)
- func NewMessagePackDecoder(reader io.Reader) *msgpack.Decoder
- func NewMessagePackEncoder(writer io.Writer) *msgpack.Encoder
- func PackXJSON(value Value) (any, bool)
- func PackXML(value Value) any
- func PrepareForEncodingXJSON(value Value, inPlace bool, reflector *Reflector) (any, error)
- func PrepareForEncodingXML(value Value, inPlace bool, reflector *Reflector) (any, error)
- func Read(reader io.Reader, format string, locate bool) (Value, Locator, error)
- func ReadURL(context contextpkg.Context, url exturl.URL, format string, forceFormat bool, ...) (Value, Locator, error)
- func ReadYAML(reader io.Reader, locate bool) (Value, Locator, error)
- func ToYAMLDocumentNode(value Value, verbose bool, reflector *Reflector) (*yaml.Node, error)
- func ToYAMLNode(value Value, verbose bool) (*yaml.Node, bool)
- func UnmarshalMessagePack(data []byte, value any) error
- func UnpackXJSONBytes(code StringMap) ([]byte, bool)
- func UnpackXJSONInteger(code StringMap) (int64, bool)
- func UnpackXJSONUInteger(code StringMap) (uint64, bool)
- func Validate(code []byte, format string) error
- func ValidateCBOR(code []byte, base64 bool) error
- func ValidateJSON(code []byte) error
- func ValidateMessagePack(code []byte, base64 bool) error
- func ValidateXML(code []byte) error
- func ValidateYAML(code []byte) error
- func ValueToString(value Value) string
- type FromARD
- type List
- type Locator
- type Map
- type Node
- func (self *Node) Append(value Value) bool
- func (self *Node) Boolean() (bool, bool)
- func (self *Node) Bytes() ([]byte, bool)
- func (self *Node) ConvertSimilar() *Node
- func (self *Node) Delete() bool
- func (self *Node) Float() (float64, bool)
- func (self *Node) ForceGet(keys ...Value) *Node
- func (self *Node) ForceGetPath(path string, separator string) *Node
- func (self *Node) Get(keys ...Value) *Node
- func (self *Node) GetPath(path string, separator string) *Node
- func (self *Node) Integer() (int64, bool)
- func (self *Node) List() (List, bool)
- func (self *Node) Map() (Map, bool)
- func (self *Node) NilMeansZero() *Node
- func (self *Node) Set(value Value) bool
- func (self *Node) String() (string, bool)
- func (self *Node) StringList() ([]string, bool)
- func (self *Node) StringMap() (StringMap, bool)
- func (self *Node) UnsignedInteger() (uint64, bool)
- type Path
- type PathElement
- type PathElementType
- type Reflector
- type StringMap
- type StructFieldNameMapperFunc
- type ToARD
- type TypeName
- type TypeValidator
- type Value
- func ConvertMapsToStringMaps(value Value) (Value, bool)
- func ConvertStringMapsToMaps(value Value) (Value, bool)
- func Copy(value Value) Value
- func CopyMapsToStringMaps(value Value) Value
- func CopyStringMapsToMaps(value Value) Value
- func DecodeCBOR(code []byte, base64 bool) (Value, error)
- func DecodeJSON(code []byte, useStringMaps bool) (Value, error)
- func DecodeMessagePack(code []byte, base64 bool, useStringMaps bool) (Value, error)
- func DecodeXJSON(code []byte, useStringMaps bool) (Value, error)
- func DecodeXML(code []byte) (Value, error)
- func Merge(target Value, source Value, appendLists bool) Value
- func PathToKeys(path string, separator string) []Value
- func ReadCBOR(reader io.Reader, base64 bool) (Value, error)
- func ReadJSON(reader io.Reader, useStringMaps bool) (Value, error)
- func ReadMessagePack(reader io.Reader, base64 bool, useStringMaps bool) (Value, error)
- func ReadXJSON(reader io.Reader, useStringMaps bool) (Value, error)
- func ReadXML(reader io.Reader) (Value, error)
- func Roundtrip(value Value, format string, reflector *Reflector) (Value, error)
- func RoundtripCBOR(value Value) (Value, error)
- func RoundtripJSON(value Value) (Value, error)
- func RoundtripMessagePack(value Value) (Value, error)
- func RoundtripXJSON(value Value, reflector *Reflector) (Value, error)
- func RoundtripXML(value Value, reflector *Reflector) (Value, error)
- func RoundtripYAML(value Value) (Value, error)
- func UnpackXJSON(value any, useStringMaps bool) (Value, bool)
- func UnpackXML(element *etree.Element) (Value, error)
- func ValidCopy(value Value, reflector *Reflector) (Value, error)
- func ValidCopyMapsToStringMaps(value Value, reflector *Reflector) (Value, error)
- func ValidCopyStringMapsToMaps(value Value, reflector *Reflector) (Value, error)
- type XJSONBytes
- type XJSONInteger
- type XJSONMap
- type XJSONMapEntry
- type XJSONUInteger
- type XMLBytes
- type XMLList
- type XMLMap
- type XMLMapEntry
- type XMLNil
- type YAMLLocator
Constants ¶
const ( XJSONIntegerCode = "$ard.integer" XJSONUIntegerCode = "$ard.uinteger" XJSONBytesCode = "$ard.bytes" XJSONMapCode = "$ard.map" )
const ( XMLNilTag = "nil" XMLBytesTag = "bytes" XMLListTag = "list" XMLMapTag = "map" XMLMapEntryTag = "entry" XMLMapEntryKeyTag = "key" XMLMapEntryValueTag = "value" )
Variables ¶
This singleton is returned from all node functions when no node is found.
var TypeValidators = map[TypeName]TypeValidator{ TypeMap: IsMap, TypeList: IsList, TypeString: IsString, TypeBoolean: IsBoolean, TypeInteger: util.IsInteger, TypeFloat: util.IsFloat, TypeNull: IsNull, TypeBytes: IsBytes, TypeTimestamp: IsTimestamp, }
var TypeZeroes = map[TypeName]Value{ TypeMap: make(Map), TypeList: List{}, TypeString: "", TypeBoolean: false, TypeInteger: int(0), TypeFloat: float64(0.0), TypeNull: nil, TypeBytes: []byte{}, TypeTimestamp: time.Time{}, }
Functions ¶
func Decode ¶
Decodes supported formats to an ARD Value.
All resulting maps are guaranteed to be Map (and not StringMap).
If locate is true then a Locator will be returned if possible. Currently only YAML decoding supports this feature.
Supported formats are "yaml", "json", "xjson", "xml", "cbor", and "messagepack".
func DecodeTemplate ¶ added in v0.2.0
Convenience function to parse and render a template and then decode it.
Would only be useful for text-based formats, so not CBOR and MessagePack.
See text/template.
func DecodeYAML ¶
Decodes YAML to an ARD Value. If more than one YAML document is present (i.e. separated by `---`) then only the first will be decoded with the remainder ignored.
When locate is true will also return a Locator for the value, otherwise will return nil.
Note that the YAML implementation uses the yamlkeys library, so that arbitrarily complex map keys are supported and decoded into ARD Map. If you need to manipulate these maps you should use the yamlkeys utility functions.
func Equals ¶
Checks for deep equality between two ARD values.
Primitives are compared via the `=` operator.
Note that Map and StringMap are treated as unequal. To gloss over the difference in type, call CopyStringMapsToMaps on one or both of the values first.
func FindYAMLNode ¶
func FindYAMLNode(node *yaml.Node, path ...PathElement) *yaml.Node
func IsPrimitiveType ¶
Returns true if value is a string, bool, int64, int32, int16, int8, int, uint64, uint32, uint16, uint8, uint, float64, float32, nil, []byte, or time.Time.
func MapKeyToString ¶ added in v0.2.0
Provides consistent stringification of keys for ARD StringMap.
Used by functions such as ConvertMapsToStringMaps and CopyMapsToStringMaps.
func MarshalMessagePack ¶ added in v0.2.1
Marshals MessagePack with support for "json" field tags.
func NewMessagePackDecoder ¶ added in v0.2.1
MessagePack decoder that supports "json" field tags.
func NewMessagePackEncoder ¶ added in v0.2.1
MessagePack encode that supports "json" field tags.
func PrepareForEncodingXJSON ¶ added in v0.2.0
Prepares an ARD Value for encoding via xml.Encoder.
If inPlace is false then the function is non-destructive: the returned data structure is a ValidCopy of the value argument. Otherwise, the value may be changed during preparation.
The reflector argument can be nil, in which case a default reflector will be used.
func PrepareForEncodingXML ¶ added in v0.2.0
Prepares an ARD Value for encoding via xml.Encoder.
If inPlace is false then the function is non-destructive: the returned data structure is a ValidCopy of the value argument. Otherwise, the value may be changed during preparation.
The reflector argument can be nil, in which case a default reflector will be used.
func Read ¶
Reads and decodes supported formats to ARD.
All resulting maps are guaranteed to be Map (and not StringMap).
If locate is true then a Locator will be returned if possible. Currently only YAML decoding supports this feature.
Supported formats are "yaml", "json", "xjson", "xml", "cbor", and "messagepack".
func ReadURL ¶ added in v0.1.1
func ReadURL(context contextpkg.Context, url exturl.URL, format string, forceFormat bool, locate bool) (Value, Locator, error)
Convenience function to read from a URL. Calls Read.
When forceFormat is true the format argument will be used. When it's false the format will be attempted to be extracted from the URL using [URL.Format]. If it can't be determined then the format argument will be used as a fallback.
func ReadYAML ¶
Reads YAML from an io.Reader and decodes it to an ARD Value. If more than one YAML document is present (i.e. separated by `---`) then only the first will be decoded with the remainder ignored.
When locate is true will also return a Locator for the value, otherwise will return nil.
Note that the YAML implementation uses the yamlkeys library, so that arbitrarily complex map keys are supported and decoded into ARD Map. If you need to manipulate these maps you should use the yamlkeys utility functions.
func ToYAMLDocumentNode ¶
func ToYAMLNode ¶
func UnmarshalMessagePack ¶ added in v0.2.1
Unmarshals MessagePack with support for "json" field tags.
func UnpackXJSONBytes ¶ added in v0.2.0
func UnpackXJSONInteger ¶ added in v0.2.0
func UnpackXJSONUInteger ¶ added in v0.2.0
func Validate ¶ added in v0.2.1
Validates that data is of a supported format. Returns nil if valid, otherwise it will be the validation error.
While you can use Read to validate data, this function is optimized to be more lightweight. On other hand, this function does not do any schema validation (for example for XML), so if this function returns no error it does not guarantee that Read would also not return an error.
func ValidateCBOR ¶ added in v0.2.1
If base64 is true then the data will first be fully read and decoded from Base64 to bytes.
func ValidateJSON ¶ added in v0.2.1
func ValidateMessagePack ¶ added in v0.2.1
If base64 is true then the data will first be fully read and decoded from Base64 to bytes.
func ValidateXML ¶ added in v0.2.1
func ValidateYAML ¶ added in v0.2.1
func ValueToString ¶
Provides consistent stringification of primitive ARD Value.
Non-ARD types will be converted via util.ToString.
Types ¶
type Map ¶
An alias used to signify a map of ARD Value in which the key is also a Value. Note that this type does not protect its users against using invalid keys. Keys must be both hashable comparable.
type Node ¶
type Node struct { Value Value // contains filtered or unexported fields }
func With ¶ added in v0.2.12
Creates an extractable, convertible, traversable, and modifiable wrapper (a Node) for an ARD Value.
func (*Node) Append ¶
Appends a value to a List and calls Node.Set.
Will fail and return false if there's no containing node or it's not Map or StringMap, or if this node is not a List.
func (*Node) Boolean ¶
Returns (bool, true) if the node is a bool.
If Node.ConvertSimilar was called then will call Node.String and then strconv.ParseBool, with failures returning (false, false). Thus "true", "1", and numerical 1 (both ints and floats) will all be interpreted as boolean true.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as false.
func (*Node) Bytes ¶
Returns ([]byte, true) if the node is a []byte.
If Node.ConvertSimilar was called and the node is a string then will attempt to decode it as base64, with failures returning (false, false).
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as an empty []byte.
func (*Node) ConvertSimilar ¶
Returns a copy of this node for which similarly-typed values are allowed and converted to the requested type. For example, Node.Float on an integer or unsigned integer would convert it to float.
func (*Node) Delete ¶ added in v0.2.7
Deletes this node's key from the containing node's map.
Will fail and return false if there's no containing node or it's not Map or StringMap.
func (*Node) Float ¶
Returns (float64, true) if the node is a float64 or a float32.
If Node.ConvertSimilar was called then will convert all other number types (int64, int32, int16, int8, int, uint64, uint32, uint16, uint8, and uint) to a float64 and return true (unless we are NoNode).
Precision may be lost.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as 0.0.
func (*Node) ForceGet ¶ added in v0.2.11
Similar to Node.Get except that along the way new maps will be created if they do not exist and the key isn't already in use by something that is not a map. The type of the created map will match that of the containing map, either Map or StringMap. If the final key does not exist then a node with a nil value, contained in the previous node, will be returned. You can thus call Node.Set on it to set the value for the final key.
Thus the idiomatic safe way to set a nested value is like so:
if ok := ard.With(value).ForceGet("key1", "key2", "key3").Set("value"); ok { ... }
If you called Node.NilMeansZero, then take care when extracting data from the returned node, e.g. via Node.String, Node.Integer, etc. If the final key does not exist then these functions would still succeed.
For StringMap keys are converted using MapKeyToString.
func (*Node) ForceGetPath ¶ added in v0.2.11
Convenience method to call Node.ForceGet with PathToKeys.
func (*Node) Get ¶
Gets a nested node by recursively following keys. Thus all keys except the final one refer to nodes that must be Map or StringMap. Returns NoNode if any of the keys is not found along the way.
Thus the idiomatic safe way to get a nested value is like so:
if s, ok := ard.With(value).Get("key1", "key2", "key3").String(); ok { ... }
For StringMap keys are converted using MapKeyToString.
func (*Node) GetPath ¶ added in v0.2.11
Convenience method to call Node.Get with PathToKeys.
func (*Node) Integer ¶
Returns (int64, true) if the node is an int64, int32, int16, int8, or int.
If Node.ConvertSimilar was called then will convert all other number types (uint64, uint32, uint16, uint8, uint, float64, and float32) to an int64 and return true (unless we are NoNode). Precision may be lost.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as 0.
func (*Node) List ¶
Returns (List, true) if the node is a List.
If Node.ConvertSimilar was called then will convert other lists to a List.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as an empty List.
func (*Node) Map ¶
Returns (Map, true) if the node is a Map.
If Node.ConvertSimilar was called then will convert other maps to a Map and return true.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as an empty Map.
func (*Node) NilMeansZero ¶
Returns a copy of this node for which nil values are allowed and interpreted as the zero value. For example, Node.String on nil would return an empty string.
func (*Node) Set ¶ added in v0.2.9
Sets the value of this node and its key in the containing map.
Will fail and return false if there's no containing node or it's not Map or StringMap.
func (*Node) String ¶
Returns (string, true) if the node is a string.
If Node.ConvertSimilar was called then will convert any value to a string representation using ValueToString and return true (unless we are NoNode).
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as an empty string.
func (*Node) StringList ¶
Returns ([]string, true) if the node is List and all its elements are strings. (Will avoid copying if the node is already a []string, which doesn't occur in valid ARD.)
If Node.ConvertSimilar was called then will convert all other lists to []string with all elements to their string representations and return true. Values are converted using ValueToString.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as an empty []string.
func (*Node) StringMap ¶
Returns (StringMap, true) if the node is a StringMap.
If Node.ConvertSimilar was called then will convert other maps to a StringMap and return true. Keys are converted using MapKeyToString.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as an empty StringMap.
func (*Node) UnsignedInteger ¶
Returns (uint64, true) if the node is an uint64, uint32, uint16, uint8, or uint.
If Node.ConvertSimilar was called then will convert all other number types (int64, int32, int16, int8, int, float64, and float32) to an uint64 and return true (unless we are NoNode). Precision may be lost.
By default will fail on nil values. Call Node.NilMeansZero to interpret nil as 0.
type Path ¶
type Path []PathElement
func (Path) Append ¶
func (self Path) Append(element PathElement) Path
func (Path) AppendField ¶
func (Path) AppendList ¶
func (Path) AppendSequencedList ¶
type PathElement ¶
type PathElement struct { Type PathElementType Value any // string for FieldPathType and MapPathType; int for ListPathType and SequencedListPathType }
func NewFieldPathElement ¶
func NewFieldPathElement(name string) PathElement
func NewListPathElement ¶
func NewListPathElement(index int) PathElement
func NewMapPathElement ¶
func NewMapPathElement(name string) PathElement
func NewSequencedListPathElement ¶
func NewSequencedListPathElement(index int) PathElement
type PathElementType ¶
type PathElementType int
const ( FieldPathType PathElementType = 0 MapPathType PathElementType = 1 ListPathType PathElementType = 2 SequencedListPathType PathElementType = 3 )
type Reflector ¶
type Reflector struct { // When true, non-existing struct fields will be ignored when packing. // Otherwise, will result in a packing error. IgnoreMissingStructFields bool // When true, nil values will be packed into the zero value for the target type. // Otherwise, only nullable types will be supported in the target: pointers, maps, // and slices, and other types will result in a packing error. NilMeansZero bool // Used for both packing and unpacking. Processed in order. StructFieldTags []string // While StructFieldTags can be used to specify specific unpacked names, when // untagged this function, if set, will be used for translating field names to // their unpacked names. StructFieldNameMapper StructFieldNameMapperFunc // contains filtered or unexported fields }
func NewReflector ¶
func NewReflector() *Reflector
Creates a reflector with default struct field tags: "ard", "yaml", "json".
func (*Reflector) Pack ¶
Packs an ARD value into Go types, recursively.
For Go struct field names, keys are converted from Map using MapKeyToString.
Structs can provide their own custom packing by implementing the FromARD interface.
packedValuePtr must be a pointer.
func (*Reflector) Unpack ¶
Unpacks Go types to ARD, recursively. Map is used for Go structs and maps.
For Go struct field names, keys are converted to StringMap using MapKeyToString.
Structs can provide their own custom unpacking by implementing the ToARD interface.
packedValuePtr must be a pointer.
func (*Reflector) UnpackStringMaps ¶ added in v0.2.14
Unpacks Go types to ARD, recursively. StringMap is used for Go structs and maps.
Keys are converted using MapKeyToString.
Structs can provide their own custom unpacking by implementing the ToARD interface.
packedValue can be a value or a pointer.
type StringMap ¶
An alias used to signify a map of ARD Value in which the key is always string. This alias is introduced for compability with certain parsers and encoders.
type TypeName ¶
type TypeName string
const ( NoType TypeName = "" // Failsafe schema: https://yaml.org/spec/1.2/spec.html#id2802346 TypeMap TypeName = "ard.map" TypeList TypeName = "ard.list" TypeString TypeName = "ard.string" // JSON schema: https://yaml.org/spec/1.2/spec.html#id2803231 TypeBoolean TypeName = "ard.boolean" TypeInteger TypeName = "ard.integer" TypeFloat TypeName = "ard.float" // Other schemas: https://yaml.org/spec/1.2/spec.html#id2805770 TypeNull TypeName = "ard.null" TypeBytes TypeName = "ard.bytes" TypeTimestamp TypeName = "ard.timestamp" )
func GetTypeName ¶
Returns a canonical name for all supported ARD types, including primitives, Map, List, and time.Time. Note that StringMap is not supported by this function.
Unspported types will use fmt.Sprintf("%T").
type TypeValidator ¶
type Value ¶
type Value = any
An alias used to signify that ARD values are expected, namely primitives, List, Map, and StringMap nested to any depth.
func ConvertMapsToStringMaps ¶ added in v0.2.0
Converts any Map to StringMap recursively, ensuring that no Map will be present. Conversion happens in place, unless the input is itself a Map, in which case a new StringMap will be returned.
Keys are converted using MapKeyToString.
Returns true if any conversion occurred.
func ConvertStringMapsToMaps ¶ added in v0.2.0
Converts any StringMap to Map recursively, ensuring that no StringMap will be present. Conversion happens in place, unless the input is itself a StringMap, in which case a new Map will be returned.
Returns true if any conversion occurred.
func Copy ¶ added in v0.2.0
Deep copy.
The input can be a mix of ARD and non-ARD values (e.g. Go structs). Non-ARD values will be left as is, thus the returned may not be valid ARD. To ensure a valid ARD result use ValidCopy.
Recurses into Map, StringMap, and List, creating new instances of each. Thus a Map is copied into a new Map and a StringMap is copied into a new StringMap. To convert them to a unified map type use CopyStringMapsToMaps or CopyMapsToStringMaps.
func CopyMapsToStringMaps ¶ added in v0.2.0
Like Copy but converts all Map to StringMap.
Keys are converted using MapKeyToString.
For in-place conversion use ConvertStringMapsToMaps.
func CopyStringMapsToMaps ¶ added in v0.2.0
Like Copy but converts all StringMap to Map.
For in-place conversion use ConvertStringMapsToMaps.
func DecodeCBOR ¶
Decodes CBOR to an ARD Value.
If base64 is true then the data will first be fully read and decoded from Base64 to bytes.
func DecodeJSON ¶
Decodes JSON to an ARD Value.
If useStringMaps is true returns maps as StringMap, otherwise they will be Map.
func DecodeMessagePack ¶
Reads MessagePack from an io.Reader and decodes it to an ARD Value.
If base64 is true then the data will first be fully read and decoded from Base64 to bytes.
If useStringMaps is true returns maps as StringMap, otherwise they will be Map.
func DecodeXJSON ¶ added in v0.2.0
Decodes JSON to an ARD Value while interpreting the XJSON extensions.
If useStringMaps is true returns maps as StringMap, otherwise they will be Map.
func DecodeXML ¶ added in v0.2.0
Decodes XML to an ARD Value.
A specific schema is expected (currently undocumented).
func Merge ¶ added in v0.2.2
Deep merge of source value into target value. Map and StringMap are merged key by key, recursively.
When appendList is true then target list elements are appended to the source list, otherwise the source list is overridden (copied over).
The source value remains safe, in that all merged data is copied (via Copy) into the target, thus any changes made to the target will not affect the source. On the other hand, the target value is changed in place. Note that for arguments that are not Map or StringMap you must use the return value from this function because it may return a new target value, e.g. a new List slice when appendList is true. Thus a safe way to use this function is like so:
target = Merge(target, source, true)
func PathToKeys ¶ added in v0.2.5
Convenience function to convert a string path to keys usable for Node.Get and Node.ForceGet.
Does a strings.Split with the provided separator.
func ReadCBOR ¶
Reads CBOR from an io.Reader and decodes it to an ARD Value.
If base64 is true then the data will first be fully read and decoded from Base64 to bytes.
func ReadJSON ¶
Reads JSON from an io.Reader and decodes it to an ARD Value.
If useStringMaps is true returns maps as StringMap, otherwise they will be Map.
func ReadMessagePack ¶
Reads MessagePack from an io.Reader and decodes it to an ARD Value.
If base64 is true then the data will first be fully read and decoded from Base64 to bytes.
If useStringMaps is true returns maps as StringMap, otherwise they will be Map.
func ReadXJSON ¶ added in v0.2.0
Reads JSON from an io.Reader and decodes it to an ARD Value while interpreting the XJSON extensions.
If useStringMaps is true returns maps as StringMap, otherwise they will be Map.
func ReadXML ¶ added in v0.2.0
Reads XML from an io.Reader and decodes it to an ARD Value.
A specific schema is expected (currently undocumented).
func Roundtrip ¶
Encodes and then decodes the value via a supported format.
Supported formats are "yaml", "json", "xjson", "xml", "cbor", and "messagepack".
While this function can be used to "canonicalize" values to ARD, it is generally be more efficient to call ValidCopy instead.
func RoundtripCBOR ¶
func RoundtripJSON ¶
func RoundtripMessagePack ¶
func RoundtripXJSON ¶ added in v0.2.0
func RoundtripXML ¶ added in v0.2.0
func RoundtripYAML ¶
func ValidCopy ¶ added in v0.2.0
Deep copy and return a valid ARD value.
The input can be a mix of ARD and non-ARD values (e.g. Go structs). The returned value is guaranteed to be valid ARD. This works by reflecting any non-ARD via the provided *Reflector. The reflector argument can be nil, in which case a default reflector will be used. To leave non-ARD values as is use Copy.
This function can be used to "canonicalize" values to ARD, for which is should generally be more efficient than calling Roundtrip.
Recurses into Map, StringMap, and List, creating new instances of each. Thus a Map is copied into a new Map and a StringMap is copied into a new StringMap. To convert them to a unified map type use ValidCopyStringMapsToMaps or ValidCopyMapsToStringMaps.
func ValidCopyMapsToStringMaps ¶ added in v0.2.0
Like ValidCopy but converts all Map to StringMap.
Keys are converted using MapKeyToString.
For in-place conversion use ConvertMapsToStringMaps.
func ValidCopyStringMapsToMaps ¶ added in v0.2.0
Like ValidCopy but converts all StringMap to Map.
For in-place conversion use ConvertStringMapsToMaps.
type XJSONBytes ¶ added in v0.2.0
type XJSONBytes []byte
func (XJSONBytes) MarshalJSON ¶ added in v0.2.0
func (self XJSONBytes) MarshalJSON() ([]byte, error)
(json.Marshaler interface)
type XJSONInteger ¶ added in v0.2.0
type XJSONInteger int64
func (XJSONInteger) MarshalJSON ¶ added in v0.2.0
func (self XJSONInteger) MarshalJSON() ([]byte, error)
(json.Marshaler interface)
type XJSONMap ¶ added in v0.2.0
type XJSONMap Map
func (XJSONMap) MarshalJSON ¶ added in v0.2.0
(json.Marshaler interface)
type XJSONMapEntry ¶ added in v0.2.0
func UnpackXJSONMapEntry ¶ added in v0.2.0
func UnpackXJSONMapEntry(entry Value, useStringMaps bool) (*XJSONMapEntry, bool)
type XJSONUInteger ¶ added in v0.2.0
type XJSONUInteger uint64
func (XJSONUInteger) MarshalJSON ¶ added in v0.2.0
func (self XJSONUInteger) MarshalJSON() ([]byte, error)
(json.Marshaler interface)
type XMLBytes ¶ added in v0.2.0
type XMLBytes struct {
// contains filtered or unexported fields
}
func (XMLBytes) MarshalXML ¶ added in v0.2.0
(xml.Marshaler interface)
type XMLList ¶ added in v0.2.0
type XMLList struct {
Entries []any
}
func (XMLList) MarshalXML ¶ added in v0.2.0
(xml.Marshaler interface)
type XMLMap ¶ added in v0.2.0
type XMLMap struct {
// contains filtered or unexported fields
}
func (XMLMap) MarshalXML ¶ added in v0.2.0
(xml.Marshaler interface)
type XMLMapEntry ¶ added in v0.2.0
type XMLMapEntry struct {
// contains filtered or unexported fields
}
func NewXMLMapEntry ¶ added in v0.2.0
func NewXMLMapEntry(element *etree.Element) (XMLMapEntry, error)
func (XMLMapEntry) MarshalXML ¶ added in v0.2.0
func (self XMLMapEntry) MarshalXML(encoder *xml.Encoder, start xml.StartElement) error
(xml.Marshaler interface)
type XMLNil ¶ added in v0.2.0
type XMLNil struct{}
func (XMLNil) MarshalXML ¶ added in v0.2.0
(xml.Marshaler interface)
type YAMLLocator ¶
type YAMLLocator struct {
RootNode *yaml.Node
}
func NewYAMLLocator ¶
func NewYAMLLocator(rootNode *yaml.Node) *YAMLLocator
func (*YAMLLocator) Locate ¶
func (self *YAMLLocator) Locate(path ...PathElement) (int, int, bool)
(Locator interface)