in internal/encoding/decode.go [237:284]
func UnmarshalComposite(r *buffer.Buffer, type_ AMQPType, fields ...UnmarshalField) error {
cType, numFields, err := readCompositeHeader(r)
if err != nil {
return err
}
// check type matches expectation
if cType != type_ {
return fmt.Errorf("invalid header %#0x for %#0x", cType, type_)
}
// Validate the field count is less than or equal to the number of fields
// provided. Fields may be omitted by the sender if they are not set.
if numFields > int64(len(fields)) {
return fmt.Errorf("invalid field count %d for %#0x", numFields, type_)
}
for i, field := range fields[:numFields] {
// If the field is null and handleNull is set, call it.
if tryReadNull(r) {
if field.HandleNull != nil {
err = field.HandleNull()
if err != nil {
return err
}
}
continue
}
// Unmarshal each of the received fields.
err = Unmarshal(r, field.Field)
if err != nil {
return fmt.Errorf("unmarshaling field %d: %v", i, err)
}
}
// check and call handleNull for the remaining fields
for _, field := range fields[numFields:] {
if field.HandleNull != nil {
err = field.HandleNull()
if err != nil {
return err
}
}
}
return nil
}