mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
govendor fetch github.com/zclconf/go-cty/...
This adds an ImpliedType to the msgpack package, which serves the same purpose as ImpliedType in the json package.
This commit is contained in:
parent
c28ce02f2a
commit
6dcaafa6ba
167
vendor/github.com/zclconf/go-cty/cty/msgpack/type_implied.go
generated
vendored
Normal file
167
vendor/github.com/zclconf/go-cty/cty/msgpack/type_implied.go
generated
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
package msgpack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/vmihailenco/msgpack"
|
||||
msgpackcodes "github.com/vmihailenco/msgpack/codes"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// 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 ImpliedType(buf []byte) (cty.Type, error) {
|
||||
r := bytes.NewReader(buf)
|
||||
dec := msgpack.NewDecoder(r)
|
||||
|
||||
ty, err := impliedType(dec)
|
||||
if err != nil {
|
||||
return cty.NilType, err
|
||||
}
|
||||
|
||||
// We must now be at the end of the buffer
|
||||
err = dec.Skip()
|
||||
if err != io.EOF {
|
||||
return ty, fmt.Errorf("extra bytes after msgpack value")
|
||||
}
|
||||
|
||||
return ty, nil
|
||||
}
|
||||
|
||||
func impliedType(dec *msgpack.Decoder) (cty.Type, error) {
|
||||
// If this function returns with a nil error then it must have already
|
||||
// consumed the next value from the decoder, since when called recursively
|
||||
// the caller will be expecting to find a following value here.
|
||||
|
||||
code, err := dec.PeekCode()
|
||||
if err != nil {
|
||||
return cty.NilType, err
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
case code == msgpackcodes.Nil || msgpackcodes.IsExt(code):
|
||||
err := dec.Skip()
|
||||
return cty.DynamicPseudoType, err
|
||||
|
||||
case code == msgpackcodes.True || code == msgpackcodes.False:
|
||||
_, err := dec.DecodeBool()
|
||||
return cty.Bool, err
|
||||
|
||||
case msgpackcodes.IsFixedNum(code):
|
||||
_, err := dec.DecodeInt64()
|
||||
return cty.Number, err
|
||||
|
||||
case code == msgpackcodes.Int8 || code == msgpackcodes.Int16 || code == msgpackcodes.Int32 || code == msgpackcodes.Int64:
|
||||
_, err := dec.DecodeInt64()
|
||||
return cty.Number, err
|
||||
|
||||
case code == msgpackcodes.Uint8 || code == msgpackcodes.Uint16 || code == msgpackcodes.Uint32 || code == msgpackcodes.Uint64:
|
||||
_, err := dec.DecodeUint64()
|
||||
return cty.Number, err
|
||||
|
||||
case code == msgpackcodes.Float || code == msgpackcodes.Double:
|
||||
_, err := dec.DecodeFloat64()
|
||||
return cty.Number, err
|
||||
|
||||
case msgpackcodes.IsString(code):
|
||||
_, err := dec.DecodeString()
|
||||
return cty.String, err
|
||||
|
||||
case msgpackcodes.IsFixedMap(code) || code == msgpackcodes.Map16 || code == msgpackcodes.Map32:
|
||||
return impliedObjectType(dec)
|
||||
|
||||
case msgpackcodes.IsFixedArray(code) || code == msgpackcodes.Array16 || code == msgpackcodes.Array32:
|
||||
return impliedTupleType(dec)
|
||||
|
||||
default:
|
||||
return cty.NilType, fmt.Errorf("unsupported msgpack code %#v", code)
|
||||
}
|
||||
}
|
||||
|
||||
func impliedObjectType(dec *msgpack.Decoder) (cty.Type, error) {
|
||||
// If we get in here then we've already peeked the next code and know
|
||||
// it's some sort of map.
|
||||
l, err := dec.DecodeMapLen()
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, nil
|
||||
}
|
||||
|
||||
var atys map[string]cty.Type
|
||||
|
||||
for i := 0; i < l; i++ {
|
||||
// Read the map key first. We require maps to be strings, but msgpack
|
||||
// doesn't so we're prepared to error here if not.
|
||||
k, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, err
|
||||
}
|
||||
|
||||
aty, err := impliedType(dec)
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, err
|
||||
}
|
||||
|
||||
if atys == nil {
|
||||
atys = make(map[string]cty.Type)
|
||||
}
|
||||
atys[k] = aty
|
||||
}
|
||||
|
||||
if len(atys) == 0 {
|
||||
return cty.EmptyObject, nil
|
||||
}
|
||||
|
||||
return cty.Object(atys), nil
|
||||
}
|
||||
|
||||
func impliedTupleType(dec *msgpack.Decoder) (cty.Type, error) {
|
||||
// If we get in here then we've already peeked the next code and know
|
||||
// it's some sort of array.
|
||||
l, err := dec.DecodeArrayLen()
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, nil
|
||||
}
|
||||
|
||||
if l == 0 {
|
||||
return cty.EmptyTuple, nil
|
||||
}
|
||||
|
||||
etys := make([]cty.Type, l)
|
||||
|
||||
for i := 0; i < l; i++ {
|
||||
ety, err := impliedType(dec)
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, err
|
||||
}
|
||||
etys[i] = ety
|
||||
}
|
||||
|
||||
return cty.Tuple(etys), nil
|
||||
}
|
3
vendor/github.com/zclconf/go-cty/cty/msgpack/unmarshal.go
generated
vendored
3
vendor/github.com/zclconf/go-cty/cty/msgpack/unmarshal.go
generated
vendored
@ -2,7 +2,6 @@ package msgpack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/vmihailenco/msgpack"
|
||||
@ -80,8 +79,6 @@ func unmarshalPrimitive(dec *msgpack.Decoder, ty cty.Type, path cty.Path) (cty.V
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
|
||||
fmt.Printf("peek %x\n", peek)
|
||||
|
||||
if msgpackCodes.IsFixedNum(peek) {
|
||||
rv, err := dec.DecodeInt64()
|
||||
if err != nil {
|
||||
|
34
vendor/vendor.json
vendored
34
vendor/vendor.json
vendored
@ -2442,50 +2442,50 @@
|
||||
{
|
||||
"checksumSHA1": "4REWNRi5Dg7Kxj1US72+/oVii3Q=",
|
||||
"path": "github.com/zclconf/go-cty/cty",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "3bFMqSB6IxIwhzIw8hyLfd7ayrY=",
|
||||
"path": "github.com/zclconf/go-cty/cty/convert",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "MyyLCGg3RREMllTJyK6ehZl/dHk=",
|
||||
"path": "github.com/zclconf/go-cty/cty/function",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "kcTJOuL131/stXJ4U9tC3SASQLs=",
|
||||
"path": "github.com/zclconf/go-cty/cty/function/stdlib",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "tmCzwfNXOEB1sSO7TKVzilb2vjA=",
|
||||
"path": "github.com/zclconf/go-cty/cty/gocty",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "1ApmO+Q33+Oem/3f6BU6sztJWNc=",
|
||||
"path": "github.com/zclconf/go-cty/cty/json",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "55JE44+FFgAo5WZEC23gp4X5tak=",
|
||||
"checksumSHA1": "8H+2pufGi2Eo3d8cXFfJs31wk+I=",
|
||||
"path": "github.com/zclconf/go-cty/cty/msgpack",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "y5Sk+n6SOspFj8mlyb8swr4DMIs=",
|
||||
"path": "github.com/zclconf/go-cty/cty/set",
|
||||
"revision": "c96d660229f9ad0a16eb5869819ea51e1ed49896",
|
||||
"revisionTime": "2018-06-16T18:02:17Z"
|
||||
"revision": "3ccef1ae92b0ac73b92d86f274f0ff781e2d9b3b",
|
||||
"revisionTime": "2018-07-07T01:23:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "vE43s37+4CJ2CDU6TlOUOYE0K9c=",
|
||||
|
Loading…
Reference in New Issue
Block a user