• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.Value类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/attic-labs/noms/types.Value的典型用法代码示例。如果您正苦于以下问题:Golang Value类的具体用法?Golang Value怎么用?Golang Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Value类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestEnumIsValue

func TestEnumIsValue(t *testing.T) {
	ds := datas.NewDataStore(chunks.NewMemoryStore())
	var v types.Value = gen.NewEnumStruct()
	ref := ds.WriteValue(v).TargetRef()
	v2 := ds.ReadValue(ref)
	assert.True(t, v.Equals(v2))
}
开发者ID:arv,项目名称:noms-old,代码行数:7,代码来源:enum_struct_test.go


示例2: TestEnumValue

func TestEnumValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.EnumStructDef{gen.Switch}
	var st types.Value
	st = def.New()
	st2 := st.(gen.EnumStruct)
	assert.True(st.Equals(st2))
}
开发者ID:arv,项目名称:noms-old,代码行数:9,代码来源:enum_struct_test.go


示例3: TestValueMapValue

func TestValueMapValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)}
	var m types.Value
	m = def.New()
	m2 := m.(gen.MapOfStringToValue)
	assert.True(m.Equals(m2))
}
开发者ID:arv,项目名称:noms-old,代码行数:9,代码来源:map_test.go


示例4: TestValue

func TestValue(t *testing.T) {
	assert := assert.New(t)

	def := gen.StructDef{"hi", true}
	var st types.Value
	st = def.New()
	st2 := st.(gen.Struct)
	assert.True(st.Equals(st2))
}
开发者ID:arv,项目名称:noms-old,代码行数:9,代码来源:struct_test.go


示例5: 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
}
开发者ID:arv,项目名称:noms-old,代码行数:32,代码来源:datastore_common.go


示例6: TestReadWriteCache

func TestReadWriteCache(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	var v types.Value = types.Bool(true)
	assert.NotEqual(ref.Ref{}, ds.WriteValue(v))
	assert.Equal(1, cs.Writes)
	r := ds.WriteValue(v).TargetRef()
	assert.Equal(1, cs.Writes)

	v = ds.ReadValue(r)
	assert.True(v.Equals(types.Bool(true)))
}
开发者ID:arv,项目名称:noms-old,代码行数:14,代码来源:datastore_test.go


示例7: processPitches

func processPitches(v types.Value) (pitches []PitchDef) {
	switch v := v.(type) {
	case types.List:
		for i := uint64(0); i < v.Len(); i++ {
			pitches = append(pitches, processPitches(v.Get(i))...)
		}
	case MapOfStringToValue:
		if checkPitch(v) {
			pitches = append(pitches, getPitch(v))
		}
	case nil:
		return // Yes, an at-bat can end with no pitches thrown.
	default:
		d.Chk.Fail("Impossible pitch", "No pitch should be %+v, which is of type %s!\n", v, reflect.TypeOf(v).String())
	}
	return
}
开发者ID:arv,项目名称:noms-old,代码行数:17,代码来源:index.go


示例8: TestStructIsValue

func TestStructIsValue(t *testing.T) {
	assert := assert.New(t)
	ds := datas.NewDataStore(chunks.NewMemoryStore())
	var v types.Value = gen.StructWithListDef{
		L: gen.ListOfUint8Def{0, 1, 2},
		B: true,
		S: "world",
		I: 42,
	}.New()

	ref := ds.WriteValue(v).TargetRef()
	v2 := ds.ReadValue(ref)
	assert.True(v.Equals(v2))

	s2 := v2.(gen.StructWithList)
	assert.True(s2.L().Equals(gen.NewListOfUint8().Append(0, 1, 2)))
	assert.True(s2.B())
	assert.Equal("world", s2.S())
	assert.Equal(int64(42), s2.I())
}
开发者ID:arv,项目名称:noms-old,代码行数:20,代码来源:struct_with_list_test.go


示例9: ValueToListAndElemDesc

// ValueToListAndElemDesc ensures that v is a types.List of structs, pulls the types.StructDesc that describes the elements of v out of vr, and returns the List and related StructDesc.
func ValueToListAndElemDesc(v types.Value, vr types.ValueReader) (types.List, types.StructDesc) {
	d.Exp.Equal(types.ListKind, v.Type().Desc.Kind(),
		"Dataset must be List<>, found: %s", v.Type().Desc.Describe())

	u := v.Type().Desc.(types.CompoundDesc).ElemTypes[0]
	d.Exp.Equal(types.UnresolvedKind, u.Desc.Kind(),
		"List<> must be UnresolvedKind, found: %s", u.Desc.Describe())

	pkg := types.ReadPackage(u.PackageRef(), vr)
	d.Exp.Equal(types.PackageKind, pkg.Type().Desc.Kind(),
		"Failed to read package: %s", pkg.Type().Desc.Describe())

	desc := pkg.Types()[u.Ordinal()].Desc
	d.Exp.Equal(types.StructKind, desc.Kind(), "Did not find Struct: %s", desc.Describe())
	return v.(types.List), desc.(types.StructDesc)
}
开发者ID:arv,项目名称:noms-old,代码行数:17,代码来源:write.go


示例10: Equals

func (s __unionOfEOfFloat64AndFOfString) Equals(other types.Value) bool {
	return other != nil && __typeFor__unionOfEOfFloat64AndFOfString.Equals(other.Type()) && s.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:struct_with_unions.noms.go


示例11: Equals

func (s EnumStruct) Equals(other types.Value) bool {
	return other != nil && __typeForEnumStruct.Equals(other.Type()) && s.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:enum_struct.noms.go


示例12: Equals

func (s StructPrimitives) Equals(other types.Value) bool {
	return other != nil && __typeForStructPrimitives.Equals(other.Type()) && s.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:struct_primitives.noms.go


示例13: Equals

func (r RefOfMapOfStringToValue) Equals(other types.Value) bool {
	return other != nil && __typeForRefOfMapOfStringToValue.Equals(other.Type()) && r.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:types.noms.go


示例14: Equals

func (s SetOfFloat32) Equals(other types.Value) bool {
	return other != nil && __typeForSetOfFloat32.Equals(other.Type()) && s.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:ref.noms.go


示例15: Equals

func (m MapOfStringToRefOfCompany) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfStringToRefOfCompany.Equals(other.Type()) && m.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:sha1_6c64b08.go


示例16: Equals

func (s Geoposition) Equals(other types.Value) bool {
	return other != nil && __typeForGeoposition.Equals(other.Type()) && s.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:geo.noms.go


示例17: Equals

func (m MapOfSizeToString) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfSizeToString.Equals(other.Type()) && m.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:photo.noms.go


示例18: Equals

func (m MapOfStringToRefOfListOfPitch) Equals(other types.Value) bool {
	return other != nil && __typeForMapOfStringToRefOfListOfPitch.Equals(other.Type()) && m.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:types.noms.go


示例19: Equals

func (r RefOfRemotePhoto) Equals(other types.Value) bool {
	return other != nil && __typeForRefOfRemotePhoto.Equals(other.Type()) && r.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:facebook.noms.go


示例20: Equals

func (s SetOfRefOfCommit) Equals(other types.Value) bool {
	return other != nil && __typeForSetOfRefOfCommit.Equals(other.Type()) && s.Ref() == other.Ref()
}
开发者ID:arv,项目名称:noms-old,代码行数:3,代码来源:types.noms.go



注:本文中的github.com/attic-labs/noms/types.Value类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.ValueReader类代码示例发布时间:2022-05-24
下一篇:
Golang types.Type类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap