RBLXSerialize - a easy to use and really cool all-in-one Roblox Serializer

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.

  1. 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)
  2. 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!:slight_smile:

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

  1. 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!

  1. Have a instance property value with more than 255 Characters.
  2. Having instance data that exceeds 255 bytes.
  3. Encode children of a unsupported instance.
    .

Latest Version!

Example of encoded data

Summary

ex.png

^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 !

71 Likes

might wanna put this in #resources:community-resources

2 Likes

Thanks! That could of been bad,

:+1:

2 Likes

Alright i have fixed this! I forgot to allow copyiong.

1 Like

WHAT THE HECK! this is the most useful module i’ve ever seen (I think im gonna faint).

So, this actually supports models right?!.. this is insanity. Yet, i dont think it supports the scripts within the models… Do you know how to make it so that the scripts also get saved? if not idk then, was planning on using this on vehicles.

Im currently working on switching on a more current API Dump, but yes scripts will be savable soon. im also working on a ton of new DataType support such as ColorSequence and NumberSequence.

I may bundle this into the next update.

im just thinking, maybe for now. When the vehicle finishes loading, it will clone and parent preset scripts from ServerStorage/ReplicatedStorage to the model of the vehicle (Very simple indeed) I just hope it doesnt break the models… Btw, Does this module store welds properly? I mean regarding at the main post, im not sure.

EDIT:
Basically, I was talking about storing references to instances, and how it was in-progress and i was going to upload the update soon…

Alright i updated, however there is a problem. Scripts cannot read the .Source of other scripts so its impossible for this module to save scripts /w source. However, a plugin version of this module could.

wait slow down… i dont understand what you mean here because your replies are all over the place. Please explain to me thoroughly the changes made to the module and the explain to me what you meant by cyclic instance references and what do you mean here:

Sorry about that LOL. Now the module can store references things like welds or Adornee properties.

As long as ; The referenced instance is a decedent of the serialized instance.

E.G ; As long as the weld doesnt try to weld to something random in workspace

So you mean, that now the module supports storing welds! YAY!!

However question: I think in one of ur replies you were talking about the scripts… for my questions if the module supports scripts in the chosen model?

Due to Script Identity, you cannot read or write the contents of a script(.Source). Plugins have this ability however.

aw damn, would be so useful lol. Aight, ima use this module and test it.

does it support mesh doe? like meshID and etc.

Would you mind adding texture id’s of meshes and meshparts if you dont mind

Encoding sibling parts with the same name causes them to be parented inside of each other after decoding. I would add this to limitations.
image

Also, the PrimaryPart property of a model cannot be encoded and decoded, which is another notable limitation.

Alright for the PrimaryPart issue I’ll fix this is the next update. it has something to do how it only allows decedants of the main model to have instance references. But its an easy fix,

I have also fixed this, really werid issue that only showed up in this version. It happens mainly because i changed how root names are decoded. Hopefullly theese fixes will come out later today as a do some more testing.

Thanks for letting me know!

1 Like

Alright both issues have been fixed! Thanks again.

1 Like