func Unmarshal()

in internal/encoding/decode.go [36:231]


func Unmarshal(r *buffer.Buffer, i any) error {
	if tryReadNull(r) {
		return nil
	}

	switch t := i.(type) {
	case *int:
		val, err := readInt(r)
		if err != nil {
			return err
		}
		*t = val
	case *int8:
		val, err := readSbyte(r)
		if err != nil {
			return err
		}
		*t = val
	case *int16:
		val, err := readShort(r)
		if err != nil {
			return err
		}
		*t = val
	case *int32:
		val, err := readInt32(r)
		if err != nil {
			return err
		}
		*t = val
	case *int64:
		val, err := readLong(r)
		if err != nil {
			return err
		}
		*t = val
	case *uint64:
		val, err := readUlong(r)
		if err != nil {
			return err
		}
		*t = val
	case *uint32:
		val, err := readUint32(r)
		if err != nil {
			return err
		}
		*t = val
	case **uint32: // fastpath for uint32 pointer fields
		val, err := readUint32(r)
		if err != nil {
			return err
		}
		*t = &val
	case *uint16:
		val, err := readUshort(r)
		if err != nil {
			return err
		}
		*t = val
	case *uint8:
		val, err := ReadUbyte(r)
		if err != nil {
			return err
		}
		*t = val
	case *float32:
		val, err := readFloat(r)
		if err != nil {
			return err
		}
		*t = val
	case *float64:
		val, err := readDouble(r)
		if err != nil {
			return err
		}
		*t = val
	case *string:
		val, err := ReadString(r)
		if err != nil {
			return err
		}
		*t = val
	case *Symbol:
		s, err := ReadString(r)
		if err != nil {
			return err
		}
		*t = Symbol(s)
	case *[]byte:
		val, err := readBinary(r)
		if err != nil {
			return err
		}
		*t = val
	case *bool:
		b, err := readBool(r)
		if err != nil {
			return err
		}
		*t = b
	case *time.Time:
		ts, err := readTimestamp(r)
		if err != nil {
			return err
		}
		*t = ts
	case *[]int8:
		return (*arrayInt8)(t).Unmarshal(r)
	case *[]uint16:
		return (*arrayUint16)(t).Unmarshal(r)
	case *[]int16:
		return (*arrayInt16)(t).Unmarshal(r)
	case *[]uint32:
		return (*arrayUint32)(t).Unmarshal(r)
	case *[]int32:
		return (*arrayInt32)(t).Unmarshal(r)
	case *[]uint64:
		return (*arrayUint64)(t).Unmarshal(r)
	case *[]int64:
		return (*arrayInt64)(t).Unmarshal(r)
	case *[]float32:
		return (*arrayFloat)(t).Unmarshal(r)
	case *[]float64:
		return (*arrayDouble)(t).Unmarshal(r)
	case *[]bool:
		return (*arrayBool)(t).Unmarshal(r)
	case *[]string:
		return (*arrayString)(t).Unmarshal(r)
	case *[]Symbol:
		return (*arraySymbol)(t).Unmarshal(r)
	case *[][]byte:
		return (*arrayBinary)(t).Unmarshal(r)
	case *[]time.Time:
		return (*arrayTimestamp)(t).Unmarshal(r)
	case *[]UUID:
		return (*arrayUUID)(t).Unmarshal(r)
	case *[]any:
		return (*list)(t).Unmarshal(r)
	case *map[any]any:
		return (*mapAnyAny)(t).Unmarshal(r)
	case *map[string]any:
		return (*mapStringAny)(t).Unmarshal(r)
	case *map[Symbol]any:
		return (*mapSymbolAny)(t).Unmarshal(r)
	case *DeliveryState:
		type_, _, err := PeekMessageType(r.Bytes())
		if err != nil {
			return err
		}

		switch AMQPType(type_) {
		case TypeCodeStateAccepted:
			*t = new(StateAccepted)
		case TypeCodeStateModified:
			*t = new(StateModified)
		case TypeCodeStateReceived:
			*t = new(StateReceived)
		case TypeCodeStateRejected:
			*t = new(StateRejected)
		case TypeCodeStateReleased:
			*t = new(StateReleased)
		default:
			return fmt.Errorf("unexpected type %d for deliveryState", type_)
		}
		return Unmarshal(r, *t)

	case *any:
		v, err := ReadAny(r)
		if err != nil {
			return err
		}
		*t = v

	case unmarshaler:
		return t.Unmarshal(r)
	default:
		// handle **T
		v := reflect.Indirect(reflect.ValueOf(i))

		// can't unmarshal into a non-pointer
		if v.Kind() != reflect.Ptr {
			return fmt.Errorf("unable to unmarshal %T", i)
		}

		// if nil pointer, allocate a new value to
		// unmarshal into
		if v.IsNil() {
			v.Set(reflect.New(v.Type().Elem()))
		}

		return Unmarshal(r, v.Interface())
	}
	return nil
}