// agent.proto
message Agent {
Permission permission = 1;
google.protobuf.Timestamp born_time = 2;
message Permission {
Type type = 1;
enum Type {
KILLNONE = 0;
KILLALL = 1;
DANCE = 2;
}
}
}
Then scanning SQL row into agent protobuf struct:
// main.go
var a proto.Agent
.....
... row.Scan(&a.Permission.Type,...)
That permission type is stored as simple MariaDB INT() value = 0
for default type. So, i can't scan it directly. So i made temp struct where Type int32
and scaned row into that temp struct after what tried to map temp struct fields to protobuf struct, but with no luck.
Similar issues i had when want to scan MariaDB string values into []byte type fields but i solved that with my temp struct []byte(tmp.UUID)
.
What is common patterns to scan database ROW (single row) into protubuf message when non-standard protobuf field types are used?
EDIT: Does there should be some additional 0
value handling?