本文整理汇总了Golang中github.com/paulfchristiano/dwimmer/term/intern.Packer.UnpackPair方法的典型用法代码示例。如果您正苦于以下问题:Golang Packer.UnpackPair方法的具体用法?Golang Packer.UnpackPair怎么用?Golang Packer.UnpackPair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/paulfchristiano/dwimmer/term/intern.Packer
的用法示例。
在下文中一共展示了Packer.UnpackPair方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: Unpickle
func (s *SettingT) Unpickle(packer intern.Packer, pickled intern.Packed) (intern.Pickler, bool) {
if v, val, ok := packer.UnpackPair(pickled); ok {
if v, ok := packer.UnpackInt(v); ok && v == v1SettingT {
if setting, packedArgs, ok := packer.UnpackPair(val); ok {
result := &SettingT{}
unpacked, ok := packer.UnpackPickler(setting, &Setting{})
if !ok {
return nil, false
}
result.Setting = unpacked.(*Setting)
args, ok := packer.UnpackList(packedArgs)
if !ok {
return nil, false
}
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)
}
return result, true
}
}
}
return nil, false
}
示例3: 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
}