RBLXSerialize v0.7
a ROBLOX serialize that can serialize most ROBLOX DataTypes, Instances and all of their children.
Supports the majoirty of roblox instances and datatypes.
Update
- An early version of RBXSerialize (rewrite) has been released.
What is serialization?
This module acts as a all-in-one to a solution of “How Can i store obejcts in a datastore”. To learn more about what seralization is i recommedn reading this
What DataTypes are supported?
Summary
- String
- BinaryString
- Content
- ProtectedString
- UDim
- UDim2
- CFrame
- CoordianteFrame
- Boolean
- Float
- Number
- Int
- Int16
- Int32
- Int64
- ALL Enums!
- Faces
- BrickColor
- Vector3
- Vector2
- Color3
- Rect
- PhysicalProperties
- NumberRange
- Vector2int16
- Vector3int16
- ColorSequence
- ColorSequenceKeypoint
- NumberSequence
- NumberSequenceKeypoint
Okay? So how big is this thing?
Summary
***Storage Costs***
Disclaimer : This references how RAW DATA is stored, data is compressed then put under base92.
Firstly, the default number type is float;
It will only differ if the ROBLOX website specifies something other than “number”
=========================
-RBLXSerializer-
DataType : 1b -- a header, to tell what type of data it is.
-InstanceSeralization-
Default Number<FLOAT> : 4b
Instance Flat Cost : 1b --[1Byte InstanceName]
Property Flat Cost : 3b -- [2 Bytes for the PropertyName][1Byte for Value indicator]
Root Flat Cost : 1b
-NonInstanceSeralization-
Value Flat Cost : 2b -- [1byte for valueName][1Byte for Value indicator]
-Example- -- (APPROX)
Stings : "My Favorite Folder" ( 10b) -- Strings arent compressed by default!
Root Name : "HumanoidRootPart/BodyGyro" (30b) -- working on a better way
[Including the entire stringName of all of its children repeated]
=========================
-DataTypes-
Bool : 1b
Faces : 1b
Int : 2b
Enum : 2b
Float : 4b
UDim : 8b
Double : 8b
Vector2 : 8b
Vector3 : 12b
UDim2 : 16b
CFrame : 48b
Small analysis of how data is stored:
Let’s say we have a part with only 2 properties size and position, this is how it would be stored.
(1:DataType)+(1:InstanceName)+(3:Property)+(12:Vector3)(12:Vector3)
It would be stored in as little as 29Bytes.
So I’d say on your average per instance will be 50-100b.
How can i make them smaller.
- Remember that strings are stored as raw data, keeping simple names reduces the amount of bytes that has to be stored to describe a instance. Having a default instance name saves a lot of storage. (as defaults aren’t saved)
- Try not to use RBLXSerializer for things like CFrames, as they aren’t as optimized YET, most of my focus going forward is adding new features and datatype support.
How can I limit values I don’t want to save?
the RBLXSerializer.Allowed
ModuleScript allows you to create a whitelist for instance properties. The index of the table is determined by the .ClassName
of the instance.Backwards compatability is presevered when modifying this!
return {
["Part"] = {
Position = true,
Size = true,
}
}
This will make it so only those values are saved!
Okay im excited! How do i use RBLXSerialize?
Firstly here are some settings of RBLXSerialize
RBLXSerialize.SaveCFrames = (DEFAULT : FALSE)
-- CFrames are super large by default they are not saved ever.
-- unless you use encode(CFrame.new())
RBLXSerialize.UseBase92 = (DEFAULT : TRUE)
-- This allows you to store in datatores, but the size goes way up^^
Heres a general usage of RBLXSerialize,
Litearlly two methods, Encode() to save to a string. and Decode() to retrive to instance/Datatype.
local RBLXSerialize = require(script.Parent.RBLXSerialize)
local BinaryString = RBLXSerialize.Encode(dataTypeOrInstance, shouldCompress)
--- ^ You can copy its contents from console now! : )
local Instance = RBLXSerialize.Decode(BinaryString,IsCompressed)
Just a reminder, you can encode pretty much any of the supported datatypes. and pretty much any instance even ones with children:
All of these methods are valid!
-- Creating a instance with children
local Model = Instance.new("Model")
local Part = Instance.new("Part")
Part.Parent = Model
-- encoding instance and then immedetly decoding!
local BinaryString = RBLXSerialize.Encode(Model) -- > 1:1 Recation when decoded
-- this retrives the model after it has been decoded! all you need is the string.
local Model = RBLXSerialize.Decode(BinaryString,true)
-- encoding a part
local BinaryString = RBLXSerialize.Encode(Instance.new("Part"))) -- > 1:1 Recation when decoded
local Part = RBLXSerialize.Decode(BinaryString,true)
--encoding a cframe value!
local BinaryString = RBLXSerialize.Encode(CFrame.new())) -- > 1:1 Recation when decoded
local CFrame = RBLXSerialize.Decode(BinaryString,true)
--encoding a model!
local BinaryString = RBLXSerialize.Encode(Model,true)
local Model = RBLXSerialize.Decode(BinaryString,true)
Make sure to keep track if BinaryStrings are compressed otherwise it will likely result in an error when attempting to decode!
yeaaaah thats it!
How much can i really store ;/?
Yeah im not quite sure myself, when using the maximum amount of datastore storage, on average you could store up to 40,000 instances using this Serializer. (without compression)
Features
- Stored Instance referneces, the root system that RBLXSerialize uses to describe the structure of a instance children. Can also be used to describe the references to instances. Like properties of
.Adornee
. This allows for things like Welds and SelectionBoxes to be saved. There are very little serializers that will allow for this kind of value to be saved!
Limitations
Here some things you cannot do!
- Have a instance property value with more than 255 Characters.
- Having instance data that exceeds 255 bytes.
- Encode children of a unsupported instance.
.
Latest Version!
Example of encoded data
Summary
^Gv((AIMBt@23pTMHv/EMm_D:y=ARMuWmu*D$AAAAA?DUE#^J$XbCA3FHnHOXflBbjTACAAABtUAMAAAsLAAT|DAuWbS3LH*5N[dEAbLS8XLAAAA*hCtw(z!LRqAgAK`cu|xzW4YlD$AAAAA3DUEAA5FIAAAkBAABthL~x7nJ*o"IGXL8M@BgAAAAA`BKC>{^fUMD";Cy$GH5P$Af<G"AAAAXLFADAAA<CAAd~AAAA@A5!3WED5F.4`AIAAAAAsAYAoyAvi~AtgtN9j){B3(HTvWAAAA6yE"BAAAmBAA8sAA#T@Agz3WED5Fo4`AIAAAAAsAYAuW/uLq8sV!3wc)$BgAAAAA/BKCAA:CEAC"#AAAXL
6 instances described in 350bytes.
Reagarding DataType support.
Summary
Im working on supporting more DataTypes that are needed! If there are any that are not listed in the supported instances. Let me know, and i can add them!
TLDR; Can Serialize pretty much anything! Let’s you store instances in strings to store them in things like datastores !