in internal/encoding/encode.go [18:196]
func Marshal(wr *buffer.Buffer, i any) error {
switch t := i.(type) {
case nil:
wr.AppendByte(byte(TypeCodeNull))
case bool:
if t {
wr.AppendByte(byte(TypeCodeBoolTrue))
} else {
wr.AppendByte(byte(TypeCodeBoolFalse))
}
case *bool:
if *t {
wr.AppendByte(byte(TypeCodeBoolTrue))
} else {
wr.AppendByte(byte(TypeCodeBoolFalse))
}
case uint:
writeUint64(wr, uint64(t))
case *uint:
writeUint64(wr, uint64(*t))
case uint64:
writeUint64(wr, t)
case *uint64:
writeUint64(wr, *t)
case uint32:
writeUint32(wr, t)
case *uint32:
writeUint32(wr, *t)
case uint16:
wr.AppendByte(byte(TypeCodeUshort))
wr.AppendUint16(t)
case *uint16:
wr.AppendByte(byte(TypeCodeUshort))
wr.AppendUint16(*t)
case uint8:
wr.Append([]byte{
byte(TypeCodeUbyte),
t,
})
case *uint8:
wr.Append([]byte{
byte(TypeCodeUbyte),
*t,
})
case int:
writeInt64(wr, int64(t))
case *int:
writeInt64(wr, int64(*t))
case int8:
wr.Append([]byte{
byte(TypeCodeByte),
uint8(t),
})
case *int8:
wr.Append([]byte{
byte(TypeCodeByte),
uint8(*t),
})
case int16:
wr.AppendByte(byte(TypeCodeShort))
wr.AppendUint16(uint16(t))
case *int16:
wr.AppendByte(byte(TypeCodeShort))
wr.AppendUint16(uint16(*t))
case int32:
writeInt32(wr, t)
case *int32:
writeInt32(wr, *t)
case int64:
writeInt64(wr, t)
case *int64:
writeInt64(wr, *t)
case float32:
writeFloat(wr, t)
case *float32:
writeFloat(wr, *t)
case float64:
writeDouble(wr, t)
case *float64:
writeDouble(wr, *t)
case string:
return writeString(wr, t)
case *string:
return writeString(wr, *t)
case []byte:
return WriteBinary(wr, t)
case *[]byte:
return WriteBinary(wr, *t)
case map[any]any:
return writeMap(wr, t)
case *map[any]any:
return writeMap(wr, *t)
case map[string]any:
return writeMap(wr, t)
case *map[string]any:
return writeMap(wr, *t)
case map[Symbol]any:
return writeMap(wr, t)
case *map[Symbol]any:
return writeMap(wr, *t)
case Unsettled:
return writeMap(wr, t)
case *Unsettled:
return writeMap(wr, *t)
case time.Time:
writeTimestamp(wr, t)
case *time.Time:
writeTimestamp(wr, *t)
case []int8:
return arrayInt8(t).Marshal(wr)
case *[]int8:
return arrayInt8(*t).Marshal(wr)
case []uint16:
return arrayUint16(t).Marshal(wr)
case *[]uint16:
return arrayUint16(*t).Marshal(wr)
case []int16:
return arrayInt16(t).Marshal(wr)
case *[]int16:
return arrayInt16(*t).Marshal(wr)
case []uint32:
return arrayUint32(t).Marshal(wr)
case *[]uint32:
return arrayUint32(*t).Marshal(wr)
case []int32:
return arrayInt32(t).Marshal(wr)
case *[]int32:
return arrayInt32(*t).Marshal(wr)
case []uint64:
return arrayUint64(t).Marshal(wr)
case *[]uint64:
return arrayUint64(*t).Marshal(wr)
case []int64:
return arrayInt64(t).Marshal(wr)
case *[]int64:
return arrayInt64(*t).Marshal(wr)
case []float32:
return arrayFloat(t).Marshal(wr)
case *[]float32:
return arrayFloat(*t).Marshal(wr)
case []float64:
return arrayDouble(t).Marshal(wr)
case *[]float64:
return arrayDouble(*t).Marshal(wr)
case []bool:
return arrayBool(t).Marshal(wr)
case *[]bool:
return arrayBool(*t).Marshal(wr)
case []string:
return arrayString(t).Marshal(wr)
case *[]string:
return arrayString(*t).Marshal(wr)
case []Symbol:
return arraySymbol(t).Marshal(wr)
case *[]Symbol:
return arraySymbol(*t).Marshal(wr)
case [][]byte:
return arrayBinary(t).Marshal(wr)
case *[][]byte:
return arrayBinary(*t).Marshal(wr)
case []time.Time:
return arrayTimestamp(t).Marshal(wr)
case *[]time.Time:
return arrayTimestamp(*t).Marshal(wr)
case []UUID:
return arrayUUID(t).Marshal(wr)
case *[]UUID:
return arrayUUID(*t).Marshal(wr)
case []any:
return list(t).Marshal(wr)
case *[]any:
return list(*t).Marshal(wr)
case marshaler:
return t.Marshal(wr)
default:
return fmt.Errorf("marshal not implemented for %T", i)
}
return nil
}