mirror of
https://github.com/imezx/Warp.git
synced 2026-06-02 12:18:32 +00:00
rewrite(phase2): minor
This commit is contained in:
parent
3e58ebc944
commit
ef25d2cf6c
1 changed files with 63 additions and 67 deletions
|
|
@ -897,8 +897,7 @@ unpackValue = function(buf: buffer, pos: number, refs: { any }?): (any, number)
|
||||||
buffer.readf32(buf, pos + 4),
|
buffer.readf32(buf, pos + 4),
|
||||||
buffer.readf32(buf, pos + 8),
|
buffer.readf32(buf, pos + 8),
|
||||||
buffer.readf32(buf, pos + 12)
|
buffer.readf32(buf, pos + 12)
|
||||||
),
|
), pos + 16
|
||||||
pos + 16
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if t == T_NUMBERRANGE then
|
if t == T_NUMBERRANGE then
|
||||||
|
|
@ -909,8 +908,7 @@ unpackValue = function(buf: buffer, pos: number, refs: { any }?): (any, number)
|
||||||
return Ray.new(
|
return Ray.new(
|
||||||
Vector3.new(buffer.readf32(buf, pos), buffer.readf32(buf, pos + 4), buffer.readf32(buf, pos + 8)),
|
Vector3.new(buffer.readf32(buf, pos), buffer.readf32(buf, pos + 4), buffer.readf32(buf, pos + 8)),
|
||||||
Vector3.new(buffer.readf32(buf, pos + 12), buffer.readf32(buf, pos + 16), buffer.readf32(buf, pos + 20))
|
Vector3.new(buffer.readf32(buf, pos + 12), buffer.readf32(buf, pos + 16), buffer.readf32(buf, pos + 20))
|
||||||
),
|
), pos + 24
|
||||||
pos + 24
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if t == T_COLSEQ then
|
if t == T_COLSEQ then
|
||||||
|
|
@ -1013,40 +1011,41 @@ function Schema.struct(fields: { [string]: SchemaType }): SchemaType
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
if s.type == "u8" then
|
local schema_type = s.type
|
||||||
|
if schema_type == "u8" then
|
||||||
return wByte
|
return wByte
|
||||||
end
|
end
|
||||||
if s.type == "i8" then
|
if schema_type == "i8" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
ensureSpace(w, 1)
|
ensureSpace(w, 1)
|
||||||
buffer.writei8(w.buf, w.cursor, v)
|
buffer.writei8(w.buf, w.cursor, v)
|
||||||
w.cursor += 1
|
w.cursor += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "u16" then
|
if schema_type == "u16" then
|
||||||
return wU16
|
return wU16
|
||||||
end
|
end
|
||||||
if s.type == "i16" then
|
if schema_type == "i16" then
|
||||||
return wI16
|
return wI16
|
||||||
end
|
end
|
||||||
if s.type == "u32" then
|
if schema_type == "u32" then
|
||||||
return wU32
|
return wU32
|
||||||
end
|
end
|
||||||
if s.type == "i32" then
|
if schema_type == "i32" then
|
||||||
return wI32
|
return wI32
|
||||||
end
|
end
|
||||||
if s.type == "f32" then
|
if schema_type == "f32" then
|
||||||
return wF32
|
return wF32
|
||||||
end
|
end
|
||||||
if s.type == "f64" then
|
if schema_type == "f64" then
|
||||||
return wF64
|
return wF64
|
||||||
end
|
end
|
||||||
if s.type == "boolean" then
|
if schema_type == "boolean" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
wByte(w, v and 1 or 0)
|
wByte(w, v and 1 or 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "string" then
|
if schema_type == "string" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
local len = #v
|
local len = #v
|
||||||
wVarUInt(w, len)
|
wVarUInt(w, len)
|
||||||
|
|
@ -1054,21 +1053,21 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "vector3" then
|
if schema_type == "vector3" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
wF32(w, v.X)
|
wF32(w, v.X)
|
||||||
wF32(w, v.Y)
|
wF32(w, v.Y)
|
||||||
wF32(w, v.Z)
|
wF32(w, v.Z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "vector2" then
|
if schema_type == "vector2" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
wF32(w, v.X)
|
wF32(w, v.X)
|
||||||
wF32(w, v.Y)
|
wF32(w, v.Y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "cframe" then
|
if schema_type == "cframe" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
local pos = v.Position
|
local pos = v.Position
|
||||||
local rx, ry, rz = v:ToOrientation()
|
local rx, ry, rz = v:ToOrientation()
|
||||||
|
|
@ -1081,7 +1080,7 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "color3" then
|
if schema_type == "color3" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
wByte(w, math.clamp(math.round(v.R * 255), 0, 255))
|
wByte(w, math.clamp(math.round(v.R * 255), 0, 255))
|
||||||
wByte(w, math.clamp(math.round(v.G * 255), 0, 255))
|
wByte(w, math.clamp(math.round(v.G * 255), 0, 255))
|
||||||
|
|
@ -1089,14 +1088,14 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "instance" then
|
if schema_type == "instance" then
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
table.insert(w.refs, v)
|
table.insert(w.refs, v)
|
||||||
wVarUInt(w, #w.refs)
|
wVarUInt(w, #w.refs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "struct" then
|
if schema_type == "struct" then
|
||||||
local fields = {}
|
local fields = {}
|
||||||
local optionalIndices = {} -- tracks which fields are optional
|
local optionalIndices = {} -- tracks which fields are optional
|
||||||
|
|
||||||
|
|
@ -1171,7 +1170,7 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "array" then
|
if schema_type == "array" then
|
||||||
local itemSchema = s.item
|
local itemSchema = s.item
|
||||||
|
|
||||||
-- bitpacking hacks
|
-- bitpacking hacks
|
||||||
|
|
@ -1217,7 +1216,7 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "map" then
|
if schema_type == "map" then
|
||||||
local keyPacker = compilePacker(s.key)
|
local keyPacker = compilePacker(s.key)
|
||||||
local valPacker = compilePacker(s.value)
|
local valPacker = compilePacker(s.value)
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
|
|
@ -1233,7 +1232,7 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "optional" then
|
if schema_type == "optional" then
|
||||||
local itemPacker = compilePacker(s.item)
|
local itemPacker = compilePacker(s.item)
|
||||||
return function(w, v)
|
return function(w, v)
|
||||||
if v == nil then
|
if v == nil then
|
||||||
|
|
@ -1249,59 +1248,60 @@ local function compilePacker(s: SchemaType): (Writer, any) -> ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any, number)
|
local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any, number)
|
||||||
if s.type == "u8" then
|
local schema_type = s.type
|
||||||
|
if schema_type == "u8" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readu8(b, c), c + 1
|
return buffer.readu8(b, c), c + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "i8" then
|
if schema_type == "i8" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readi8(b, c), c + 1
|
return buffer.readi8(b, c), c + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "u16" then
|
if schema_type == "u16" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readu16(b, c), c + 2
|
return buffer.readu16(b, c), c + 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "i16" then
|
if schema_type == "i16" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readi16(b, c), c + 2
|
return buffer.readi16(b, c), c + 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "u32" then
|
if schema_type == "u32" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readu32(b, c), c + 4
|
return buffer.readu32(b, c), c + 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "i32" then
|
if schema_type == "i32" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readi32(b, c), c + 4
|
return buffer.readi32(b, c), c + 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "f32" then
|
if schema_type == "f32" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readf32(b, c), c + 4
|
return buffer.readf32(b, c), c + 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "f64" then
|
if schema_type == "f64" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readf64(b, c), c + 8
|
return buffer.readf64(b, c), c + 8
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "boolean" then
|
if schema_type == "boolean" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
return buffer.readu8(b, c) ~= 0, c + 1
|
return buffer.readu8(b, c) ~= 0, c + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "string" then
|
if schema_type == "string" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
local len
|
local len
|
||||||
len, c = readVarUInt(b, c)
|
len, c = readVarUInt(b, c)
|
||||||
return buffer.readstring(b, c, len), c + len
|
return buffer.readstring(b, c, len), c + len
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "vector3" then
|
if schema_type == "vector3" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
local x = buffer.readf32(b, c)
|
local x = buffer.readf32(b, c)
|
||||||
local y = buffer.readf32(b, c + 4)
|
local y = buffer.readf32(b, c + 4)
|
||||||
|
|
@ -1310,7 +1310,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "vector2" then
|
if schema_type == "vector2" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
local x = buffer.readf32(b, c)
|
local x = buffer.readf32(b, c)
|
||||||
local y = buffer.readf32(b, c + 4)
|
local y = buffer.readf32(b, c + 4)
|
||||||
|
|
@ -1318,7 +1318,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "color3" then
|
if schema_type == "color3" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
local r = buffer.readu8(b, c)
|
local r = buffer.readu8(b, c)
|
||||||
local g = buffer.readu8(b, c + 1)
|
local g = buffer.readu8(b, c + 1)
|
||||||
|
|
@ -1327,7 +1327,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "cframe" then
|
if schema_type == "cframe" then
|
||||||
return function(b, c)
|
return function(b, c)
|
||||||
local px = buffer.readf32(b, c)
|
local px = buffer.readf32(b, c)
|
||||||
local py = buffer.readf32(b, c + 4)
|
local py = buffer.readf32(b, c + 4)
|
||||||
|
|
@ -1338,7 +1338,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
return CFrame.new(px, py, pz) * CFrame.fromOrientation(rx, ry, rz), c + 24
|
return CFrame.new(px, py, pz) * CFrame.fromOrientation(rx, ry, rz), c + 24
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if s.type == "instance" then
|
if schema_type == "instance" then
|
||||||
return function(b, c, refs)
|
return function(b, c, refs)
|
||||||
local idx
|
local idx
|
||||||
idx, c = readVarUInt(b, c)
|
idx, c = readVarUInt(b, c)
|
||||||
|
|
@ -1346,7 +1346,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "struct" then
|
if schema_type == "struct" then
|
||||||
local fields = {}
|
local fields = {}
|
||||||
local optionalIndices = {}
|
local optionalIndices = {}
|
||||||
|
|
||||||
|
|
@ -1409,7 +1409,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "array" then
|
if schema_type == "array" then
|
||||||
local itemSchema = s.item
|
local itemSchema = s.item
|
||||||
|
|
||||||
-- bitpacking hacks
|
-- bitpacking hacks
|
||||||
|
|
@ -1447,7 +1447,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "map" then
|
if schema_type == "map" then
|
||||||
local keyReader = compileReader(s.key)
|
local keyReader = compileReader(s.key)
|
||||||
local valReader = compileReader(s.value)
|
local valReader = compileReader(s.value)
|
||||||
return function(b, c, refs)
|
return function(b, c, refs)
|
||||||
|
|
@ -1464,7 +1464,7 @@ local function compileReader(s: SchemaType): (buffer, number, { any }?) -> (any,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if s.type == "optional" then
|
if schema_type == "optional" then
|
||||||
local itemReader = compileReader(s.item)
|
local itemReader = compileReader(s.item)
|
||||||
return function(b, c, refs)
|
return function(b, c, refs)
|
||||||
local exists = buffer.readu8(b, c) ~= 0
|
local exists = buffer.readu8(b, c) ~= 0
|
||||||
|
|
@ -1578,10 +1578,6 @@ BufferSerdes.build = build
|
||||||
BufferSerdes.buildWithRefs = buildWithRefs
|
BufferSerdes.buildWithRefs = buildWithRefs
|
||||||
BufferSerdes.reset = reset
|
BufferSerdes.reset = reset
|
||||||
|
|
||||||
BufferSerdes.varUIntSize = varUIntSize
|
|
||||||
BufferSerdes.writeVarUInt = writeVarUInt
|
|
||||||
BufferSerdes.readVarUInt = readVarUInt
|
|
||||||
|
|
||||||
BufferSerdes.readTagged = unpackValue
|
BufferSerdes.readTagged = unpackValue
|
||||||
BufferSerdes.packTagged = packValue
|
BufferSerdes.packTagged = packValue
|
||||||
BufferSerdes.unpack = unpackValue
|
BufferSerdes.unpack = unpackValue
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue