First working version of cli packet generator
This commit is contained in:
parent
86a306664c
commit
2a553ed9af
|
@ -355,11 +355,36 @@ function action_generate() {
|
||||||
hashs=' {'
|
hashs=' {'
|
||||||
for field_name in "${!fields[@]}"
|
for field_name in "${!fields[@]}"
|
||||||
do
|
do
|
||||||
hashs+="\n $field_name = @$field_name,"
|
hashs+="\n $field_name: @$field_name,"
|
||||||
done
|
done
|
||||||
hashs="${hashs::-1}"
|
hashs="${hashs::-1}"
|
||||||
hashs+="\n }"
|
hashs+="\n }"
|
||||||
replace_line "$tmpfile" "{ foo: @foo," "${hashs:2}"
|
replace_line "$tmpfile" "{ foo: @foo," "${hashs:2}"
|
||||||
|
|
||||||
|
local packs=''
|
||||||
|
for field_name in "${!fields[@]}"
|
||||||
|
do
|
||||||
|
packs+=" "
|
||||||
|
field_type="${fields[$field_name]}"
|
||||||
|
if [ "$field_type" == "raw" ]
|
||||||
|
then
|
||||||
|
packs+="Packer.pack_raw(@$field_name) +\n"
|
||||||
|
elif [ "$field_type" == "int" ]
|
||||||
|
then
|
||||||
|
packs+="Packer.pack_int(@$field_name) +\n"
|
||||||
|
else # string or other
|
||||||
|
packs+="Packer.pack_str(@$field_name) +\n"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
replace_line "$tmpfile" Packer.pack_int "${packs:2:-4}"
|
||||||
|
local destfile
|
||||||
|
destfile="lib/models/$(basename "$tmpfile")"
|
||||||
|
if [ -f "$destfile" ]
|
||||||
|
then
|
||||||
|
echo "Error: file already exists '$destfile'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mv "$tmpfile" "$destfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_args() {
|
function parse_args() {
|
||||||
|
|
|
@ -32,8 +32,7 @@ class PacketName
|
||||||
# basically to_network
|
# basically to_network
|
||||||
# int array the SENDER sends to the RECEIVER
|
# int array the SENDER sends to the RECEIVER
|
||||||
def to_a
|
def to_a
|
||||||
Packer.pack_int(@foo) +
|
Packer.pack_int(@foo) + Packer.pack_str(@bar)
|
||||||
Packer.pack_str(@bar)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
Loading…
Reference in a new issue