in ptp/protocol/management.go [173:211]
func (p *ManagementMsgErrorStatus) UnmarshalBinary(rawBytes []byte) error {
reader := bytes.NewReader(rawBytes)
be := binary.BigEndian
if err := binary.Read(reader, be, &p.ManagementMsgHead); err != nil {
return fmt.Errorf("reading ManagementMsgErrorStatus ManagementMsgHead: %w", err)
}
if err := binary.Read(reader, be, &p.ManagementErrorStatusTLV.TLVHead); err != nil {
return fmt.Errorf("reading ManagementMsgErrorStatus TLVHead: %w", err)
}
if err := binary.Read(reader, be, &p.ManagementErrorStatusTLV.ManagementErrorID); err != nil {
return fmt.Errorf("reading ManagementMsgErrorStatus ManagementErrorID: %w", err)
}
if err := binary.Read(reader, be, &p.ManagementErrorStatusTLV.ManagementID); err != nil {
return fmt.Errorf("reading ManagementMsgErrorStatus ManagementID: %w", err)
}
if err := binary.Read(reader, be, &p.ManagementErrorStatusTLV.Reserved); err != nil {
return fmt.Errorf("reading ManagementMsgErrorStatus Reserved: %w", err)
}
// packet can have trailing bytes, let's make sure we don't try to read past given length
toRead := int(p.ManagementMsgHead.Header.MessageLength)
toRead -= binary.Size(p.ManagementMsgHead)
toRead -= binary.Size(p.ManagementErrorStatusTLV.TLVHead)
toRead -= binary.Size(p.ManagementErrorStatusTLV.ManagementErrorID)
toRead -= binary.Size(p.ManagementErrorStatusTLV.ManagementID)
toRead -= binary.Size(p.ManagementErrorStatusTLV.Reserved)
if reader.Len() == 0 || toRead <= 0 {
// DisplayData is completely optional
return nil
}
data := make([]byte, reader.Len())
if _, err := io.ReadFull(reader, data); err != nil {
return err
}
if err := p.DisplayData.UnmarshalBinary(data); err != nil {
return fmt.Errorf("reading ManagementMsgErrorStatus DisplayData: %w", err)
}
return nil
}