protobufs/scripts/rust-gen.sh

23 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
for f in *.proto
do
name=$(basename $f .proto)
mkdir -p ./rust-grpc/$name
protoc \
--prost_out=./rust-grpc/$name \
--tonic_out=./rust-grpc/$name \
$f
2024-07-14 15:42:20 +00:00
#I couldn't figure out how to configure protoc to do this
2024-07-16 20:01:05 +00:00
sed -i "s/#\[derive(Clone, PartialEq, ::prost::Message)\]/#\[derive(Clone, PartialEq, ::prost::Message, serde::Serialize, serde::Deserialize)\]\n#\[serde(rename_all_fields = \"PascalCase\")\]/g" "./rust-grpc/$name/$name.rs"
2024-07-16 20:20:23 +00:00
sed -i "s/ pub id:/ \[serde(rename = \"ID\")\]\n pub id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub time_id:/ \[serde(rename = \"TimeID\")\]\n pub time_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub file_id:/ \[serde(rename = \"FileID\")\]\n pub file_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub game_id:/ \[serde(rename = \"GameID\")\]\n pub game_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub user_id:/ \[serde(rename = \"UserID\")\]\n pub user_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub mode_id:/ \[serde(rename = \"ModeID\")\]\n pub mode_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub style_id:/ \[serde(rename = \"StyleID\")\]\n pub style_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub state_id:/ \[serde(rename = \"StateID\")\]\n pub state_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub place_id:/ \[serde(rename = \"PlaceID\")\]\n pub place_id:" "./rust-grpc/$name/$name.rs"
sed -i "s/ pub vip_server_id:/ \[serde(rename = \"VipServerID\")\]\n pub vip_server_id:" "./rust-grpc/$name/$name.rs"
done