Clean up serialization

* Adds a header to serialized data (to make version checking sane).
  * Removes the duplicate deserialization for `worldedit.deserialize` and `worldedit.allocate`.
  * Optimizes `worldedit.deserialize` by only deserializing the data once.
  * Makes some fields optional.
  * Cleans up the comments and a little of the code style.
This commit is contained in:
ShadowNinja
2014-10-24 15:01:46 -04:00
parent 70c24c9501
commit 796aa3870d
5 changed files with 230 additions and 238 deletions

View File

@ -911,9 +911,12 @@ minetest.register_chatcommand("/allocate", {
local value = file:read("*a")
file:close()
if worldedit.valueversion(value) == 0 then --unknown version
worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
local version = worldedit.read_header(value)
if version == 0 then
worldedit.player_notify(name, "File is invalid!")
return
elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
end
local nodepos1, nodepos2, count = worldedit.allocate(pos, value)
@ -963,8 +966,12 @@ minetest.register_chatcommand("/load", {
local value = file:read("*a")
file:close()
if worldedit.valueversion(value) == 0 then --unknown version
worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
local version = worldedit.read_header(value)
if version == 0 then
worldedit.player_notify(name, "File is invalid!")
return
elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
return
end