Ejemplo n.º 1
0
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))
}
Ejemplo n.º 2
0
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))

}