Fix packet ids

This commit is contained in:
Vladislavs Golubs
2021-02-07 02:20:12 +03:00
parent ab4d40e482
commit d589bd7956
5 changed files with 130 additions and 29 deletions

View File

@@ -1,15 +1,15 @@
pub enum {{protocol_enum_name}} {
{{~#if packets}}
pub enum {{packet_enum_name}} {
{{~#each packets as |p|}}
{{p.name}}{{#if p.fields}}({{p.name}}){{/if}}{{#unless @last}},{{/unless}}
{{~/each}}
}
impl {{protocol_enum_name}} {
impl {{packet_enum_name}} {
pub fn get_type_id(&self) -> u8 {
match self {
{{~#each packets as |p|}}
Self::{{p.name}}{{#if p.fields}}(_){{/if}} => {{packet_id @index}}{{#unless @last}},{{/unless}}
Self::{{p.name}}{{#if p.fields}}(_){{/if}} => {{packet_id p.id}}{{#unless @last}},{{/unless}}
{{~/each}}
}
}
@@ -17,7 +17,7 @@ impl {{protocol_enum_name}} {
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
match type_id {
{{~#each packets as |p|}}
{{@index}} => {
{{packet_id p.id}} => {
{{~#if p.fields}}
let {{snake_case p.name}} = {{p.name}}::decode(reader)?;
@@ -48,3 +48,4 @@ impl {{protocol_enum_name}} {
}
{{/each~}}
}
{{~/if}}