in message.go [235:313]
func (m *Message) Unmarshal(r *buffer.Buffer) error {
// loop, decoding sections until bytes have been consumed
for r.Len() > 0 {
// determine type
type_, headerLength, err := encoding.PeekMessageType(r.Bytes())
if err != nil {
return err
}
var (
section any
// section header is read from r before
// unmarshaling section is set to true
discardHeader = true
)
switch encoding.AMQPType(type_) {
case encoding.TypeCodeMessageHeader:
discardHeader = false
section = &m.Header
case encoding.TypeCodeDeliveryAnnotations:
section = &m.DeliveryAnnotations
case encoding.TypeCodeMessageAnnotations:
section = &m.Annotations
case encoding.TypeCodeMessageProperties:
discardHeader = false
section = &m.Properties
case encoding.TypeCodeApplicationProperties:
section = &m.ApplicationProperties
case encoding.TypeCodeApplicationData:
r.Skip(int(headerLength))
var data []byte
err = encoding.Unmarshal(r, &data)
if err != nil {
return err
}
m.Data = append(m.Data, data)
continue
case encoding.TypeCodeAMQPSequence:
r.Skip(int(headerLength))
var data []any
err = encoding.Unmarshal(r, &data)
if err != nil {
return err
}
m.Sequence = append(m.Sequence, data)
continue
case encoding.TypeCodeFooter:
section = &m.Footer
case encoding.TypeCodeAMQPValue:
section = &m.Value
default:
return fmt.Errorf("unknown message section %#02x", type_)
}
if discardHeader {
r.Skip(int(headerLength))
}
err = encoding.Unmarshal(r, section)
if err != nil {
return err
}
}
return nil
}