実現したいこと
.protoファイルに多次元配列を実装したい.
発生している問題・分からないこと
.protoファイルに2次元配列を実装したが,呼び出し時にTypeErrorが起きている.
エラーメッセージ
error
1Traceback (most recent call last): 2 File "./client.py", line 3, in <module> 3 req = Pickup_Plan_pb2.Request( 4TypeError: Parameter to MergeFrom() must be instance of same class: expected <class 'Pickup_Plan_pb2.Row'> got <class 'list'>.
該当のソースコード
client.py
1from pb import Pickup_Plan_pb2 2 3req = Pickup_Plan_pb2.Request( 4 rows = [ 5 [1,2], 6 [3,4] 7 ] 8) 9
syntax = "proto3"; package Pickup_Plan; service Pickup_Plan{ rpc Generate_Pickup_Plan (Request) returns (Response){} } message Request{ repeated Row rows = 1; } message Row{ repeated int32 row = 1; } message Response{ }
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
「Protocol Buffersでは repeatedを連続させた多次元配列は定義できないが、任意のメッセージ型に repeated を付けることはできるので、そのメッセージ型の中に repeated フィールドを配置すれば、多次元配列と同様のデータを表現することができる」 (参考:https://maku.blog/p/b2q2jmh/)
とのことだったので、実装してみたのですが上手くいきませんでした.
補足
特になし
あなたの回答
tips
プレビュー