Turn objects into strings! - SerialBit

About

SerialBit was made with speed and efficiently in mind. It’s made to store objects. For example, lets say a player made a cool build. How would you save it? You can’t store Instances. But, you can store strings. Serialization is the process the process of converting the state of an object into a form that can be persisted or transported. So, in order to save a build, you could use SerialBit, and then happily store your player builds in a datastore, using a compressed string.

See these totally not free model generic huts here?
image
image

Well, the hut on the far left is the original.
The middle, is a model completely rebuilt using SerialBit.
The right, is rebuilt by another serialization module, RbxSerialize

SerialBit was quite accurate, don’t you think?

SerialBit took 0.123 seconds to encode, compress, decode, decompress and then load this model! Without yielding, this would be faster (but you don’t want to crash the server with large models, do you? :wink: )

Infact, heres the string that SerialBit used to create this model.

Serialized string

What kind of cryptic language is this?!?!?! Witchcraft I say!
This string stores all the properties and descendants of the object.

I@jrA1dTC@b|!j03~ER;m9bp7$|GCF4iRF7V>CSOM:=Dsek4oH`x!~~6zV`lK0Bl_56xKw,FAS;zDb~]B;Or.|Pk0k(IvFPs5>S82g.#D7&nJ&Mpl8_jU[.1Jsn(_;2r8?lI:|s<_jQn<~*s3l}bQ~bIPs6,LQ^%LF{id/|;VCa+*][OmrvyR>[__|4eB&yXy)49Aqe=;8^_Mh7{{`Sha92}7e3gUrZg<(25y*fU3*j.@(Nh%>|$zlCVD(|:u9d{l]Ing&nEi{jga&%%B>TW+=l3a?RU&ox*8tAX^js%BV,HAi4fq?<uQt$Ip//?t@?k"Q8yP^rU/3=TrLtW/{<N:?mrQ;?pG([xq8bU]_%,D+"7;mXSmXNb6834.>3xxU`BsyE9yP!t^)]~zYI`eo+vBTD~8PM&wny$LCQ57ssfI0O/9%TCb9HgjED5urAUZ7W!fE>WQ0wCOOeyZvf;kfR5pbQZ)7;CM$ZvgGG>+7N)}.IFIwRXtTH/&<yC.TRrQLOD*r~9$P}pQC^VF<])]P3gN@oDi>^_PW^_N/rg&3R(&_BIr%rJJxSf"iYIXLV"vA@Lz=f`pRWS^C4CN[g5U~9s*4<U)WzB&4$fbdE2Rj>ZC;C%@_/dZD@hi{`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string of 3.6k. (That’s quite the difference)

Currently, it’s there’s just two functions. But, I can always add more! What do you think?

SerialBit.serial(Object: Instance): string

Serializes the instance and it’s descendants into a string. This can be loaded into an exact copy with SerialBit.struct

SerialBit.struct(Serial: string): Instance

Instances the model from the serial string. Returns a Model.

SerialBit.reference(Object : Instance) : void

The object passed must have an attribute called “REF_ID”. The descendants of this object must also have an attribute called “REF_CHILD_ID”. When serializing a model with a reference, they must have the exact same attributes, but can have different properties.

Selected the desired object(s) and then run this code in the command bar
local Selection = game:GetService("Selection") local Selected = Selection:Get() for i, v in Selected do local AllObjects = v:GetDescendants() v:SetAttribute("REF_ID", game:GetService("HttpService"):GenerateGUID(0):split("-")[1]) for i = 1, #AllObjects do local Object = AllObjects[i] Object:SetAttribute("REF_CHILD_ID", game:GetService("HttpService"):GenerateGUID(0):split("-")[1]) end end
Example

This is our reference object.
image
image

In our script, we’d add this using SerialBit.reference
image

We would then serialize like normal.
We can also change the properties of the reference object:
image
(hes now tall!)

And when loading the object into the game, it will clone the original reference object, and then apply all of the properties.
You can also use models and basically anything else as references, as long as they have the special attributes.
image
(It worked! But… everything was unanchored :sweat_smile:)

image

If you have any issues, suggestion, or nit-picks, please, leave a post! I’d like to hear from you all. Also, this is one of my first posts! :slight_smile:

Doesn’t support MeshParts or Unions. Unfortunately, MeshParts are impossible to implement without using SpecialMeshes, which, in my opinion, is cheating! Union support may be something in the future :eyes:

30 Likes

That’s interesting! I can’t get my hands on it right now, but it could be useful for things such as exporting data from live games into Studio, or creating dynamic place update systems if this serialization really works.

1 Like

you could check for already existing assets saved in the game and clone them for mesh parts and unions or have a folder for it to check for resources

1 Like

That’s something I could totally implement!

[EDIT: Working on it now.]

Update v1.1.0

Added boolean SerialBit.DebugPrints

Added SerialBit.reference

Instructions on how to use it have been added to the post.

This looks amazing! I’ll definitely check it out.

Why is it that

1 Like

Well, you cant set the MeshId of a MeshPart in scripts. But, you can use SerialBit.reference instead, just with a bit more setup. Hope that helped. :slight_smile:

1 Like

Ah, okay. Never knew that you couldn’t set the MeshId of meshparts. Good to know.

1 Like

the package version is offsale

My bad, I just discovered i dont think you can share packages.

why not release it as a model (not a package)

It is released as a model. I released a package along with it, realised it doesn’t work, then removed it.

Nice work, I’ve abandoned by module due to how busy i am nowadays. I use some super old purelua library for compression and don’t necessarily understand it too much. Hence why now my compression is worse. Anyways there are some isseus like the way you store datatypes. However in some cases storing datatypes in pure text will be smaller. And in some cases it will be significantly bigger. Something i’ve wanted to implement is multiple headers for different encoding methods of datatypes and only use the smallest one. Howerver i never got around to it. The point is, offset this model with extreme decimal percision and with a great offset from the world origin and you will use significantly more memory. Consider storing some datatypes in a raw format.

1 Like

This is very cool and useful for safely storing models in your game with out having to worry too much about game theft.

All we need now is a client script serialization which will prevent client code theft and exploiters from viewing the script. All though running said code might be another challenge in it self too.

Keep up the great work!

1 Like

This module wasn’t for securing your game, but rather, for example, storing player builds. Unfortunately, i dont think anything like this is possible.

1 Like

Hello! First of all, I dont understand the compression module I use either :sweat_smile:. Also, wdym “raw format”

The purpose of the module was to condense everything into a string for storage (eg. Datastore). Do you mean storing it raw as in, like inside a table? That I can totally add as an option of storage, too!

Store all numbers in binary. use string.pack() or some sort of binary stream this will decrease your size significantly.

2 Likes

Thanks for the advice, ill have to research this stuff when I get home

did you implement that for the current update?

I really appreciate the idea!

I already implemented it! It was part of version 1.1.0. If you have any other ideas, tell me!