ataarg.go
func (a *ATAArg) UnmarshalBinary(b []byte) error {
	// Must contain minimum length for ATA argument
	if len(b) < ataArgLen {
		return io.ErrUnexpectedEOF
	}

	// 2 bytes reserved
	if b[10] != 0 || b[11] != 0 {
		return ErrorBadArgumentParameter
	}

	// Read bit flags at appropriate positions:
	//
	// 0101 0011
	//  | |   ||
	//  | |   |+-- write flag
	//  | |   +--- asynchronous flag
	//  | +------- device/head register flag
	//  +--------- extended LBA48 flag
	a.FlagLBA48Extended = (b[0] & 0x40) != 0
	a.FlagATADeviceHeadRegister = (b[0] & 0x10) != 0
	a.FlagAsynchronous = (b[0] & 0x02) != 0
	a.FlagWrite = (b[0] & 0x01) != 0

	// Read ATA data
	a.ErrFeature = b[1]
	a.SectorCount = b[2]
	a.CmdStatus = ATACmdStatus(b[3])
	a.LBA[0] = b[4]
	a.LBA[1] = b[5]
	a.LBA[2] = b[6]
	a.LBA[3] = b[7]
	a.LBA[4] = b[8]
	a.LBA[5] = b[9]

	// Copy raw data from ATA argument
	d := make([]byte, len(b[12:]))
	copy(d, b[12:])
	a.Data = d

	return nil
}
func (a *ATAArg) UnmarshalBinary(b []byte) error {
	// Must contain minimum length for ATA argument
	if len(b) < ataArgLen {
		return io.ErrUnexpectedEOF
	}

	// 2 bytes reserved
	if b[10] != 0 || b[11] != 0 {
		return ErrorBadArgumentParameter
	}

	// Read bit flags at appropriate positions:
	//
	// 0101 0011
	//  | |   ||
	//  | |   |+-- write flag
	//  | |   +--- asynchronous flag
	//  | +------- device/head register flag
	//  +--------- extended LBA48 flag
	a.FlagLBA48Extended = (b[0] & 0x40) != 0
	a.FlagATADeviceHeadRegister = (b[0] & 0x10) != 0
	a.FlagAsynchronous = (b[0] & 0x02) != 0
	a.FlagWrite = (b[0] & 0x01) != 0

	// Read ATA data
	a.ErrFeature = b[1]
	a.SectorCount = b[2]
	a.CmdStatus = ATACmdStatus(b[3])
	a.LBA[0] = b[4]
	a.LBA[1] = b[5]
	a.LBA[2] = b[6]
	a.LBA[3] = b[7]
	a.LBA[4] = b[8]
	a.LBA[5] = b[9]

	// Copy raw data from ATA argument
	d := make([]byte, len(b[12:]))
	copy(d, b[12:])
	a.Data = d

	return nil
}
// UnmarshalBinary unmarshals a byte slice into an ATAArg.
//
// If the byte slice does not contain enough data to form a valid ATAArg,
// io.ErrUnexpectedEOF is returned.
//
// If bytes 10 and 11 are not zero (reserved bytes), ErrorBadArgumentParameter
// is returned.