RBXSerialize v0.1
A All-In-One Roblox instance and datatype serializer
Supports the majority of ROBLOX instances and datatypes.
Version Notes
- This is an early version! Some things may not work as expected. I’m releasing it semi-unfinished because of how long its taking me to complete the rewrite.
What is serialization?
RBXSerialize acts as a solution to, “How can i store obejct in a datastore” or “how can i store leaderstats”. Although this modules somewhat encourages bad habits, the point was making this as a easy and all-in-one solution whilst being compact and fast. To learn more about what seralization is i recommend reading this.
Getting started.
It’s extermely easy to get started using this module.
Ah-ha! Step 1, requiring the module and building the api.
local RBXSerialize = require(game.ReplicatedStorage.Modules.RBXSerialize)
RBXSerialize.BuildAPI()
If you dont build the API then the encode methods will fail.
So we got the module. Next step Encoding
local RBXSerialize = require(game.ReplicatedStorage.Modules.RBXSerialize)
RBXSerialize.BuildAPI()
-- Different Example Values
local Model = Instance.new("Model")
local Part = Instance.new("Part",Model)
local CFrame = CFrame.new(Vector3.new(0,10,35))
local ModelEncoded = RBXSerialize.Encode(Model)
local CFrameEncoded = RBXSerialize.Encode(CFrame)
Now our information is stored in a string format. We can use this string to Decode.
local ModelEncoded = RBXSerialize.Encode(Model)
local CFrameEncoded = RBXSerialize.Encode(CFrame)
-- Theese values are identical to the orginal. You can store the string and recreate it later.
local NewModel = RBXSerialize.Decode(ModelEncoded)
local NewCFrane = RBXSerialize.Decode(CFrameEncoded)
That’s it! You should now be a pro at decoding and encoding instances using RBXSerialize. Remember that you should save the encoded string to hold on to the instance data.
Things to Note
You can also modify the DeepValues
,PostValues
,AlwaysSave
,NeverSave
tables under RBXSerialize to change how the saving works for certain classes.
You can also serialize custom references or references outside of the instance your encoding by using RBXSerialize.RegisterReferences({})
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.
Features
Some unique features of RBXSerialize.
- Saves Instance References, Adornee, Parent, and ObjectValue.Value properties.
- Saves Attributes.
- No limitation with instance names.
Latest Version!
Here is the latest available version of RBXSerialize.
FAQ
What does encoded data look like?
Summary
RawData Example
This is what raw data looks like for instance data.
^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.
Will more DataTypes be supported in the future?
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!
What DataTypes are supported?
Summary
Suported DataTypes
- 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.
TLDR; Can Serialize pretty much anything! Let’s you store instances in strings to store them in things like datastores !