diff --git a/yunq/message.cpp.jinja b/yunq/message.cpp.jinja index dba366a..4a3e599 100644 --- a/yunq/message.cpp.jinja +++ b/yunq/message.cpp.jinja @@ -26,10 +26,10 @@ glcr::Status {{message.name}}::ParseFromBytes(const yunq::MessageView& message) {%- if field.type == Type.CAPABILITY %} {%- if not field.repeated %} // Parse {{field.name}}. - ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{loop.index0}})); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{field.number}})); {%- else %} // Parse {{field.name}}. - ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{loop.index0}})); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{field.number}})); {%- endif %} {%- endif %} {%- endfor %} @@ -43,10 +43,10 @@ glcr::Status {{message.name}}::ParseFromBytes(const yunq::MessageView& message, {%- if field.type == Type.CAPABILITY %} {%- if not field.repeated %} // Parse {{field.name}}. - ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{loop.index0}}, caps)); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadCapability({{field.number}}, caps)); {%- else %} // Parse {{field.name}}. - ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{loop.index0}}, caps)); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeatedCapability({{field.number}}, caps)); {%- endif %} {%- endif %} {%- endfor %} @@ -61,9 +61,9 @@ glcr::Status {{message.name}}::ParseFromBytesInternal(const yunq::MessageView& m {%- if field.type != Type.CAPABILITY %} {%- if not field.repeated %} - ASSIGN_OR_RETURN({{field.name}}_, message.ReadField<{{field.cpp_type()}}>({{loop.index0}})); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadField<{{field.cpp_type()}}>({{field.number}})); {%- else %} - ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeated<{{field.cpp_type()}}>({{loop.index0}})); + ASSIGN_OR_RETURN({{field.name}}_, message.ReadRepeated<{{field.cpp_type()}}>({{field.number}})); {% endif %} {%- endif %} @@ -88,17 +88,17 @@ uint64_t {{message.name}}::SerializeInternal(yunq::Serializer& serializer) const {%- if not field.repeated %} {%- if field.type != Type.CAPABILITY %} - serializer.WriteField<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_); + serializer.WriteField<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_); {%- else %} - serializer.WriteCapability({{loop.index0}}, {{field.name}}_); + serializer.WriteCapability({{field.number}}, {{field.name}}_); {%- endif %} {%- else %} {%- if field.type != Type.CAPABILITY %} - serializer.WriteRepeated<{{field.cpp_type()}}>({{loop.index0}}, {{field.name}}_); + serializer.WriteRepeated<{{field.cpp_type()}}>({{field.number}}, {{field.name}}_); {%- else %} - serializer.WriteRepeatedCapability({{loop.index0}}, {{field.name}}_); + serializer.WriteRepeatedCapability({{field.number}}, {{field.name}}_); {%- endif %} {%- endif %} diff --git a/yunq/parser.py b/yunq/parser.py index d9c3eaa..5507880 100644 --- a/yunq/parser.py +++ b/yunq/parser.py @@ -17,6 +17,7 @@ class LexemeType(Enum): ARROW = 7 SEMICOLON = 8 DOT = 9 + EQUALS = 10 class Lexeme(): @@ -266,8 +267,11 @@ class Parser(): fields: list[Field] = [] field_names = set() + next_field_num = 0 while self.peektype() != LexemeType.RIGHT_BRACE: f = self.field() + f.number = next_field_num + next_field_num += 1 if f.name in field_names: sys.exit("Field %s declared twice on %s" % (f.name, name)) field_names.add(f.name)