本文整理汇总了Golang中github.com/attic-labs/noms/types.MakePrimitiveType函数的典型用法代码示例。如果您正苦于以下问题:Golang MakePrimitiveType函数的具体用法?Golang MakePrimitiveType怎么用?Golang MakePrimitiveType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakePrimitiveType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("StructWithUnions",
[]types.Field{
types.Field{"a", types.MakeType(ref.Ref{}, 1), false},
types.Field{"d", types.MakeType(ref.Ref{}, 2), false},
},
types.Choices{},
),
types.MakeStructType("",
[]types.Field{},
types.Choices{
types.Field{"b", types.MakePrimitiveType(types.Float64Kind), false},
types.Field{"c", types.MakePrimitiveType(types.StringKind), false},
},
),
types.MakeStructType("",
[]types.Field{},
types.Choices{
types.Field{"e", types.MakePrimitiveType(types.Float64Kind), false},
types.Field{"f", types.MakePrimitiveType(types.StringKind), false},
},
),
}, []ref.Ref{})
__genPackageInFile_struct_with_unions_CachedRef = types.RegisterPackage(&p)
}
示例2: TestSkipDuplicateTypes
func TestSkipDuplicateTypes(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir("", "codegen_test_")
assert.NoError(err)
defer os.RemoveAll(dir)
leaf1 := types.NewPackage([]types.Type{
types.MakeEnumType("E1", "a", "b"),
types.MakeStructType("S1", []types.Field{
types.Field{"f", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint16Kind)), false},
types.Field{"e", types.MakeType(ref.Ref{}, 0), false},
}, types.Choices{}),
}, []ref.Ref{})
leaf2 := types.NewPackage([]types.Type{
types.MakeStructType("S2", []types.Field{
types.Field{"f", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint16Kind)), false},
}, types.Choices{}),
}, []ref.Ref{})
written := map[string]bool{}
tag1 := code.ToTag(leaf1.Ref())
leaf1Path := filepath.Join(dir, tag1+".go")
generateAndEmit(tag1, leaf1Path, written, depsMap{}, pkg.Parsed{Package: leaf1, Name: "p"})
tag2 := code.ToTag(leaf2.Ref())
leaf2Path := filepath.Join(dir, tag2+".go")
generateAndEmit(tag2, leaf2Path, written, depsMap{}, pkg.Parsed{Package: leaf2, Name: "p"})
code, err := ioutil.ReadFile(leaf2Path)
assert.NoError(err)
assert.NotContains(string(code), "type ListOfUint16")
}
示例3: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeEnumType("QuarterEnum", "Q1", "Q2", "Q3", "Q4"),
types.MakeStructType("Quarter",
[]types.Field{
types.Field{"Year", types.MakePrimitiveType(types.Int32Kind), false},
types.Field{"Quarter", types.MakeType(ref.Ref{}, 0), false},
},
types.Choices{},
),
types.MakeStructType("Key",
[]types.Field{},
types.Choices{
types.Field{"Category", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Quarter", types.MakeType(ref.Ref{}, 1), false},
types.Field{"Region", types.MakePrimitiveType(types.StringKind), false},
types.Field{"RoundType", types.MakeType(ref.Ref{}, 3), false},
types.Field{"Year", types.MakePrimitiveType(types.Int32Kind), false},
},
),
types.MakeEnumType("RoundTypeEnum", "Seed", "SeriesA", "SeriesB", "SeriesC", "SeriesD", "SeriesE", "SeriesF", "SeriesG", "SeriesH", "UnknownRoundType"),
}, []ref.Ref{
ref.Parse("sha1-6c64b08a509e25f9814dbf036489267c957a6fd8"),
ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"),
})
__mainPackageInFile_index_CachedRef = types.RegisterPackage(&p)
}
示例4: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("OptionalStruct",
[]types.Field{
types.Field{"s", types.MakePrimitiveType(types.StringKind), true},
types.Field{"b", types.MakePrimitiveType(types.BoolKind), true},
},
types.Choices{},
),
}, []ref.Ref{})
__genPackageInFile_struct_optional_CachedRef = types.RegisterPackage(&p)
}
示例5: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("Pitch",
[]types.Field{
types.Field{"X", types.MakePrimitiveType(types.Float64Kind), false},
types.Field{"Z", types.MakePrimitiveType(types.Float64Kind), false},
},
types.Choices{},
),
}, []ref.Ref{})
__mainPackageInFile_types_CachedRef = types.RegisterPackage(&p)
}
示例6: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("S",
[]types.Field{
types.Field{"s", types.MakePrimitiveType(types.StringKind), false},
types.Field{"b", types.MakePrimitiveType(types.BoolKind), false},
},
types.Choices{},
),
types.MakeEnumType("E", "e1", "e2", "e3"),
}, []ref.Ref{})
__leafDepPackageInFile_leafDep_CachedRef = types.RegisterPackage(&p)
}
示例7: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("StructWithList",
[]types.Field{
types.Field{"l", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint8Kind)), false},
types.Field{"b", types.MakePrimitiveType(types.BoolKind), false},
types.Field{"s", types.MakePrimitiveType(types.StringKind), false},
types.Field{"i", types.MakePrimitiveType(types.Int64Kind), false},
},
types.Choices{},
),
}, []ref.Ref{})
__genPackageInFile_struct_with_list_CachedRef = types.RegisterPackage(&p)
}
示例8: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("Song",
[]types.Field{
types.Field{"Title", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Artist", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Album", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Year", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Mp3", types.MakePrimitiveType(types.BlobKind), false},
},
types.Choices{},
),
}, []ref.Ref{})
__mainPackageInFile_types_CachedRef = types.RegisterPackage(&p)
}
示例9: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("User",
[]types.Field{
types.Field{"Id", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Name", types.MakePrimitiveType(types.StringKind), false},
types.Field{"Photos", types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"), 0))), false},
},
types.Choices{},
),
}, []ref.Ref{
ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"),
})
__mainPackageInFile_facebook_CachedRef = types.RegisterPackage(&p)
}
示例10: TestGenerateDeps
func TestGenerateDeps(t *testing.T) {
assert := assert.New(t)
ds := datas.NewDataStore(chunks.NewMemoryStore())
dir, err := ioutil.TempDir("", "codegen_test_")
assert.NoError(err)
defer os.RemoveAll(dir)
leaf1 := types.NewPackage([]types.Type{types.MakeEnumType("e1", "a", "b")}, []ref.Ref{})
leaf1Ref := ds.WriteValue(leaf1).TargetRef()
leaf2 := types.NewPackage([]types.Type{types.MakePrimitiveType(types.BoolKind)}, []ref.Ref{})
leaf2Ref := ds.WriteValue(leaf2).TargetRef()
depender := types.NewPackage([]types.Type{}, []ref.Ref{leaf1Ref})
dependerRef := ds.WriteValue(depender).TargetRef()
top := types.NewPackage([]types.Type{}, []ref.Ref{leaf2Ref, dependerRef})
types.RegisterPackage(&top)
localPkgs := refSet{top.Ref(): true}
generateDepCode(filepath.Base(dir), dir, map[string]bool{}, top, localPkgs, ds)
leaf1Path := filepath.Join(dir, code.ToTag(leaf1.Ref())+".go")
leaf2Path := filepath.Join(dir, code.ToTag(leaf2.Ref())+".go")
leaf3Path := filepath.Join(dir, code.ToTag(depender.Ref())+".go")
_, err = os.Stat(leaf1Path)
assert.NoError(err)
_, err = os.Stat(leaf2Path)
assert.NoError(err)
_, err = os.Stat(leaf3Path)
assert.NoError(err)
}
示例11: WriteValue
// WriteValue takes a Value, schedules it to be written it to ds, and returns v.Ref(). v is not guaranteed to be actually written until after a successful Commit().
func (ds *dataStoreCommon) WriteValue(v types.Value) (r types.RefBase) {
if v == nil {
return
}
targetRef := v.Ref()
r = types.PrivateRefFromType(targetRef, types.MakeRefType(v.Type()))
if entry := ds.checkCache(targetRef); entry != nil && entry.Present() {
return
}
// Encoding v causes any child chunks, e.g. internal nodes if v is a meta sequence, to get written. That needs to happen before we try to validate v.
chunk := types.EncodeValue(v, ds)
for _, reachable := range v.Chunks() {
entry := ds.checkCache(reachable.TargetRef())
d.Chk.True(entry != nil && entry.Present(), "Value to write contains ref %s, which points to a non-existent Value.", reachable.TargetRef())
// BUG 1121
// It's possible that entry.Type() will be simply 'Value', but that 'reachable' is actually a properly-typed object -- that is, a Ref to some specific Type. The Chk below would fail, though it's possible that the Type is actually correct. We wouldn't be able to verify without reading it, though, so we'll dig into this later.
targetType := getTargetType(reachable)
if targetType.Equals(types.MakePrimitiveType(types.ValueKind)) {
continue
}
d.Chk.True(entry.Type().Equals(targetType), "Value to write contains ref %s, which points to a value of a different type: %+v != %+v", reachable.TargetRef(), entry.Type(), targetType)
}
ds.cs.Put(chunk) // TODO: DataStore should manage batching and backgrounding Puts.
ds.setCache(targetRef, presentChunk(v.Type()))
return
}
示例12: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveType(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveType(types.Float32Kind), false},
},
types.Choices{},
),
types.MakeStructType("Georectangle",
[]types.Field{
types.Field{"TopLeft", types.MakeType(ref.Ref{}, 0), false},
types.Field{"BottomRight", types.MakeType(ref.Ref{}, 0), false},
},
types.Choices{},
),
}, []ref.Ref{})
__commonPackageInFile_geo_CachedRef = types.RegisterPackage(&p)
}
示例13: SetupTest
func (suite *ImportTestSuite) SetupTest() {
suite.vrw = datas.NewDataStore(chunks.NewMemoryStore())
ns := types.MakeStructType("NestedDepStruct", []types.Field{}, types.Choices{
types.Field{"b", types.MakePrimitiveType(types.BoolKind), false},
types.Field{"i", types.MakePrimitiveType(types.Int8Kind), false},
})
suite.nested = types.NewPackage([]types.Type{ns}, []ref.Ref{})
suite.nestedRef = suite.vrw.WriteValue(suite.nested).TargetRef()
fs := types.MakeStructType("ForeignStruct", []types.Field{
types.Field{"b", types.MakeType(ref.Ref{}, 1), false},
types.Field{"n", types.MakeType(suite.nestedRef, 0), false},
},
types.Choices{})
fe := types.MakeEnumType("ForeignEnum", "uno", "dos")
suite.imported = types.NewPackage([]types.Type{fs, fe}, []ref.Ref{suite.nestedRef})
suite.importRef = suite.vrw.WriteValue(suite.imported).TargetRef()
}
示例14: TestDetectFreeVariable
func (suite *ImportTestSuite) TestDetectFreeVariable() {
ls := types.MakeStructType("Local", []types.Field{
types.Field{"b", types.MakePrimitiveType(types.BoolKind), false},
types.Field{"n", types.MakeUnresolvedType("", "OtherLocal"), false},
},
types.Choices{})
suite.Panics(func() {
inter := intermediate{Types: []types.Type{ls}}
resolveLocalOrdinals(&inter)
})
}
示例15: init
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
p := types.NewPackage([]types.Type{
types.MakeStructType("Date",
[]types.Field{
types.Field{"MsSinceEpoch", types.MakePrimitiveType(types.Int64Kind), false},
},
types.Choices{},
),
}, []ref.Ref{})
__commonPackageInFile_date_CachedRef = types.RegisterPackage(&p)
}