I have the following 2 structures
type AAAA struct{
Aa [2]byte
Ab [2]byte
Ac [3]byte
}
type BBBB struct{
Ba [4]byte
Bb [2]byte
Bc [3]byte
Bd [2]byte // No Of Struct AAA Items
BBStr []AAAA
}
So Struct BBB is repeating in Struct AAA
Then I have a string that I have as input which contains the value of the structure coming as input
input := "aaaabbccc02ddeefffddeefff" (here 02 is no of time Struct AAAA repeats in Struct BBBB)
I need to read through the input string and populate the structure BBBB including the array of structure AAA
I wrote the function below to achieve this. But I am getting " Bad error - binary.Read: invalid type *main.BBBB
Need Help in identifying why this error? Also is there a way to do this differently?
func main() {
input := "aaaabbccc02ddeefffddeefff"
var k BBBB
var j AAAA
k.BBStr = append(k.BBStr,j)
k.BBStr = append(k.BBStr,j)
xyz := []byte(input)
err := binary.Read(bytes.NewReader(xyz), binary.LittleEndian, &k)
if err != nil {
fmt.Println("Bad error - ",err)
}
fmt.Println("Structure Definition - ",k)
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…