Skip to content
Snippets Groups Projects
Commit de90e54b authored by Nikita Pettik's avatar Nikita Pettik Committed by Aleksandr Lyapunov
Browse files

lua/prbuf: introduce entry:data() method

prbuf entry contains pointer to raw memory (char *) and its length.
Let's introduce :data() methods which would convert this memory chunk
to Lua string.

NO_DOC=<Feature for internal usage>
NO_CHANGELOG=<Feature for internal usage>
parent 6e7fa12a
No related branches found
No related tags found
No related merge requests found
......@@ -290,6 +290,13 @@ local function prbuf_iterator_next(iterator)
return entry
end
local function prbuf_entry_data(entry)
if not ffi.istype(prbuf_entry_t, entry) then
errorf('Attempt to entry:data() without object, use entry:data()')
end
return ffi.string(entry.ptr, tonumber(entry.size))
end
local prbuf_iterator_methods = {
next = prbuf_iterator_next;
}
......@@ -300,6 +307,16 @@ local prbuf_iterator_mt = {
ffi.metatype(prbuf_iterator_t, prbuf_iterator_mt);
local prbuf_entry_methods = {
data = prbuf_entry_data;
}
local prbuf_entry_mt = {
__index = prbuf_entry_methods;
}
ffi.metatype(prbuf_entry_t, prbuf_entry_mt);
local function prbuf_tostring(self)
return '<prbuf>'
end
......
......@@ -37,6 +37,9 @@ g.test_object_misc = function()
while entry ~= nil do
entry_count = entry_count + 1
t.assert_equals(entry.size, sample_size)
local data = entry:data()
t.assert_equals(string.len(data), entry.size)
t.assert_equals(data, require('ffi').string(entry.ptr, entry.size))
t.assert_equals(check_memory(entry.ptr, tonumber(entry.size)), true)
entry = iter:next()
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment