(Near Optimal DataStore) BitBuffer

At least I think it’s near optimal
~if you know how to improve it please do

If you want to learn about BitBuffers, I think this tutorial on how to use stravant’s BitBuffer by TheNexusAvenger is useful

+/- stravant’s bitbuffer:
+nicer API
+stores more compactly
-no innate Roblox userdata support(you shouldn’t be storing them in a BitBuffer though)
+predefined int,uint,short,ushort,etc types
+full float support: inf,-inf,nan,and subnormals

I believe the speed is about the same(fast enough for practical usage if you don’t compute 1000 260k [datastore-valid] character BitBuffers at once-so don’t save all player datas at once, save player one, then wait 5 seconds, etc (and you can even pause while manipulating a single player’s buffer))

Sample usage:

local buff=BitBuffer.New()
buff:UDouble(1/0):Int(123456789):Bool(true):String'Hi'
local s=buff:DataStore()
print(#s)
local buff2=shared.BitBuffer.DataStore(s)
print(buff2:UDouble())
print(buff2:Int())
print(buff2:Bool())
print(buff2:String())
Output

24
inf
123456789
true
Hi

Module link
ghostbin

Thanks for reading
If you have any suggestions, please message me on discord Acreol#0001

10 Likes

I’d suggest switching that Hastebin to something like Ghostbin, since I think Hastebin clears pastes occasionally.

I put it on Ghostbin for you, here’s the link.

2 Likes

Out of curiosity, is there a difference between stravant’s BitBuffer and Adventus’?

There is a pro/con list in the OP

one thing that isnt mentioned here though is that this one uses two’s complement too so it can store 2^(width-1) when using signed numbers (stravants only stores up to 2^(width-1)-1)

One way the api is nicer is that you dont have separate WriteString and ReadString methods (and others), theres just one String method which knows whether to write or read based on how the buffer was instantiated: if it was created from a string(base64,datastore,dump(base256))then its reading the buffer(deserializing) else it writes to the buffer(serializes)

1 Like

Ohh, sorry, I thought you were just giving a pro/con list for using bit-based saving in general, whoops

1 Like