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

Golang intern.Packer类代码示例

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

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



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

示例1: p

func p(packer intern.Packer, xs ...interface{}) intern.Packed {
	args := make([]intern.Packed, len(xs))
	for i, x := range xs {
		args[i] = pack(packer, x)
	}
	return packer.PackList(args)
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:7,代码来源:pickle.go


示例2: pair

func pair(packer intern.Packer, a, b interface{}) intern.Packed {
	args := make([]intern.Packed, 2)
	for i, x := range []interface{}{a, b} {
		args[i] = pack(packer, x)
	}
	return packer.PackPair(args[0], args[1])
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:7,代码来源:pickle.go


示例3: unpickleC

func unpickleC(packer intern.Packer, kind int, packed intern.Packed) (C, bool) {
	switch kind {
	case compoundC:
		result := &CompoundC{}
		if packed, args, ok := packer.UnpackPair(packed); ok {
			if args, ok := packer.UnpackList(args); ok {
				result.args = make([]C, len(args))
				for i, arg := range args {
					unpacked, ok := packer.UnpackPickler(arg, &CompoundC{})
					if !ok {
						return nil, false
					}
					result.args[i] = unpacked.(C)
				}
				id, ok := unpickleTemplateID(packer, packed)
				if !ok {
					return nil, false
				}
				result.TemplateID = id
				return result, true
			}
		}
	case referenceC:
		n, ok := packer.UnpackInt(packed)
		return ReferenceC{n}, ok
	case constantC:
		unpacked, ok := packer.UnpackPickler(packed, &CompoundT{})
		if !ok {
			return nil, false
		}
		return ConstC{unpacked.(T)}, ok
	}
	return nil, false
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:34,代码来源:pickle.go


示例4: unpickleTemplateID

func unpickleTemplateID(packer intern.Packer, packed intern.Packed) (TemplateID, bool) {
	unpickled, ok := packer.UnpackPickler(packed, TemplateID(0))
	if !ok {
		unpickled, ok = packer.UnpackPickler(packed, &Template{})
		if !ok {
			return TemplateID(0), false
		}
		unpickled = unpickled.(*Template).ID()
	}
	return unpickled.(TemplateID), true
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:11,代码来源:pickle.go


示例5: Unpickle

func (s *Setting) Unpickle(packer intern.Packer, pickled intern.Packed) (intern.Pickler, bool) {
	lines, ok := packer.UnpackList(pickled)
	if !ok {
		return nil, false
	}
	result := Init()
	for _, packedLine := range lines {
		line, slots, ok := unpickleSettingLine(packer, packedLine)
		if !ok {
			return nil, false
		}
		result = result.Append(line, slots)
	}
	return result, true
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:15,代码来源:pickle.go


示例6: unpickleSettingLine

func unpickleSettingLine(packer intern.Packer, x intern.Packed) (SettingLine, int, bool) {
	result, ok := packer.UnpackPickler(x, ActionCID(0))
	if ok {
		return result.(ActionCID), 0, true
	}
	id, ok := unpickleTemplateID(packer, x)
	if ok {
		return id, id.Template().Slots(), true
	}
	result, ok = packer.UnpackPickler(x, ActionC{})
	if ok {
		return result.(ActionC).ID(), 0, true
	}
	return nil, 0, false
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:15,代码来源:pickle.go


示例7: Pickle

func (s *Setting) Pickle(packer intern.Packer) intern.Packed {
	if s.Size == 0 {
		return packer.PackList([]intern.Packed{})
	}
	previous := s.Previous.Pickle(packer)
	return packer.AppendToPacked(previous, packer.PackPickler(s.Last))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:7,代码来源:pickle.go


示例8: pack

func pack(packer intern.Packer, x interface{}) intern.Packed {
	switch x := x.(type) {
	case intern.Packed:
		return x
	case int:
		return packer.PackInt(x)
	case string:
		return packer.PackString(x)
	case intern.Pickler:
		return packer.PackPickler(x)
	case []int:
		args := make([]interface{}, len(x))
		for i, y := range x {
			args[i] = interface{}(y)
		}
		return p(packer, args...)
	case []string:
		args := make([]interface{}, len(x))
		for i, y := range x {
			args[i] = interface{}(y)
		}
		return p(packer, args...)
	case []intern.Pickler:
		args := make([]interface{}, len(x))
		for i, y := range x {
			args[i] = interface{}(y)
		}
		return p(packer, args...)
	case []T:
		args := make([]interface{}, len(x))
		for i, y := range x {
			args[i] = interface{}(y)
		}
		return p(packer, args...)
	case []C:
		args := make([]interface{}, len(x))
		for i, y := range x {
			args[i] = interface{}(y)
		}
		return p(packer, args...)
	case []intern.Packed:
		args := make([]interface{}, len(x))
		for i, y := range x {
			args[i] = interface{}(y)
		}
		return p(packer, args...)
	case []interface{}:
		return p(packer, x...)
	}
	panic(fmt.Errorf("bad argument %v to p(...) (type %T)", x, x))

}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:52,代码来源:pickle.go


示例9: unpickleT

func unpickleT(packer intern.Packer, kind int, packed intern.Packed) (T, bool) {
	switch kind {
	case chanT:
		unpickled, ok := packer.UnpackPickler(packed, &SettingT{})
		if !ok {
			return nil, false
		}
		setting, ok := unpickled.(*SettingT)
		return MakeChannel(setting), ok
	case intT:
		result, ok := packer.UnpackInt(packed)
		if !ok {
			//panic(fmt.Errorf("failed to unpickle int from %v", packed))
		}
		return Int(result), ok
	case strT:
		result, ok := packer.UnpackString(packed)
		return Str(result), ok
	case quotedT:
		unpickled, ok := packer.UnpackPickler(packed, &CompoundT{})
		if !ok {
			return nil, false
		}
		return Quote(unpickled.(T)), true
	case wrapperT:
		return Make("a term that stands in for a wrapped go object that could not be pickled").T(), true
	case compoundT:
		result := &CompoundT{}
		if packed, args, ok := packer.UnpackPair(packed); ok {
			if args, ok := packer.UnpackList(args); ok {
				result.args = make([]T, len(args))
				for i, arg := range args {
					unpacked, ok := packer.UnpackPickler(arg, &CompoundT{})
					if !ok {
						return nil, false
					}
					result.args[i] = unpacked.(T)
				}
				id, ok := unpickleTemplateID(packer, packed)
				if !ok {
					return nil, false
				}
				result.TemplateID = id
				return result, true
			}
		}
	}
	return nil, false
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:49,代码来源:pickle.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang geos.Geometry类代码示例发布时间:2022-05-28
下一篇:
Golang term.SettingT类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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