ataarg.go
func (a *ATAArg) MarshalBinary() ([]byte, error) {
	// Allocate correct number of bytes for argument and data
	b := make([]byte, ataArgLen+len(a.Data))

	// Add bit flags at appropriate positions
	//
	// 0101 0011
	//  | |   ||
	//  | |   |+-- write flag
	//  | |   +--- asynchronous flag
	//  | +------- device/head register flag
	//  +--------- extended LBA48 flag
	var flags uint8
	if a.FlagLBA48Extended {
		flags |= (1 << 6)
	}
	if a.FlagATADeviceHeadRegister {
		flags |= (1 << 4)
	}
	if a.FlagAsynchronous {
		flags |= (1 << 1)
	}
	if a.FlagWrite {
		flags |= 1
	}
	b[0] = flags

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

	// 2 bytes reserved space

	// Copy raw data after argument header
	copy(b[12:], a.Data)

	return b, nil
}
func (a *ATAArg) MarshalBinary() ([]byte, error) {
	// Allocate correct number of bytes for argument and data
	b := make([]byte, ataArgLen+len(a.Data))

	// Add bit flags at appropriate positions
	//
	// 0101 0011
	//  | |   ||
	//  | |   |+-- write flag
	//  | |   +--- asynchronous flag
	//  | +------- device/head register flag
	//  +--------- extended LBA48 flag
	var flags uint8
	if a.FlagLBA48Extended {
		flags |= (1 << 6)
	}
	if a.FlagATADeviceHeadRegister {
		flags |= (1 << 4)
	}
	if a.FlagAsynchronous {
		flags |= (1 << 1)
	}
	if a.FlagWrite {
		flags |= 1
	}
	b[0] = flags

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

	// 2 bytes reserved space

	// Copy raw data after argument header
	copy(b[12:], a.Data)

	return b, nil
}
func ( a * ATAArg ) MarshalBinary ( ) ( [ ] byte , error ) { // Allocate correct number of bytes for argument and data b := make ( [ ] byte , ataArgLen + len ( a . Data ) ) // Add bit flags at appropriate positions // // 0101 0011 //  | |   || //  | |   |+-- write flag //  | |   +--- asynchronous flag //  | +------- device/head register flag //  +--------- extended LBA48 flag var flags uint8 if a . FlagLBA48Extended { flags |= ( 1 << 6 ) } if a . FlagATADeviceHeadRegister { flags |= ( 1 << 4 ) } if a . FlagAsynchronous { flags |= ( 1 << 1 ) } if a . FlagWrite { flags |= 1 } b [ 0 ] = flags // Set other ATA data b [ 1 ] = a . ErrFeature b [ 2 ] = a . SectorCount b [ 3 ] = uint8 ( a . CmdStatus ) b [ 4 ] = a . LBA [ 0 ] b [ 5 ] = a . LBA [ 1 ] b [ 6 ] = a . LBA [ 2 ] b [ 7 ] = a . LBA [ 3 ] b [ 8 ] = a . LBA [ 4 ] b [ 9 ] = a . LBA [ 5 ] // 2 bytes reserved space // Copy raw data after argument header copy ( b [ 12 : ] , a . Data ) return b , nil }
// MarshalBinary allocates a byte slice containing the data from an ATAArg.
//
// MarshalBinary never returns an error.
MarshalBinary allocates a byte slice containing the data from an ATAArg . MarshalBinary never returns an error .