Hello, I have encountered a problem with my code.
Basically I made a buffer module and various sub-modules for buffer serialization of different DataTypes.
But I got a problem with this one DataType: string.
Here’s my code:
return {
write = function(buf, value: string)
local typ, size, met = getmetatable(buf).checkType(buf, #value)
if not met then return end
local _met = getmetatable(buf).readTransformedNumberIntoBufferStringMethod(buf, met)
print(#value)
getmetatable(buf).w8u(buf, met) --method (number)
getmetatable(buf).w8u(buf, getmetatable(buf).getAllocationNumberFromBufferMethod(buf, getmetatable(buf).swap(buf, _met))) --alloc
getmetatable(buf)[getmetatable(buf).swap(buf ,_met)](buf, #value) --characters
getmetatable(buf).wstring(buf, value) --actual string
end,
read = function(buf, cursor: number)
local met = getmetatable(buf).readTransformedNumberIntoBufferStringMethod(buf, getmetatable(buf).r8u(buf, cursor))
print(met, getmetatable(buf).r8u(buf, cursor), buf, getmetatable(buf))
local allocChars = getmetatable(buf).r8u(buf, cursor + 1)
local characters = getmetatable(buf)[met](buf, cursor + 1 + allocChars)
return getmetatable(buf).rstring(buf, cursor + 1 + allocChars, characters)
end,
}
Basically if I imput any string, for example: “hello world”, it returns: " hello worl".
It deleates the last letter of the string and adds a space at the start instead.
Any help would be appreaciated!