Skip to content

Commit

Permalink
gamenet: Add function to decode message given its ID
Browse files Browse the repository at this point in the history
  • Loading branch information
heinrich5991 committed Aug 14, 2024
1 parent 08db817 commit 835e9ea
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gamenet/ddnet/src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ pub fn decode<'a, W>(warn: &mut W, p: &mut Unpacker<'a>)
libtw2_gamenet_common::msg::decode(warn, Protocol, p)
}

pub fn decode_msg<'a, W>(warn: &mut W, id: SystemOrGame<MessageId, MessageId>, p: &mut Unpacker<'a>)
-> Result<SystemOrGame<System<'a>, Game<'a>>, Error>
where W: Warn<Warning>
{
Ok(match id {
SystemOrGame::System(id) => SystemOrGame::System(System::decode_msg(warn, id, p)?),
SystemOrGame::Game(id) => SystemOrGame::Game(Game::decode_msg(warn, id, p)?),
})
}
10 changes: 10 additions & 0 deletions gamenet/generate/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,16 @@ def emit_msg_module():
{
libtw2_gamenet_common::msg::decode(warn, Protocol, p)
}
pub fn decode_msg<'a, W>(warn: &mut W, id: SystemOrGame<MessageId, MessageId>, p: &mut Unpacker<'a>)
-> Result<SystemOrGame<System<'a>, Game<'a>>, Error>
where W: Warn<Warning>
{
Ok(match id {
SystemOrGame::System(id) => SystemOrGame::System(System::decode_msg(warn, id, p)?),
SystemOrGame::Game(id) => SystemOrGame::Game(Game::decode_msg(warn, id, p)?),
})
}\
""")

def emit_traits_module():
Expand Down
9 changes: 9 additions & 0 deletions gamenet/teeworlds-0.5/src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ pub fn decode<'a, W>(warn: &mut W, p: &mut Unpacker<'a>)
libtw2_gamenet_common::msg::decode(warn, Protocol, p)
}

pub fn decode_msg<'a, W>(warn: &mut W, id: SystemOrGame<MessageId, MessageId>, p: &mut Unpacker<'a>)
-> Result<SystemOrGame<System<'a>, Game<'a>>, Error>
where W: Warn<Warning>
{
Ok(match id {
SystemOrGame::System(id) => SystemOrGame::System(System::decode_msg(warn, id, p)?),
SystemOrGame::Game(id) => SystemOrGame::Game(Game::decode_msg(warn, id, p)?),
})
}
9 changes: 9 additions & 0 deletions gamenet/teeworlds-0.6/src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ pub fn decode<'a, W>(warn: &mut W, p: &mut Unpacker<'a>)
libtw2_gamenet_common::msg::decode(warn, Protocol, p)
}

pub fn decode_msg<'a, W>(warn: &mut W, id: SystemOrGame<MessageId, MessageId>, p: &mut Unpacker<'a>)
-> Result<SystemOrGame<System<'a>, Game<'a>>, Error>
where W: Warn<Warning>
{
Ok(match id {
SystemOrGame::System(id) => SystemOrGame::System(System::decode_msg(warn, id, p)?),
SystemOrGame::Game(id) => SystemOrGame::Game(Game::decode_msg(warn, id, p)?),
})
}
9 changes: 9 additions & 0 deletions gamenet/teeworlds-0.7/src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ pub fn decode<'a, W>(warn: &mut W, p: &mut Unpacker<'a>)
libtw2_gamenet_common::msg::decode(warn, Protocol, p)
}

pub fn decode_msg<'a, W>(warn: &mut W, id: SystemOrGame<MessageId, MessageId>, p: &mut Unpacker<'a>)
-> Result<SystemOrGame<System<'a>, Game<'a>>, Error>
where W: Warn<Warning>
{
Ok(match id {
SystemOrGame::System(id) => SystemOrGame::System(System::decode_msg(warn, id, p)?),
SystemOrGame::Game(id) => SystemOrGame::Game(Game::decode_msg(warn, id, p)?),
})
}

0 comments on commit 835e9ea

Please sign in to comment.