expanding buffer

This commit is contained in:
EternityDev 2024-03-16 23:49:23 +07:00
parent 4b568356c8
commit 01c5533394
11 changed files with 89 additions and 18 deletions

BIN
Warp.rbxm

Binary file not shown.

View file

@ -1,6 +1,12 @@
{
"name": "Warp",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"Warp": {
"$path": "src"
}
}
}
}

View file

@ -39,6 +39,7 @@ function side() {
text: 'Utilities',
items: [
{ text: 'Signal', link: '/api/1.0/signal' },
{ text: 'Buffer', link: '/api/1.0/buffer' },
]
},
]

3
docs/api/1.0/buffer.md Normal file
View file

@ -0,0 +1,3 @@
# Buffer <Badge type="tip" text="utilities" />
A Additional buffer.

View file

@ -87,7 +87,7 @@ Disconnect the event connection.
```lua [Variable]
(
key: string
)
): boolean
```
```lua [Example]
@ -128,7 +128,7 @@ This function have rate limiting it self and configured from server.
## `:Invoke` <Badge type="warning" text="yield" />
Semiliar to `:InvokeServer`, its for Invoke to a server.
Semiliar to `:InvokeServer`, but it have timeout system that not exists on `RemoteFunction.InvokeServer`.
::: code-group
```lua [Variable]
@ -139,7 +139,7 @@ Semiliar to `:InvokeServer`, its for Invoke to a server.
```
```lua [Example]
local Request = Remote:Invoke(2, "Hello World!")
local Request = Remote:Invoke(2, "Hello World!") -- this yield until it response
```
:::
@ -152,7 +152,7 @@ This function is yielded, once it timeout it will return nil.
Wait the event being triggered.
```lua
Remote:Wait()
Remote:Wait() -- :Wait return number value
```
::: warning
@ -161,7 +161,7 @@ This function is yielded, Invoke might also ping this one and also causing error
## `:Destroy`
Disconnect all connection of event and remove the event from Warp
Disconnect all connection of event and remove the event from Warp list
```lua
Remote:Destroy()

View file

@ -97,7 +97,7 @@ Disconnect the event connection.
```lua [Variable]
(
key: string
)
): boolean
```
```lua [Example]
@ -170,7 +170,7 @@ Remote:FireExcept(true, { Players.Eternity_Devs, Players.Player2 }, "Hello World
## `:Invoke` <Badge type="warning" text="yield" />
Semiliar to `:InvokeClient`, its for Invoke to a client.
Semiliar to `:InvokeClient`, but it have timeout system that not exists on `RemoteFunction.InvokeClient`.
::: code-group
```lua [Variable]
@ -195,7 +195,7 @@ This function is yielded, once it timeout it will return nil.
Wait the event being triggered.
```lua
Remote:Wait()
Remote:Wait() -- :Wait return number value
```
::: warning

View file

@ -16,7 +16,7 @@ local Buffer = require(Util.Buffer)
function Client.new(Identifier: string)
local self = setmetatable({}, Client)
self._buffer = Buffer.new()
self._buffer:writeu8(Serdes(Identifier))
self._buffer:wu8(Serdes(Identifier))
self.id = Buffer.convert(self._buffer:build())
self.fn = {}
self.IsConnected = false

View file

@ -17,7 +17,7 @@ local Buffer = require(Util.Buffer)
function Server.new(Identifier: string, rateLimit: Type.rateLimitArg?)
local self = setmetatable({}, Server)
self._buffer = Buffer.new()
self._buffer:writeu8(Serdes(Identifier))
self._buffer:wu8(Serdes(Identifier))
self.id = Buffer.convert(self._buffer:build())
self.fn = {}
self.IsConnected = false

View file

@ -6,12 +6,21 @@ DedicatedBuffer.__index = DedicatedBuffer
local create = buffer.create
local copy = buffer.copy
local writei8 = buffer.writei8
local writei16 = buffer.writei16
local writei32 = buffer.writei32
local writeu8 = buffer.writeu8
local tostring = buffer.tostring
local writeu16 = buffer.writeu16
local writeu32 = buffer.writeu32
local writef32 = buffer.writef32
local writef64 = buffer.writef64
local writestring = buffer.writestring
local default = {
point = 0,
size = 256,
next = 0,
size = 128,
bufferSize = 128,
}
function DedicatedBuffer.alloc(self: any, byte: number)
@ -23,9 +32,13 @@ function DedicatedBuffer.alloc(self: any, byte: number)
end
local newBuffer: buffer = create(size)
DedicatedBuffer.copy(self, 0, newBuffer)
copy(newBuffer, 0, b)
b = newBuffer
self.point = self.next
self.next += byte
end
function DedicatedBuffer.build(self: any): buffer
@ -36,23 +49,64 @@ function DedicatedBuffer.build(self: any): buffer
return build
end
function DedicatedBuffer.writeu8(self: any, val: number)
function DedicatedBuffer.wi8(self: any, val: number)
DedicatedBuffer.alloc(self, 1)
writei8(self.buffer, self.point, val)
end
function DedicatedBuffer.wi16(self: any, val: number)
DedicatedBuffer.alloc(self, 2)
writei16(self.buffer, self.point, val)
end
function DedicatedBuffer.wi32(self: any, val: number)
DedicatedBuffer.alloc(self, 4)
writei32(self.buffer, self.point, val)
end
function DedicatedBuffer.wu8(self: any, val: number)
DedicatedBuffer.alloc(self, 1)
writeu8(self.buffer, self.point, val)
self.point += 1
end
function DedicatedBuffer.wu16(self: any, val: number)
DedicatedBuffer.alloc(self, 2)
writeu16(self.buffer, self.point, val)
end
function DedicatedBuffer.wu32(self: any, val: number)
DedicatedBuffer.alloc(self, 4)
writeu32(self.buffer, self.point, val)
end
function DedicatedBuffer.wf32(self: any, val: number)
DedicatedBuffer.alloc(self, 4)
writef32(self.buffer, self.point, val)
end
function DedicatedBuffer.wf64(self: any, val: number)
DedicatedBuffer.alloc(self, 8)
writef64(self.buffer, self.point, val)
end
function DedicatedBuffer.wstring(self: any, val: string)
DedicatedBuffer.alloc(self, #val)
writestring(self.buffer, self.point, val)
end
function DedicatedBuffer.flush(self: any)
self.point = default.point
self.next = default.next
self.size = default.size
self.buffer = create(256)
self.buffer = create(default.bufferSize)
end
function DedicatedBuffer.new()
return setmetatable({
point = default.point,
next = default.next,
size = default.size,
buffer = create(256)
buffer = create(default.bufferSize)
}, DedicatedBuffer)
end

View file

@ -12,6 +12,7 @@ local Client = script.Client
local Type = require(script.Type)
local Assert = require(Util.Assert)
local Signal = require(script.Signal)
local Buffer = require(Util.Buffer)
if IsServer then
require(Server.ServerProcess).start()
@ -64,7 +65,11 @@ function Index.fromSignalArray(arrays: { any })
for _, identifier: string in arrays do
copy[identifier] = Index.Signal(identifier)
end
return copy :: typeof(copy)
return table.freeze(copy) :: typeof(copy)
end
function Index.buffer()
return Buffer.new()
end
return table.freeze(Index) :: typeof(Index)

View file

@ -13,4 +13,6 @@ return {
Signal = Index.Signal,
fromSignalArray = Index.fromSignalArray,
buffer = Index.buffer,
}