Skip to content

Commit e3b5604

Browse files
authored
Update srpc_generator to support thrift2. (#436)
1 parent 10fda29 commit e3b5604

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

src/generator/parser.cc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool Parser::parse(const std::string& proto_file, idl_info& info)
191191
if ((state & PARSER_ST_BLOCK_MASK) == PARSER_ST_INSIDE_BLOCK)
192192
{
193193
if (flag_append == true)
194-
block.append(line);
194+
block.append(line); // block.append(line + "\n");
195195

196196
if (this->check_block_begin(line) == true)
197197
++stack_count;
@@ -758,11 +758,31 @@ bool Parser::parse_rpc_param_thrift(const std::string& file_name_prefix,
758758
continue;
759759

760760
auto typevar = parse_thrift_variable(filedparam[1], ' ');
761-
if (typevar.size() != 2)
761+
762+
if (typevar.size() == 3) // for optional/required in thrift2
763+
{
764+
std::string qualifier = SGenUtil::strip(typevar[0]);
765+
if (qualifier == "optional")
766+
{
767+
param.required_state = srpc::THRIFT_STRUCT_FIELD_OPTIONAL;
768+
typevar.erase(typevar.begin());
769+
}
770+
else if (qualifier == "required")
771+
{
772+
param.required_state = srpc::THRIFT_STRUCT_FIELD_REQUIRED;
773+
typevar.erase(typevar.begin());
774+
}
775+
else
776+
continue; // error
777+
}
778+
else if (typevar.size() == 2)
779+
{
780+
param.required_state = srpc::THRIFT_STRUCT_FIELD_REQUIRED;
781+
}
782+
else
762783
continue;
763784

764785
param.var_name = typevar[1];
765-
param.required_state = srpc::THRIFT_STRUCT_FIELD_REQUIRED;
766786
param.field_id = atoi(SGenUtil::strip(filedparam[0]).c_str());
767787
idl_type = SGenUtil::strip(typevar[0]);
768788
fill_rpc_param_type(file_name_prefix, idl_type, param, info);

0 commit comments

Comments
 (0)