From d8f2110b486bac7abb3a459de6dbb5f214af9a75 Mon Sep 17 00:00:00 2001 From: Srlion Date: Sun, 15 Dec 2024 21:46:16 +0200 Subject: [PATCH] Update README example for version 4.0.0 --- README.MD | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.MD b/README.MD index 1588226..c5666b9 100644 --- a/README.MD +++ b/README.MD @@ -41,6 +41,7 @@ You can also add custom types! ```lua local Encoder = sfs.Encoder local Decoder = sfs.Decoder +local ENDING = Encoder.ENDING local SortedMap; do local SortedMapMethods = {} @@ -80,33 +81,30 @@ local SORTED_MAP_ID SORTED_MAP_ID = sfs.add_custom_type("SortedMap", function(buf, v) Encoder.write_byte(buf, SORTED_MAP_ID) - Encoder.write_u16(buf, v.size) - if Encoder.write_table(buf, v.map) then -- if it returns true, there was an error return true end + Encoder.write_byte(buf, ENDING) if Encoder.write_array(buf, v.keys, v.size) then -- if it returns true, there was an error return true end + Encoder.write_byte(buf, ENDING) end, function(ctx) ctx[1] = ctx[1] + 1 -- Skip the type byte (SORTED_MAP_ID) - local size, map, keys, err - - size, err = Decoder.read_u16(ctx) - if err then return nil, err end + local map, keys, err - map, err = Decoder.read_table(ctx, size) + map, err = Decoder.read_table(ctx, ENDING) if err then return nil, err end - keys, err = Decoder.read_array(ctx, size) + keys, err = Decoder.read_array(ctx, ENDING) if err then return nil, err end return setmetatable({ map = map, keys = keys, - size = size + size = #keys }, SortedMap.Meta) end)