From 227a5ad7c8977a40242720ac886139860e701188 Mon Sep 17 00:00:00 2001 From: Nobody Date: Sun, 3 Oct 2021 00:18:53 +0500 Subject: [PATCH] Autogenerate PacketId enum --- .gitignore | 7 +++++++ gen_ids.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 gen_ids.sh diff --git a/.gitignore b/.gitignore index ea69607..9c8929f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,10 @@ Cargo.lock # keys /keys/ + +# Vim temp files +.*.swp +.*.swo + +# Autogenerated files +/gen/ diff --git a/gen_ids.sh b/gen_ids.sh new file mode 100755 index 0000000..cd26ea5 --- /dev/null +++ b/gen_ids.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +#echo "#[macro_use]"; +#echo "extern crate num_derive;"; + +#echo ""; + +echo "// Autogenerated file, do not edit!" + +echo ""; + +echo "#[repr(u16)]"; +echo "#[derive(FromPrimitive, ToPrimitive)]"; +echo "#[derive(Debug, PartialEq, Eq, Clone, Hash)]"; + +echo "pub enum PacketId {"; + +for f in protobuf/*; do + CMD_ID=`cat $f | grep CMD_ID | cut -d'=' -f2 | tr -d ' ;\015'`; + + if [ "x${CMD_ID}" != "x" ]; then + NAME=`echo $f | cut -d'/' -f2 | cut -d'.' -f1`; + echo " ${NAME} = ${CMD_ID}," + fi +done + +echo "}";