本文整理汇总了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)
}
示例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])
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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))
}
示例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))
}
示例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
}