DataSerializer - A package for compressing data with support for DataStore

DataSerializer

IF YOU FIND A BUG, PLEASE LET ME KNOW BELOW

A package for compressing/decompressing data with support for DataStore.


Downloading

Wally (recommended)

Versions 1.*.* assure backwards compatibility

DataSerializer = "ohimesan/dataserializer@1.1.7"

Creator Marketplace


Benchmark

All tests taken with Base64 encoding and max compression (Zlib level 9)

  --------------------------------
  Testing "API-Dump"
  
  Serialized in: 4254ms, 520 chunks
  Deserialized in: 50ms
  
  Original size: 1167706
  Serialized size: 321833
  Comparison: 28% of original value
  --------------------------------
  Testing "PlayerData1"
  
  Serialized in: 14ms, 5 chunks
  Deserialized in: 1ms
  
  Original size: 6937
  Serialized size: 4364
  Comparison: 63% of original value
  --------------------------------
  Testing "PlayerData2"
  
  Serialized in: 35ms, 14 chunks
  Deserialized in: 1ms
  
  Original size: 16870
  Serialized size: 8359
  Comparison: 50% of original value
  --------------------------------
  Testing "PlayerData3"
  
  Serialized in: 2ms, 2 chunks
  Deserialized in: 1ms
  
  Original size: 1450
  Serialized size: 1039
  Comparison: 72% of original value
  --------------------------------
  Tests made: 4
  Average percentage: 53%

API Dump


How does it work?

Expand

Bitbuffer

The BitBuffer module with some additions is used to serialize values

VarInts

VarInts are variable-length integers. They are good because as the number increases, the length also does. Making short numbers use less amount of data.

Reutilizing

This is the most important part, reutilizing values. Any kind of value reference.
There are a lot of dictionaries with repeating indexes, and it’s good to shorten it to ~2 bytes.


Documentation

Expand
These are all the values currently supported
export type SupportedType =
      nil
	| boolean
	| number
	| string
	| { [SupportedType]: SupportedType }
	| BrickColor
	| Color3
	| CFrame
	| Vector3
	| Vector2
	| UDim2
	| UDim
	| Ray
	| Rect
	| Region3
	| Enum
	| NumberRange
	| NumberSequence
	| ColorSequence
  • .Serialize( SupportedType input, number? zlibLevel, boolean? useBase64 ) → {string} output

Serializes a data and returns the chunks

input is the input, can be any value in SupportedType.

zlibLevel is the level of compression, the higher the lightest, but slowest. Use 0 for disabling, 9 for max compression. Defaults to 6.

useBase64 is whether the data will be encoded into valid characters or not. Base64 makes the result ~33% heavier, but does the job.
Keep it enabled if you are storing the output in a DataStore, as it only accepts valid characters. Defaults to true.

  • .Deserialize( {string} input, boolean? usesBase64 ) → {string} output

Deserializes the previously serialized data

input is the previously serialized data

usesBase64 is whether the input is using Base64 or not.


Example code

local DataSerializer = require(DataSerializer)

local playerData = {
		Admin = true,
		Values = {
				Coins = 2000000,
				Diamonds = 7000,
				Skills = {
						"Thorns",
						"Flying",
						"X-Ray"
				}
		}
}

-- Returns an array of strings, that you can save in DataStore
-- to deserialize later
local encoded = DataSerializer.Serialize(playerData)
DataStore:SetAsync("Player_1", encoded)
local DataSerializer = require(DataSerializer)

local encoded = DataStore:GetAsync("Player_1")
local playerData = DataSerializer.Deserialize(encoded)

Update log

1.1.7

Fixed major bug where sometimes the module wouldn’t load correctly

1.1.6

Fixed major bug where Roblox datatypes wouldn’t work

1.1.5

Checking something

1.1.4

Improved Base64 performance

I switched the encoding/decoding functions to
fast_base64.lua · GitHub

Made negative integers lighter

1.0.0 > 1.1.3

A lot

Not including here due to embarrassment. But here is a link!

26 Likes

I might be missing something, but won’t this error as script.Parent.Parent["dekkonot_bitbuffer@1.1.1"]["bitbuffer"] does not exist?

4 Likes

I am pretty sure they messed something up when uploading it on the creator marketplace, as this is how you would require modules if you’re using Wally.

2 Likes

what? but it’s alright when I pull the model
image

1 Like

I reuploaded it, please try again

1 Like

OK so I just realized how dumb I was, I thought that the MainModule is broken
now I added the actual Bitbuffer code, so it should work now

2 Likes

thanks for making this, i need this so much!

1 Like

This doesn’t seem to be working anymore.

No errors on serialization, Always getting “Invalid type” errors on Deserializing.

Seems if you try to serialize tables containing CFrames, it will be unable to deserialize the result. Still works with strings and integers as far as I can tell.

1 Like

yeah… it’s been broken for quite a long time already
I was planning on remaking all of it from 0, with many new features and better code
sadly I lack time right now, so that’ll take quite some time to be done

1 Like

I think it still works correctly with Vectors, in my testing I have not encountered any issues.