blueserializer
serialize and deserialize roblox's primitive typesGithub repository | Releases downloads and rbxm | Readmedotmd | wally package
Why?
Roblox has a thing called “primitive types”, If you dont know what these are, these are special values like Vector3. You use them alot in roblox development, even if you didn’t know.
But there are a few issues with these,
- Cant be saved in datastore
- Cant be transferred to remote events
- Etc
Serializing these values are the solution. But writing the serializers for these are a huge pain, so this small module will help.
ze famous examples
local blueSerializer = require(path.to.blueserializer)
local serialized = blueSerializer.serialize(Vector3.new(1, 5, 88))
print(serialized) -- >> {"V", 1, 5, 88}
print(blueSerializer.deserialize(serialized)) -- >> Vector3.new(1, 5, 88) or in the output 1, 5, 88
-- blueSerialize.deSerialize exists as an alias of blueSerializer.deserialize
local blueSerializer = require(path.to.blueserializer)
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("mypart")
local myPart = workspace.myPart
-- i want to save the part's position and the part's color3 in workspace
dataStore:SetAsync("mypart", {
Position = blueSerializer.serialize(myPart.Position),
Color3 = blueSerializer.serialize(myPart.Color3)
})
-- the loading
local dat = dataStore:GetAsync("mypart")
myPart.Position = blueSerializer.deserialize(dat.Position)
myPart.Color3 = blueSerializer.deserialize(dat.Color3)
-- note this is psuedo example code and is only supposed to represent the basic usage
-- of blue serializer
Supported primitive types for this module
Supported primitive types |
---|
CFrame |
Vector3 |
Color3 |
EnumItem |
BrickColor |
TweenInfo |
Vector2 |
Vector2int16 |
Vector3int16 |
UDim |
UDim2 |
Region3 |
Region3int16 |
PhysicalProperties |
Rect |
NumberRange |
Ray |
DockWidgetPluginGuiInfo |
PathwayPoint |
(this list might mot be up to date or be updated frequently but you can read the serializerList.lua in module in the repo to see the supported primitive types)
Note
Not the most optimized serializer
Thanks and feedback is appreciated