mirror of
https://github.com/imezx/Warp.git
synced 2026-03-18 00:44:16 +00:00
chore(docs): update buffer.md
This commit is contained in:
parent
ff6a0c5cf4
commit
1200ff41f1
1 changed files with 33 additions and 1 deletions
|
|
@ -37,7 +37,8 @@ Define strict data schemas for optimized serialization and type safety.
|
||||||
"vector2",
|
"vector2",
|
||||||
"vector3",
|
"vector3",
|
||||||
"cframe",
|
"cframe",
|
||||||
"color3",
|
"color3", -- u8
|
||||||
|
"color3f16",
|
||||||
"instance",
|
"instance",
|
||||||
|
|
||||||
-- other types
|
-- other types
|
||||||
|
|
@ -48,6 +49,37 @@ Define strict data schemas for optimized serialization and type safety.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom Datatypes
|
||||||
|
|
||||||
|
### `.custom_datatype`
|
||||||
|
|
||||||
|
::: code-group
|
||||||
|
```luau [Variable]
|
||||||
|
(
|
||||||
|
name: string,
|
||||||
|
object: { any },
|
||||||
|
writer: (w: Writer, v: any) -> (),
|
||||||
|
reader: (b: buffer, c: number, refs: { Instance }?) -> (buffer, number))
|
||||||
|
): Writer
|
||||||
|
```
|
||||||
|
|
||||||
|
```luau [Example]
|
||||||
|
local Buffer = Warp.Buffer()
|
||||||
|
|
||||||
|
-- # this custom datatype must be registered on both server & client side
|
||||||
|
Buffer.Schema.custom_datatype("u64", {}, function(writer, value)
|
||||||
|
-- writing u64 logics here
|
||||||
|
end, function(b, cursor, refs)
|
||||||
|
-- reading u64 logics here
|
||||||
|
return b, cursor
|
||||||
|
end)
|
||||||
|
|
||||||
|
local DataSchema = Buffer.Schema.struct({
|
||||||
|
LongInteger = Buffer.Schema.u64, -- use the custom datatype
|
||||||
|
})
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
## Writer and Reader Functions
|
## Writer and Reader Functions
|
||||||
|
|
||||||
### `.createWriter`
|
### `.createWriter`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue