RBNSR - A Store Lua Tables /w Roblox Datatypes

RBNSR v0.1

A Store Lua Tables /w Roblox Datatypes.


What is this?
This module acts as a solution, to save all Roblox datatypes in a custom format (A Normal Table). This can act as more of an optimized solution if you dont need to store an entire instance.

If you DO Want to store entire instances, i’d recommned finding my other module here:

What is serialization?

Serilization is basically the abililty of saving certain datatypes into a object or differnt structure. Learn more about it here :

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

Limitations/Rules

  1. Unlike JSON, rbnsr can story any dictonary with a valid index including roblox datatypes. Yes Mixed Tables work. You can even index with tables.

  2. RBNSR is 130% bigger than json, however this is mostly due to rbnsr storing every index and value, however roblox datatypes usally take no more than 10bytes to store. ( 90% Of the time will be smaller than serializing inside json ).

How to use!

Using rbnsr, is just like using :JSONEncode and JSONDecode, expect it uses two methods Serialize and Deserialize

Firstly, require the module, and create a table to encode.

-- Heres an 
local toEncode = {
 ["ComplicatedDataType"] = ColorSequence.new{
    ColorSequenceKeypoint.new(0,Color3.new(0.368627, 1, 0.270588)),
    ColorSequenceKeypoint.new(1,Color3.new(1, 0.0666667, 0)),
  },
  [Vector3.new(1,5,3)] = {
	["VectorIndex"] = 1 
  },
  ["StringIndex"] = {
    "MixedTables",
    ["StringIndex"] = "MixedTables"
  },
  VectorValue = Vector3.new(1,2,3)
}

local rbnsr = require(game.ServerScriptService.rbnsr)

Now Serialize/Deserailze


local encoded = rbnsr.Serialize(toEncode) 

-- now to decode

local decodedTable = rbnsr.Deserialize(encoded)

-- Now!  toEncode == decodedTable

print("Compare:",toEncode,decodedTable)

And thats it! rbnsr can easily replace any jsonencode call without any extra setup.

Latest Version!

4 Likes

This sounds interesting! This is surely a great way to serialize Roblox data types.

1 Like

Right of the bat I can already see some errors within this module.

image
You can’t type write a table in Roblox Lua.


Vector3.new() function only accepts 3 arguments and no more and less than that.

This wont actually cause an error,
Methods are prototypes to show up in syntax highlighting to give an idea on how to use the function ; therefore it doesnt really matter what is type casted. The methods are later overwritten, and will not cause an error.

For this, doesnt really cause an error but i can see some unintended functionality i’ve replaced it with `Ray.new(Vector3.new(x,y,z),Vector3.new(x1,y1,z1))

I’ve pretty much abonded this thread, however this contains all of the serailization/deserialization for most roblox datatypse if anyone is intrested in creating their own serializer.

1 Like

I am pretty sure that this fails to deserialize boolean values that are in a dictionary