The problem is that m.Struct
is just a pointer to _struct
type and it's not initialized yet, so you can't assign anything to it's Data
Field.
If you look at the generated code for My
message, it's something like this:
type My struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Struct *My_XStruct
}
so Struct
type is pointer to My_XStruct
. You have to do something like this:
m := my.My{}
m.Struct = &my.My_XStruct{}
m.Struct.Data = []byte{1, 2}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…