I forked the https://github.com/HewlettPackard/structex, and tried to turn the example code which is :
package main
import (
"fmt"
"github.com/HewlettPackard/structex"
)
type SCSI_Standard_Inquiry struct {
PeripheralDeviceType uint8 `bitfield:"5"` // Byte 0
PeripheralQualifier uint8 `bitfield:"3"`
reserved0 uint8 `bitfield:"6,reserved"` // Byte 1
LU_Cong uint8 `bitfield:"1"`
RMB uint8 `bitfield:"1"`
Version uint8 // Byte 2
}
func main() {
var inquiry = new(SCSI_Standard_Inquiry)
// Perform IOCTL on device, returns byte reader to byte response
if err := structex.Decode(byteReader, inquiry); err != nil {
panic("a problem")
}
fmt.Printf("SCSI Peripheral Device Type: %d\n", inquiry.PeripheralDeviceType)
fmt.Printf("SCSI Peripheral Qualifier: %d\n", inquiry.PeripheralQualifier)
fmt.Printf("Inquiry Version: %#02x\n", inquiry.Version)
// etc
}
, I am using sublime text with go build packages to build this code, i am getting the following error: .\test.go:22:31: undefined: byteReader
Here is the function Decode for reference :
func Decode(reader io.ByteReader, s interface{}) error {
d := decoder{
reader: reader,
currentByte: 0,
byteOffset: 0,
bitOffset: 0,
}
t := newTranscoder(&d)
d.transcoder = t
return t.transcode(reflect.ValueOf(s), nil)
}
// DecodeByteBuffer takes a raw byte buffer and unpacks the buffer into
// the provided structure. Unused bytes do not cause an error.
func DecodeByteBuffer(b *bytes.Buffer, s interface{}) error {
reader := byteBufferReader{
buffer: b,
}
return Decode(&reader, s)
}