ctystructpb

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package ctystructpb supports bidirectional conversions between cty values and google.protobuf.Struct protobuf messages.

Because google.protobuf.Struct is a mapping of the JSON infoset into the protobuf infoset, ctystructpb always makes the same decisions as cty's standard JSON serialization, but produces a protobuf-compatible result instead of a raw byte buffer.

Note that cty's JSON support uses arbitrary-precision number values, but google.protobuf.Struct always uses float64 values and so numbers outside of that range will silently lose precision on encoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromStructValue

func FromStructValue(sv *structpb.Value, ty cty.Type) (cty.Value, error)

FromStructValue decodes a JSON representation of the given value into a cty Value conforming to the given type.

While decoding, type conversions will be made where possible to make the result conformant even if the types given in JSON are not exactly correct. If conversion isn't possible then an error is returned, which may be a cty.PathError.

func ImpliedType

func ImpliedType(sv *structpb.Value) (cty.Type, error)

ImpliedType returns the cty Type implied by the structure of the given structpb value. This function implements the default type mapping behavior used when decoding arbitrary values without explicit cty Type information.

The mapping rules are the same as for cty's JSON ImpliedType function.

func ToStructValue

func ToStructValue(v cty.Value, ty cty.Type) (*structpb.Value, error)

ToStructValue produces a struct value representation of the given value that can later be decoded into a value of the given type.

A type is specified separately to allow for the given type to include cty.DynamicPseudoType to represent situations where any type is permitted and so type information must be included to allow recovery of the stored structure when decoding.

The given type will also be used to attempt automatic conversions of any non-conformant types in the given value, although this will not always be possible. If the value cannot be made to be conformant then an error is returned, which may be a cty.PathError.

Capsule-typed values can be encoded via their own MarshalJSON implementations, but with some caveats. Since capsule values are compared by pointer equality, it is impossible to recover a value that will compare equal to the original value. Additionally, it's not possible to JSON-serialize the capsule type itself, so it's not valid to use capsule types within parts of the value that are conformed to cty.DynamicPseudoType.

Types

This section is empty.

Jump to

Keyboard shortcuts

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