msgpack

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 10 Imported by: 104

Documentation

Overview

Package msgpack provides functions for serializing cty values in the msgpack encoding, and decoding them again.

If the same type information is provided both at encoding and decoding time then values can be round-tripped without loss, except for capsule types which are not currently supported.

If any unknown values are passed to Marshal then they will be represented using a msgpack extension with type code zero, which is understood by the Unmarshal function within this package but will not be understood by a generic (non-cty-aware) msgpack decoder. Ensure that no unknown values are used if interoperability with other msgpack implementations is required.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImpliedType

func ImpliedType(buf []byte) (cty.Type, error)

ImpliedType returns the cty Type implied by the structure of the given msgpack-compliant buffer. This function implements the default type mapping behavior used when decoding arbitrary msgpack without explicit cty Type information.

The rules are as follows:

msgpack strings, numbers and bools map to their equivalent primitive type in cty.

msgpack maps become cty object types, with the attributes defined by the map keys and the types of their values.

msgpack arrays become cty tuple types, with the elements defined by the types of the array members.

Any nulls are typed as DynamicPseudoType, so callers of this function must be prepared to deal with this. Callers that do not wish to deal with dynamic typing should not use this function and should instead describe their required types explicitly with a cty.Type instance when decoding.

Any unknown values are similarly typed as DynamicPseudoType, because these do not carry type information on the wire.

Any parse errors will be returned as an error, and the type will be the invalid value cty.NilType.

func Marshal

func Marshal(val cty.Value, ty cty.Type) ([]byte, error)

Marshal produces a msgpack serialization of the given value that can be decoded into the given type later using Unmarshal.

The given value must conform to the given type, or an error will be returned.

func Unmarshal

func Unmarshal(b []byte, ty cty.Type) (cty.Value, error)

Unmarshal interprets the given bytes as a msgpack-encoded cty Value of the given type, returning the result.

If an error is returned, the error is written with a hypothetical end-user that wrote the msgpack file as its audience, using cty type system concepts rather than Go type system concepts.

Types

This section is empty.

Jump to

Keyboard shortcuts

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