Skip to content
Snippets Groups Projects
  • Alexander Turenko's avatar
    ab95ddaa
    module api/lua: add luaT_tuple_encode() · ab95ddaa
    Alexander Turenko authored
    It is the same as luaT_tuple_new(), but returns raw MsgPack data (not
    <box_tuple_t>) allocated on the box region.
    
    The reason to expose this function is to provide ability to use
    box_tuple_compare_with_key() function from an external module for a key
    passed as a Lua table. The compare function has the following signature:
    
     | API_EXPORT int
     | box_tuple_compare_with_key(box_tuple_t *tuple_a, const char *key_b,
     |                            box_key_def_t *key_def);
    
    The second parameter is a key encoded as an MsgPack array, not a tuple
    structure. So luaT_tuple_new() is not applicable here (it is not
    worthful to create a tuple structure if we need just MsgPack data).
    
    Some complexity was introduced to support encoding on the Lua shared
    buffer and the box region both. The motivation is the following:
    
    - luaT_tuple_encode() is exposed with encoding to the box region,
      because it is more usual to the module API. In particular a user of
      the API able to control when the tuple data should be released.
    - Encoding to the Lua shared buffer is kept internally, because there is
      no strong reason to change it to the box region for box.tuple.new().
    
    Part of #5273
    module api/lua: add luaT_tuple_encode()
    Alexander Turenko authored
    It is the same as luaT_tuple_new(), but returns raw MsgPack data (not
    <box_tuple_t>) allocated on the box region.
    
    The reason to expose this function is to provide ability to use
    box_tuple_compare_with_key() function from an external module for a key
    passed as a Lua table. The compare function has the following signature:
    
     | API_EXPORT int
     | box_tuple_compare_with_key(box_tuple_t *tuple_a, const char *key_b,
     |                            box_key_def_t *key_def);
    
    The second parameter is a key encoded as an MsgPack array, not a tuple
    structure. So luaT_tuple_new() is not applicable here (it is not
    worthful to create a tuple structure if we need just MsgPack data).
    
    Some complexity was introduced to support encoding on the Lua shared
    buffer and the box region both. The motivation is the following:
    
    - luaT_tuple_encode() is exposed with encoding to the box region,
      because it is more usual to the module API. In particular a user of
      the API able to control when the tuple data should be released.
    - Encoding to the Lua shared buffer is kept internally, because there is
      no strong reason to change it to the box region for box.tuple.new().
    
    Part of #5273