in marshal.go [388:464]
func marshalSmallInt(info TypeInfo, value interface{}) ([]byte, error) {
switch v := value.(type) {
case Marshaler:
return v.MarshalCQL(info)
case unsetColumn:
return nil, nil
case int16:
return encShort(v), nil
case uint16:
return encShort(int16(v)), nil
case int8:
return encShort(int16(v)), nil
case uint8:
return encShort(int16(v)), nil
case int:
if v > math.MaxInt16 || v < math.MinInt16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case int32:
if v > math.MaxInt16 || v < math.MinInt16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case int64:
if v > math.MaxInt16 || v < math.MinInt16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case uint:
if v > math.MaxUint16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case uint32:
if v > math.MaxUint16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case uint64:
if v > math.MaxUint16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case string:
n, err := strconv.ParseInt(v, 10, 16)
if err != nil {
return nil, marshalErrorf("can not marshal %T into %s: %v", value, info, err)
}
return encShort(int16(n)), nil
}
if value == nil {
return nil, nil
}
switch rv := reflect.ValueOf(value); rv.Type().Kind() {
case reflect.Int, reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8:
v := rv.Int()
if v > math.MaxInt16 || v < math.MinInt16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case reflect.Uint, reflect.Uint64, reflect.Uint32, reflect.Uint16, reflect.Uint8:
v := rv.Uint()
if v > math.MaxUint16 {
return nil, marshalErrorf("marshal smallint: value %d out of range", v)
}
return encShort(int16(v)), nil
case reflect.Ptr:
if rv.IsNil() {
return nil, nil
}
}
return nil, marshalErrorf("can not marshal %T into %s. Accepted types: Marshaler, int16, uint16, int8, uint8, int, uint, int32, uint32, int64, uint64, string, UnsetValue.", value, info)
}