[Yunq] Move message fields to a numbering scheme set by the parser.
This commit is contained in:
parent
ee341fa739
commit
3b91819a4b
|
@ -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 %}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue