Skip to content

Document msgpack object iterator take_array method #2749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TarantoolBot opened this issue Mar 14, 2022 · 0 comments · Fixed by #3605
Closed

Document msgpack object iterator take_array method #2749

TarantoolBot opened this issue Mar 14, 2022 · 0 comments · Fixed by #3605
Assignees
Labels
2.10 feature A new functionality msgpack reference [location] Tarantool manual, Reference part

Comments

@TarantoolBot
Copy link
Collaborator

TarantoolBot commented Mar 14, 2022

Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/msgpack/#msgpack-object-methods

The new method copies the given number of msgpack values starting from
the iterator cursor position to a new msgpack array object. On success
it returns the new msgpack object and advances the iterator cursor. If
there isn't enough values to decode, it raises a Lua error and leaves
the iterator cursor unchanged.

This function could be implemented in Lua like this:

function take_array(iter, count)
    local array = {}
    for _ = 1, count do
        table.insert(array, iter:take())
    end
    return msgpack.object(array)
end

Usage example:

local mp = msgpack.object({10, 20, 30, 40})
local it = mp:iterator()
it:decode_array_header()       -- returns 4
it:decode()                    -- returns 10
local mp2 = it:take_array(2)
mp2:decode()                   -- returns {20, 30}
it:decode()                    -- returns 40

Requested by @locker in tarantool/tarantool@68bf388.

@art-dr art-dr added reference [location] Tarantool manual, Reference part server [area] Task relates to Tarantool's server (core) functionality feature A new functionality labels Mar 14, 2022
@veod32 veod32 added this to the Estimate [@veod32] milestone Jul 14, 2022
@veod32 veod32 added msgpack and removed server [area] Task relates to Tarantool's server (core) functionality labels Mar 1, 2023
@veod32 veod32 removed this from the Estimate [@veod32] milestone Mar 1, 2023
@veod32 veod32 added the 2.10 label Mar 6, 2023
@andreyaksenov andreyaksenov self-assigned this Aug 3, 2023
@andreyaksenov andreyaksenov linked a pull request Aug 7, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.10 feature A new functionality msgpack reference [location] Tarantool manual, Reference part
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants