1
// 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;
        }
   }
}

次に、SQL 行をエージェントの protobuf 構造体にスキャンします。

// main.go

var a proto.Agent

.....

... row.Scan(&a.Permission.Type,...)

その権限タイプはvalue = 0、デフォルト タイプのシンプルな MariaDB INT() として保存されます。そのため、直接スキャンすることはできません。そのため、temp struct whereType int32を作成し、temp struct フィールドを protobuf struct にマップしようとした後、行をその temp struct にスキャンしましたが、うまくいきませんでした。MariaDB 文字列値を []byte 型フィールドにスキャンするときに発生した同様の問題がありましたが、 temp struct で解決しました[]byte(tmp.UUID)

非標準の protobuf フィールド タイプが使用されている場合に、データベース ROW (単一行) をスキャンして protubuf メッセージにする一般的なパターンは何ですか?

編集:追加の0値の処理が必要ですか?

4

1 に答える 1