I am working on a personal project & using Go for the first time. I am using structs for operating on the data and for storing the data in a file, I am using proto as the encoder.
In the project, my proto definition looks something like this
message Data {
string key = 1;
string value = 2;
}
message Record {
int64 size = 1;
Data data = 2;
}
and my struct looks like this
type KVData struct {
Key string
Value string
}
Currently, this is how I am creating proto data
kvData := KVData{Key: "name", Value: "A"}
record := &pb.Record{
Size: 20,
Data: &pb.Data{Key: "name", Value: "A"},
}
What I am looking for is a way to do this:
record := &pb.Record{
Size: 20,
Data: &((pb.Data)kvData), // Won't work
}
// or like Python
record := &pb.Record{
Size: 20,
Data: &(pb.Data{**kvData}), // Won't work
}
I tried googling but couldn't find any solution explaining how to do this.
Note, I am not just trying to solve this specific case, I also want to know what's the recommended Go way to operate between structs and proto(use only proto?)?