configarg.go
func (c *ConfigArg) UnmarshalBinary(b []byte) error {
	// Must contain minimum length for argument
	if len(b) < configArgLen {
		return io.ErrUnexpectedEOF
	}

	// Retrieve basic data
	c.BufferCount = binary.BigEndian.Uint16(b[0:2])
	c.FirmwareVersion = binary.BigEndian.Uint16(b[2:4])
	c.SectorCount = b[4]

	// Version is most significant 4 bits
	c.Version = uint8(b[5] >> 4)

	// Command is least significant 4 bits of byte 5
	c.Command = ConfigCommand(b[5] & 0x0f)

	// StringLength cannot be larger than the number of bytes remaining
	// in the buffer
	c.StringLength = binary.BigEndian.Uint16(b[6:8])
	if len(b[8:]) < int(c.StringLength) {
		return io.ErrUnexpectedEOF
	}
	// StringLength must not be greater than 1024, per AoEr11, Section 3.2.
	if c.StringLength > 1024 {
		return ErrorBadArgumentParameter
	}

	// Copy config string for use
	d := make([]byte, c.StringLength)
	copy(d, b[8:])
	c.String = d

	return nil
}
func (c *ConfigArg) UnmarshalBinary(b []byte) error {
	// Must contain minimum length for argument
	if len(b) < configArgLen {
		return io.ErrUnexpectedEOF
	}

	// Retrieve basic data
	c.BufferCount = binary.BigEndian.Uint16(b[0:2])
	c.FirmwareVersion = binary.BigEndian.Uint16(b[2:4])
	c.SectorCount = b[4]

	// Version is most significant 4 bits
	c.Version = uint8(b[5] >> 4)

	// Command is least significant 4 bits of byte 5
	c.Command = ConfigCommand(b[5] & 0x0f)

	// StringLength cannot be larger than the number of bytes remaining
	// in the buffer
	c.StringLength = binary.BigEndian.Uint16(b[6:8])
	if len(b[8:]) < int(c.StringLength) {
		return io.ErrUnexpectedEOF
	}
	// StringLength must not be greater than 1024, per AoEr11, Section 3.2.
	if c.StringLength > 1024 {
		return ErrorBadArgumentParameter
	}

	// Copy config string for use
	d := make([]byte, c.StringLength)
	copy(d, b[8:])
	c.String = d

	return nil
}
// UnmarshalBinary unmarshals a byte slice into a ConfigArg.
//
// If the byte slice does not contain enough data to form a valid ConfigArg,
// or config string length is greater than the number of remaining bytes in b,
// io.ErrUnexpectedEOF is returned.
//
// If config string length is greater than 1024, ErrorBadArgumentParameter is
// returned.