예제 #1
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))

}