encoding

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeValue

func DecodeValue(v interface{}) (syntax.Node, syntax.Diagnostics)

DecodeValue decodes a plain Go value into a syntax.Node.

Decoding uses the following rules:

  • Interface and pointer values decode as their element value. Nil interface and pointer values decode as *syntax.NullNode.
  • Boolean values decode as *syntax.BooleanNode.
  • Floating point and integer values decode as *syntax.NumberNode.
  • json.Number values decode as *syntax.NumberNode.
  • String values decode as *syntax.StringNode.
  • Arrays and slices decode as *syntax.ListNode. Nil slices are decoded as *syntax.NullNode.
  • Maps are decoded as *syntax.ObjectNode. Map keys must be strings. Nil maps are deocded as *syntax.NullNode.
  • Structs are decoded as *syntax.ObjectNode. Exported struct fields decode into object properties using the name of the field as the property's key. The name of the struct field can be customized using a struct tag of the form `object:"name"`. If a field's value decodes as *syntax.NullNode, that field is omitted from the result.

func DecodeYAML

func DecodeYAML(filename string, d *yaml.Decoder, tags TagDecoder) (syntax.Node, syntax.Diagnostics)

DecodeYAML decodes a YAML value from the given decoder into a syntax node. See UnmarshalYAML for mode details on the decoding process.

func DecodeYAMLBytes

func DecodeYAMLBytes(filename string, bytes []byte, tags TagDecoder) (syntax.Node, syntax.Diagnostics)

DecodeYAMLBytes decodes a YAML value from the given decoder into a syntax node. See UnmarshalYAML for mode details on the decoding process.

func EncodeValue

func EncodeValue(n syntax.Node, v interface{}) syntax.Diagnostics

EncodeValue encodes a syntax.Node into a plain Go value. The encoding rules are the inverse of the decoding rules described in the documentation for DecodeValue.

func EncodeYAML

func EncodeYAML(e *yaml.Encoder, n syntax.Node) syntax.Diagnostics

EncodeYAML encodes a syntax node into YAML text using the given encoder. See MarshalYAML for mode details on the encoding process.

func MarshalYAML

func MarshalYAML(n syntax.Node) (*yaml.Node, syntax.Diagnostics)

MarshalYAML marshals a syntax node into a YAML node. If a syntax node has an associated YAMLSyntax annotation, the tag, style, and comments on the result will be pulled from the YAMLSyntax. The marshaling process otherwise follows the inverse of the unmarshaling process described in the documentation for UnmarshalYAML.

func UnmarshalYAML

func UnmarshalYAML(filename string, n *yaml.Node, tags TagDecoder) (syntax.Node, syntax.Diagnostics)

UnmarshalYAML unmarshals a YAML node into a syntax node.

Nodes are decoded as follows: - Scalars are decoded as the corresponding literal type (null -> nullNode, bool -> BooleanNode, etc.) - Sequences are decoded as array nodes - Mappings are decoded as object nodes

Tagged nodes are decoded using the given TagDecoder. To avoid infinite recursion, the TagDecoder must call UnmarshalYAMLNode if it needs to unmarshal the node it is processing.

func UnmarshalYAMLNode

func UnmarshalYAMLNode(filename string, n *yaml.Node, tags TagDecoder) (syntax.Node, syntax.Diagnostics)

UnmarshalYAMLNode unmarshals the given YAML node into a syntax Node. UnmarshalYAMLNode does _not_ use the tag decoder for the node itself, though it does use the tag decoder for the node's children. This allows tag decoders to call UnmarshalYAMLNode without infinitely recurring on the same node. See UnmarshalYAML for more details.

Types

type TagDecoder

type TagDecoder interface {
	// DecodeTag decodes a tagged YAML node.
	DecodeTag(filename string, n *yaml.Node) (syntax.Node, syntax.Diagnostics, bool)
}

A TagDecoder decodes tagged YAML nodes. See the documentation on UnmarshalYAML for more details.

type YAMLSyntax

type YAMLSyntax struct {
	*yaml.Node
	// contains filtered or unexported fields
}

YAMLSyntax is a syntax.Syntax implementation that is backed by a YAML node.

func (YAMLSyntax) Delete added in v0.11.1

func (s YAMLSyntax) Delete(prefix, path resource.PropertyPath) error

func (YAMLSyntax) FootComment added in v0.6.0

func (s YAMLSyntax) FootComment() string

func (YAMLSyntax) Get added in v0.11.1

func (s YAMLSyntax) Get(path resource.PropertyPath) (_ *yaml.Node, ok bool)

func (YAMLSyntax) HeadComment added in v0.6.0

func (s YAMLSyntax) HeadComment() string

func (YAMLSyntax) LineComment added in v0.6.0

func (s YAMLSyntax) LineComment() string

func (YAMLSyntax) Path added in v0.6.0

func (s YAMLSyntax) Path() string

Path returns the path of the YAML node, if any.

func (YAMLSyntax) Range

func (s YAMLSyntax) Range() *hcl.Range

Range returns the textual range of the YAML node, if any.

func (YAMLSyntax) ScalarRange added in v0.8.0

func (s YAMLSyntax) ScalarRange(start, end int) *hcl.Range

func (YAMLSyntax) Set added in v0.11.1

func (s YAMLSyntax) Set(prefix, path resource.PropertyPath, new yaml.Node) (*yaml.Node, error)

Jump to

Keyboard shortcuts

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