mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-07 16:17:37 -06:00
dolt/go/store: marshall: Thread *Format.
This commit is contained in:
committed by
Brian Hendriks
parent
8459c68b0b
commit
072d5cd178
@@ -126,7 +126,7 @@ func MustMarshalOpt(ctx context.Context, vrw types.ValueReadWriter, v interface{
|
||||
nt := nomsTags{
|
||||
set: opt.Set,
|
||||
}
|
||||
encoder := typeEncoder(rv.Type(), map[string]reflect.Type{}, nt)
|
||||
encoder := typeEncoder(vrw.Format(), rv.Type(), map[string]reflect.Type{}, nt)
|
||||
return encoder(ctx, rv, vrw)
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ func marshalerEncoder(t reflect.Type) encoderFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func typeEncoder(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTags) encoderFunc {
|
||||
func typeEncoder(format *types.Format, t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTags) encoderFunc {
|
||||
if t.Implements(marshalerInterface) {
|
||||
return marshalerEncoder(t)
|
||||
}
|
||||
@@ -254,7 +254,7 @@ func typeEncoder(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsT
|
||||
case reflect.String:
|
||||
return stringEncoder
|
||||
case reflect.Struct:
|
||||
return structEncoder(t, seenStructs)
|
||||
return structEncoder(format, t, seenStructs)
|
||||
case reflect.Slice, reflect.Array:
|
||||
if shouldEncodeAsSet(t, tags) {
|
||||
return setFromListEncoder(t, seenStructs)
|
||||
@@ -269,7 +269,7 @@ func typeEncoder(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsT
|
||||
return func(ctx context.Context, v reflect.Value, vrw types.ValueReadWriter) types.Value {
|
||||
// Get the dynamic type.
|
||||
v2 := reflect.ValueOf(v.Interface())
|
||||
return typeEncoder(v2.Type(), seenStructs, tags)(ctx, v2, vrw)
|
||||
return typeEncoder(format, v2.Type(), seenStructs, tags)(ctx, v2, vrw)
|
||||
}
|
||||
case reflect.Ptr:
|
||||
// Allow implementations of types.Value (like *types.Type)
|
||||
@@ -290,7 +290,7 @@ func getStructName(t reflect.Type) string {
|
||||
return strings.Title(t.Name())
|
||||
}
|
||||
|
||||
func structEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderFunc {
|
||||
func structEncoder(format *types.Format, t reflect.Type, seenStructs map[string]reflect.Type) encoderFunc {
|
||||
if t.Implements(nomsValueInterface) {
|
||||
return nomsValueEncoder
|
||||
}
|
||||
@@ -303,7 +303,7 @@ func structEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderF
|
||||
structName := getStructName(t)
|
||||
|
||||
seenStructs[t.Name()] = t
|
||||
fields, knownShape, originalFieldIndex := typeFields(t, seenStructs, false, false)
|
||||
fields, knownShape, originalFieldIndex := typeFields(format, t, seenStructs, false, false)
|
||||
if knownShape {
|
||||
fieldNames := make([]string, len(fields))
|
||||
for i, f := range fields {
|
||||
@@ -316,7 +316,7 @@ func structEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderF
|
||||
for i, f := range fields {
|
||||
values[i] = f.encoder(ctx, v.FieldByIndex(f.index), vrw)
|
||||
}
|
||||
return structTemplate.NewStruct(types.Format_7_18, values)
|
||||
return structTemplate.NewStruct(format, values)
|
||||
}
|
||||
} else if originalFieldIndex == nil {
|
||||
// Slower path: cannot precompute the Noms type since there are Noms collections,
|
||||
@@ -330,7 +330,7 @@ func structEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderF
|
||||
}
|
||||
data[f.name] = f.encoder(ctx, fv, vrw)
|
||||
}
|
||||
return types.NewStruct(types.Format_7_18, structName, data)
|
||||
return types.NewStruct(format, structName, data)
|
||||
}
|
||||
} else {
|
||||
// Slowest path - we are extending some other struct. We need to start with the
|
||||
@@ -339,7 +339,7 @@ func structEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderF
|
||||
fv := v.FieldByIndex(originalFieldIndex)
|
||||
ret := fv.Interface().(types.Struct)
|
||||
if ret.IsZeroValue() {
|
||||
ret = types.NewStruct(types.Format_7_18, structName, nil)
|
||||
ret = types.NewStruct(format, structName, nil)
|
||||
}
|
||||
for _, f := range fields {
|
||||
fv := v.FieldByIndex(f.index)
|
||||
@@ -462,7 +462,7 @@ func validateField(f reflect.StructField, t reflect.Type) {
|
||||
}
|
||||
}
|
||||
|
||||
func typeFields(t reflect.Type, seenStructs map[string]reflect.Type, computeType, embedded bool) (fields fieldSlice, knownShape bool, originalFieldIndex []int) {
|
||||
func typeFields(format *types.Format, t reflect.Type, seenStructs map[string]reflect.Type, computeType, embedded bool) (fields fieldSlice, knownShape bool, originalFieldIndex []int) {
|
||||
knownShape = true
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
index := make([]int, 1)
|
||||
@@ -479,7 +479,7 @@ func typeFields(t reflect.Type, seenStructs map[string]reflect.Type, computeType
|
||||
}
|
||||
|
||||
if f.Anonymous && f.PkgPath == "" && !tags.hasName {
|
||||
embeddedFields, embeddedKnownShape, embeddedOriginalFieldIndex := typeFields(f.Type, seenStructs, computeType, true)
|
||||
embeddedFields, embeddedKnownShape, embeddedOriginalFieldIndex := typeFields(format, f.Type, seenStructs, computeType, true)
|
||||
if embeddedOriginalFieldIndex != nil {
|
||||
originalFieldIndex = append(index, embeddedOriginalFieldIndex...)
|
||||
}
|
||||
@@ -496,7 +496,7 @@ func typeFields(t reflect.Type, seenStructs map[string]reflect.Type, computeType
|
||||
var nt *types.Type
|
||||
validateField(f, t)
|
||||
if computeType {
|
||||
nt = encodeType(f.Type, seenStructs, tags)
|
||||
nt = encodeType(format, f.Type, seenStructs, tags)
|
||||
if nt == nil {
|
||||
knownShape = false
|
||||
}
|
||||
@@ -508,7 +508,7 @@ func typeFields(t reflect.Type, seenStructs map[string]reflect.Type, computeType
|
||||
|
||||
fields = append(fields, field{
|
||||
name: tags.name,
|
||||
encoder: typeEncoder(f.Type, seenStructs, tags),
|
||||
encoder: typeEncoder(format, f.Type, seenStructs, tags),
|
||||
index: index,
|
||||
nomsType: nt,
|
||||
omitEmpty: tags.omitEmpty,
|
||||
@@ -546,7 +546,7 @@ func listEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderFun
|
||||
}
|
||||
|
||||
encoderCache.set(t, e)
|
||||
elemEncoder = typeEncoder(t.Elem(), seenStructs, nomsTags{})
|
||||
elemEncoder = typeEncoder(types.Format_7_18, t.Elem(), seenStructs, nomsTags{})
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -573,7 +573,7 @@ func setFromListEncoder(t reflect.Type, seenStructs map[string]reflect.Type) enc
|
||||
}
|
||||
|
||||
setEncoderCache.set(t, e)
|
||||
elemEncoder = typeEncoder(t.Elem(), seenStructs, nomsTags{})
|
||||
elemEncoder = typeEncoder(types.Format_7_18, t.Elem(), seenStructs, nomsTags{})
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ func setEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderFunc
|
||||
}
|
||||
|
||||
setEncoderCache.set(t, e)
|
||||
encoder = typeEncoder(t.Key(), seenStructs, nomsTags{})
|
||||
encoder = typeEncoder(types.Format_7_18, t.Key(), seenStructs, nomsTags{})
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -628,8 +628,8 @@ func mapEncoder(t reflect.Type, seenStructs map[string]reflect.Type) encoderFunc
|
||||
}
|
||||
|
||||
encoderCache.set(t, e)
|
||||
keyEncoder = typeEncoder(t.Key(), seenStructs, nomsTags{})
|
||||
valueEncoder = typeEncoder(t.Elem(), seenStructs, nomsTags{})
|
||||
keyEncoder = typeEncoder(types.Format_7_18, t.Key(), seenStructs, nomsTags{})
|
||||
valueEncoder = typeEncoder(types.Format_7_18, t.Elem(), seenStructs, nomsTags{})
|
||||
return e
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ import (
|
||||
//
|
||||
// If a Go struct contains a noms tag with original the field is skipped since
|
||||
// the Noms type depends on the original Noms value which is not available.
|
||||
func MarshalType(v interface{}) (nt *types.Type, err error) {
|
||||
return MarshalTypeOpt(v, Opt{})
|
||||
func MarshalType(format *types.Format, v interface{}) (nt *types.Type, err error) {
|
||||
return MarshalTypeOpt(format, v, Opt{})
|
||||
}
|
||||
|
||||
// MarshalTypeOpt is like MarshalType but with additional options.
|
||||
func MarshalTypeOpt(v interface{}, opt Opt) (nt *types.Type, err error) {
|
||||
func MarshalTypeOpt(format *types.Format, v interface{}, opt Opt) (nt *types.Type, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
switch r := r.(type) {
|
||||
@@ -40,23 +40,23 @@ func MarshalTypeOpt(v interface{}, opt Opt) (nt *types.Type, err error) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
nt = MustMarshalTypeOpt(v, opt)
|
||||
nt = MustMarshalTypeOpt(format, v, opt)
|
||||
return
|
||||
}
|
||||
|
||||
// MustMarshalType computes a Noms type from a Go type or panics if there is an
|
||||
// error.
|
||||
func MustMarshalType(v interface{}) (nt *types.Type) {
|
||||
return MustMarshalTypeOpt(v, Opt{})
|
||||
func MustMarshalType(format *types.Format, v interface{}) (nt *types.Type) {
|
||||
return MustMarshalTypeOpt(format, v, Opt{})
|
||||
}
|
||||
|
||||
// MustMarshalTypeOpt is like MustMarshalType but provides additional options.
|
||||
func MustMarshalTypeOpt(v interface{}, opt Opt) (nt *types.Type) {
|
||||
func MustMarshalTypeOpt(format *types.Format, v interface{}, opt Opt) (nt *types.Type) {
|
||||
rv := reflect.ValueOf(v)
|
||||
tags := nomsTags{
|
||||
set: opt.Set,
|
||||
}
|
||||
nt = encodeType(rv.Type(), map[string]reflect.Type{}, tags)
|
||||
nt = encodeType(format, rv.Type(), map[string]reflect.Type{}, tags)
|
||||
|
||||
if nt == nil {
|
||||
panic(&UnsupportedTypeError{Type: rv.Type()})
|
||||
@@ -77,7 +77,7 @@ type TypeMarshaler interface {
|
||||
var typeOfTypesType = reflect.TypeOf((*types.Type)(nil))
|
||||
var typeMarshalerInterface = reflect.TypeOf((*TypeMarshaler)(nil)).Elem()
|
||||
|
||||
func encodeType(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTags) *types.Type {
|
||||
func encodeType(format *types.Format, t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTags) *types.Type {
|
||||
if t.Implements(typeMarshalerInterface) {
|
||||
v := reflect.Zero(t)
|
||||
typ, err := v.Interface().(TypeMarshaler).MarshalNomsType()
|
||||
@@ -137,9 +137,9 @@ func encodeType(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTa
|
||||
case reflect.String:
|
||||
return types.StringType
|
||||
case reflect.Struct:
|
||||
return structEncodeType(t, seenStructs)
|
||||
return structEncodeType(format, t, seenStructs)
|
||||
case reflect.Array, reflect.Slice:
|
||||
elemType := encodeType(t.Elem(), seenStructs, nomsTags{})
|
||||
elemType := encodeType(format, t.Elem(), seenStructs, nomsTags{})
|
||||
if elemType == nil {
|
||||
break
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func encodeType(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTa
|
||||
}
|
||||
return types.MakeListType(elemType)
|
||||
case reflect.Map:
|
||||
keyType := encodeType(t.Key(), seenStructs, nomsTags{})
|
||||
keyType := encodeType(format, t.Key(), seenStructs, nomsTags{})
|
||||
if keyType == nil {
|
||||
break
|
||||
}
|
||||
@@ -157,7 +157,7 @@ func encodeType(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTa
|
||||
return types.MakeSetType(keyType)
|
||||
}
|
||||
|
||||
valueType := encodeType(t.Elem(), seenStructs, nomsTags{})
|
||||
valueType := encodeType(format, t.Elem(), seenStructs, nomsTags{})
|
||||
if valueType != nil {
|
||||
return types.MakeMapType(keyType, valueType)
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func encodeType(t reflect.Type, seenStructs map[string]reflect.Type, tags nomsTa
|
||||
// the type but we also need to look at the value. In these cases this returns
|
||||
// nil and we have to wait until we have a value to be able to determine the
|
||||
// type.
|
||||
func structEncodeType(t reflect.Type, seenStructs map[string]reflect.Type) *types.Type {
|
||||
func structEncodeType(format *types.Format, t reflect.Type, seenStructs map[string]reflect.Type) *types.Type {
|
||||
name := getStructName(t)
|
||||
if name != "" {
|
||||
if _, ok := seenStructs[name]; ok {
|
||||
@@ -181,7 +181,7 @@ func structEncodeType(t reflect.Type, seenStructs map[string]reflect.Type) *type
|
||||
seenStructs[name] = t
|
||||
}
|
||||
|
||||
fields, knownShape, _ := typeFields(t, seenStructs, true, false)
|
||||
fields, knownShape, _ := typeFields(format, t, seenStructs, true, false)
|
||||
|
||||
var structType *types.Type
|
||||
if knownShape {
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestMarshalTypeType(tt *testing.T) {
|
||||
t := func(exp *types.Type, ptr interface{}) {
|
||||
p := reflect.ValueOf(ptr)
|
||||
assert.NotEqual(tt, reflect.Ptr, p.Type().Kind())
|
||||
actual, err := MarshalType(p.Interface())
|
||||
actual, err := MarshalType(types.Format_7_18, p.Interface())
|
||||
assert.NoError(tt, err)
|
||||
assert.NotNil(tt, actual, "%#v", p.Interface())
|
||||
assert.True(tt, exp.Equals(types.Format_7_18, actual))
|
||||
@@ -106,7 +106,7 @@ func TestMarshalTypeType(tt *testing.T) {
|
||||
|
||||
//
|
||||
func assertMarshalTypeErrorMessage(t *testing.T, v interface{}, expectedMessage string) {
|
||||
_, err := MarshalType(v)
|
||||
_, err := MarshalType(types.Format_7_18, v)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, expectedMessage, err.Error())
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func TestMarshalTypeEmbeddedStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
var s TestStruct
|
||||
typ := MustMarshalType(s)
|
||||
typ := MustMarshalType(types.Format_7_18, s)
|
||||
|
||||
assert.True(types.MakeStructTypeFromFields("TestStruct", types.FieldMap{
|
||||
"a": types.FloaTType,
|
||||
@@ -147,7 +147,7 @@ func TestMarshalTypeEmbeddedStructSkip(t *testing.T) {
|
||||
}
|
||||
|
||||
var s TestStruct
|
||||
typ := MustMarshalType(s)
|
||||
typ := MustMarshalType(types.Format_7_18, s)
|
||||
|
||||
assert.True(types.MakeStructTypeFromFields("TestStruct", types.FieldMap{
|
||||
"a": types.FloaTType,
|
||||
@@ -166,7 +166,7 @@ func TestMarshalTypeEmbeddedStructNamed(t *testing.T) {
|
||||
}
|
||||
|
||||
var s TestStruct
|
||||
typ := MustMarshalType(s)
|
||||
typ := MustMarshalType(types.Format_7_18, s)
|
||||
|
||||
assert.True(types.MakeStructTypeFromFields("TestStruct", types.FieldMap{
|
||||
"a": types.FloaTType,
|
||||
@@ -191,7 +191,7 @@ func TestMarshalTypeEncodeTaggingSkip(t *testing.T) {
|
||||
Def bool
|
||||
}
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructTypeFromFields("S", types.FieldMap{
|
||||
"def": types.BoolType,
|
||||
@@ -207,7 +207,7 @@ func TestMarshalTypeNamedFields(t *testing.T) {
|
||||
Ccc string
|
||||
}
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructTypeFromFields("S", types.FieldMap{
|
||||
"a": types.FloaTType,
|
||||
@@ -231,7 +231,7 @@ func TestMarshalTypeOmitEmpty(t *testing.T) {
|
||||
String string `noms:",omitempty"`
|
||||
}
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructType("S", types.StructField{"string", types.StringType, true}).Equals(types.Format_7_18, typ))
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func ExampleMarshalType() {
|
||||
Female bool
|
||||
}
|
||||
var person Person
|
||||
personNomsType, err := MarshalType(person)
|
||||
personNomsType, err := MarshalType(types.Format_7_18, person)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
@@ -260,7 +260,7 @@ func TestMarshalTypeSlice(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
s := []string{"a", "b", "c"}
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeListType(types.StringType).Equals(types.Format_7_18, typ))
|
||||
}
|
||||
@@ -269,7 +269,7 @@ func TestMarshalTypeArray(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
a := [3]int{1, 2, 3}
|
||||
typ, err := MarshalType(a)
|
||||
typ, err := MarshalType(types.Format_7_18, a)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeListType(types.FloaTType).Equals(types.Format_7_18, typ))
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func TestMarshalTypeStructWithSlice(t *testing.T) {
|
||||
List []int
|
||||
}
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructTypeFromFields("S", types.FieldMap{
|
||||
"list": types.MakeListType(types.FloaTType),
|
||||
@@ -296,7 +296,7 @@ func TestMarshalTypeRecursive(t *testing.T) {
|
||||
Children []Node
|
||||
}
|
||||
var n Node
|
||||
typ, err := MarshalType(n)
|
||||
typ, err := MarshalType(types.Format_7_18, n)
|
||||
assert.NoError(err)
|
||||
|
||||
typ2 := types.MakeStructType("Node",
|
||||
@@ -316,7 +316,7 @@ func TestMarshalTypeMap(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var m map[string]int
|
||||
typ, err := MarshalType(m)
|
||||
typ, err := MarshalType(types.Format_7_18, m)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeMapType(types.StringType, types.FloaTType).Equals(types.Format_7_18, typ))
|
||||
|
||||
@@ -325,7 +325,7 @@ func TestMarshalTypeMap(t *testing.T) {
|
||||
}
|
||||
|
||||
var m2 map[S]bool
|
||||
typ, err = MarshalType(m2)
|
||||
typ, err = MarshalType(types.Format_7_18, m2)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeMapType(
|
||||
types.MakeStructTypeFromFields("S", types.FieldMap{
|
||||
@@ -348,7 +348,7 @@ func TestMarshalTypeSet(t *testing.T) {
|
||||
H string `noms:",set"`
|
||||
}
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
|
||||
emptyStructType := types.MakeStructTypeFromFields("", types.FieldMap{})
|
||||
@@ -396,7 +396,7 @@ func TestEncodeTypeOpt(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, t := range tc {
|
||||
r, err := MarshalTypeOpt(t.in, t.opt)
|
||||
r, err := MarshalTypeOpt(types.Format_7_18, t.in, t.opt)
|
||||
assert.True(t.wantType.Equals(types.Format_7_18, r))
|
||||
assert.Nil(err)
|
||||
}
|
||||
@@ -412,7 +412,7 @@ func TestMarshalTypeSetWithTags(t *testing.T) {
|
||||
}
|
||||
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructType("S",
|
||||
types.StructField{"foo", types.MakeSetType(types.FloaTType), false},
|
||||
@@ -427,7 +427,7 @@ func TestMarshalTypeInvalidTag(t *testing.T) {
|
||||
F string `noms:",omitEmpty"`
|
||||
}
|
||||
var s S
|
||||
_, err := MarshalType(s)
|
||||
_, err := MarshalType(types.Format_7_18, s)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, `Unrecognized tag: omitEmpty`, err.Error())
|
||||
}
|
||||
@@ -442,7 +442,7 @@ func TestMarshalTypeCanSkipUnexportedField(t *testing.T) {
|
||||
var s S
|
||||
assert.False(s.notExported) // here to remove compiler warning about notExported not being used.
|
||||
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructTypeFromFields("S", types.FieldMap{
|
||||
"abc": types.FloaTType,
|
||||
@@ -458,7 +458,7 @@ func TestMarshalTypeOriginal(t *testing.T) {
|
||||
}
|
||||
|
||||
var s S
|
||||
typ, err := MarshalType(s)
|
||||
typ, err := MarshalType(types.Format_7_18, s)
|
||||
assert.NoError(err)
|
||||
assert.True(types.MakeStructType("S",
|
||||
types.StructField{"foo", types.FloaTType, true},
|
||||
@@ -476,7 +476,7 @@ func TestMarshalTypeNomsTypes(t *testing.T) {
|
||||
Type *types.Type
|
||||
}
|
||||
var s S
|
||||
assert.True(MustMarshalType(s).Equals(types.Format_7_18,
|
||||
assert.True(MustMarshalType(types.Format_7_18, s).Equals(types.Format_7_18,
|
||||
types.MakeStructTypeFromFields("S", types.FieldMap{
|
||||
"blob": types.BlobType,
|
||||
"bool": types.BoolType,
|
||||
@@ -495,7 +495,7 @@ func TestTypeMarshalerPrimitiveType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var u primitiveType
|
||||
typ := MustMarshalType(u)
|
||||
typ := MustMarshalType(types.Format_7_18, u)
|
||||
assert.Equal(types.FloaTType, typ)
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ func TestTypeMarshalerPrimitiveSliceType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var u primitiveSliceType
|
||||
typ := MustMarshalType(u)
|
||||
typ := MustMarshalType(types.Format_7_18, u)
|
||||
assert.Equal(types.StringType, typ)
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ func TestTypeMarshalerPrimitiveMapType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var u primitiveMapType
|
||||
typ := MustMarshalType(u)
|
||||
typ := MustMarshalType(types.Format_7_18, u)
|
||||
assert.Equal(types.MakeSetType(types.StringType), typ)
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ func TestTypeMarshalerPrimitiveStructTypeNoMarshalNomsType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var u primitiveStructType
|
||||
_, err := MarshalType(u)
|
||||
_, err := MarshalType(types.Format_7_18, u)
|
||||
assert.Error(err)
|
||||
assert.Equal("cannot marshal type which implements marshal.Marshaler, perhaps implement marshal.TypeMarshaler for marshal.primitiveStructType", err.Error())
|
||||
}
|
||||
@@ -540,7 +540,7 @@ func TestTypeMarshalerBuiltinType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var u builtinType
|
||||
typ := MustMarshalType(u)
|
||||
typ := MustMarshalType(types.Format_7_18, u)
|
||||
assert.Equal(types.StringType, typ)
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ func TestTypeMarshalerWrapperMarshalerType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var u wrappedMarshalerType
|
||||
typ := MustMarshalType(u)
|
||||
typ := MustMarshalType(types.Format_7_18, u)
|
||||
assert.Equal(types.FloaTType, typ)
|
||||
}
|
||||
|
||||
@@ -573,21 +573,21 @@ func TestTypeMarshalerErrors(t *testing.T) {
|
||||
|
||||
expErr := errors.New("expected error")
|
||||
var m1 returnsMarshalerError
|
||||
_, actErr := MarshalType(m1)
|
||||
_, actErr := MarshalType(types.Format_7_18, m1)
|
||||
assert.Equal(expErr, actErr)
|
||||
|
||||
var m2 returnsMarshalerNil
|
||||
assert.Panics(func() { MarshalType(m2) })
|
||||
assert.Panics(func() { MarshalType(types.Format_7_18, m2) })
|
||||
|
||||
var m3 panicsMarshaler
|
||||
assert.Panics(func() { MarshalType(m3) })
|
||||
assert.Panics(func() { MarshalType(types.Format_7_18, m3) })
|
||||
}
|
||||
|
||||
func TestMarshalTypeStructName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var ts TestStructWithNameImpl
|
||||
typ := MustMarshalType(ts)
|
||||
typ := MustMarshalType(types.Format_7_18, ts)
|
||||
assert.True(types.MakeStructType("A", types.StructField{"x", types.FloaTType, false}).Equals(types.Format_7_18, typ), typ.Describe(context.Background()))
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ func TestMarshalTypeStructName2(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var ts TestStructWithNameImpl2
|
||||
typ := MustMarshalType(ts)
|
||||
typ := MustMarshalType(types.Format_7_18, ts)
|
||||
assert.True(types.MakeStructType("", types.StructField{"x", types.FloaTType, false}).Equals(types.Format_7_18, typ), typ.Describe(context.Background()))
|
||||
}
|
||||
|
||||
@@ -614,7 +614,7 @@ func (f OutFace) MarshalNomsStructName() string {
|
||||
|
||||
func TestMarshalTypeOutface(t *testing.T) {
|
||||
|
||||
typ := MustMarshalType(OutPhoto{})
|
||||
typ := MustMarshalType(types.Format_7_18, OutPhoto{})
|
||||
expectedType := nomdl.MustParseType(`Struct OutPhoto {
|
||||
faces: Set<Struct Face {
|
||||
blob: Ref<Value>,
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
// datas/Database. Required to avoid import cycle between this package and the
|
||||
// package that implements Value reading.
|
||||
type ValueReader interface {
|
||||
Format() *Format
|
||||
ReadValue(ctx context.Context, h hash.Hash) Value
|
||||
ReadManyValues(ctx context.Context, hashes hash.HashSlice) ValueSlice
|
||||
}
|
||||
@@ -120,6 +121,11 @@ func (lvs *ValueStore) ChunkStore() chunks.ChunkStore {
|
||||
return lvs.cs
|
||||
}
|
||||
|
||||
func (lvs *ValueStore) Format() *Format {
|
||||
lvs.versOnce.Do(lvs.expectVersion)
|
||||
return lvs.format
|
||||
}
|
||||
|
||||
// ReadValue reads and decodes a value from lvs. It is not considered an error
|
||||
// for the requested chunk to be empty; in this case, the function simply
|
||||
// returns nil.
|
||||
|
||||
@@ -110,7 +110,7 @@ func TestMarshalType(t *testing.T) {
|
||||
defer vs.Close()
|
||||
|
||||
dt := DateTime{time.Unix(0, 0)}
|
||||
typ := marshal.MustMarshalType(dt)
|
||||
typ := marshal.MustMarshalType(types.Format_7_18, dt)
|
||||
assert.Equal(DateTimeType, typ)
|
||||
|
||||
v := marshal.MustMarshal(context.Background(), vs, dt)
|
||||
|
||||
Reference in New Issue
Block a user