In a proto, how can I define a map as a custom option

試著忘記壹切 提交于 2020-04-16 02:43:24

问题


In my proto file, I want to define a map as a custom option, tried a few things but none is working.

my metadata proto file:

syntax = "proto2";
import "google/protobuf/descriptor.proto";

package com.util;
option java_package = "com.util";

message MyMeta {
  optional bool needValidation = 1;
  map<string, string> fileMap = 2;
}

extend google.protobuf.FieldOptions {
  optional MyMeta meta = 80412; 
}

my proto file

syntax = "proto3";

package com.test;

import "util/meta.proto";
import "google/protobuf/timestamp.proto";

message MyMeta {
  int32 id = 1 [(com.util.meta).needValidation = false, /*looking for a way to set a map (com.meta).tableOptions = {"t,raw_orders"}]*/;

}

Is this possible?


回答1:


Seems it is not possible. To make my logic, I created a string like "StoreOrders:raw_orders_test,OrderItems:raw_order_items_test


message MyMeta {
  int32 id = 1 [(com.util.meta).needValidation = false, (com.meta).tableOptions = "TableA:valueA,TableB:valueB;
}

and in my jav code and splitting the string to create a hash map.



来源:https://stackoverflow.com/questions/60982469/in-a-proto-how-can-i-define-a-map-as-a-custom-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!