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
Extend msgpack Lua API #2755
Comments
Proposed API extension:
|
- Do not throw an exception from msgpack.decode() if the supplied data cannot be parsed (mp_check() fails). Return {nil, nil, error} instead: obj, offset, err = msgpack.decode(data) if obj == nil then print(err) return end - Allow to pass a C buffer to msgpack.decode(). Syntax: buf = buffer.ibuf() ... obj, rpos, err = msgpack.decode(buf.rpos, buf:size()) - Introduce a version of msgpack.decode() that doesn't check the supplied msgpack - msgpack.decode_unchecked(). It has the same signature as msgpack.decode() except if called on a C buffer it doesn't require the buffer size. It is supposed to supplant msgpack.ibuf_decode() over time. - Introduce msgpack.ibuf_encode(buf, obj). It encodes a Lua object to an input buffer and returns the number of bytes encoded. - Add tests. See #2755
In order to use fio in conjunction with ibuf, we need to extend read(), pread(), write(), pwrite() so that they can take a C buffer instead of a Lua string. The syntax is as follows: read(size) -> str read(buf, size) -> len pread(size, offset) -> str pread(buf, size, offset) -> len write(str) write(buf, size) pwrite(str, offset) pwrite(buf, size, offset) See #2755
In order to use fio in conjunction with ibuf, we need to extend read(), pread(), write(), pwrite() so that they can take a C buffer instead of a Lua string. The syntax is as follows: read(size) -> str read(buf, size) -> len pread(size, offset) -> str pread(buf, size, offset) -> len write(str) write(buf, size) pwrite(str, offset) pwrite(buf, size, offset) See #2755
- Allow to pass a C buffer to msgpack.decode(). Syntax: buf = buffer.ibuf() ... obj, rpos = msgpack.decode(buf.rpos, buf:size()) - Introduce a version of msgpack.decode() that doesn't check the supplied msgpack - msgpack.decode_unchecked(). It has the same signature as msgpack.decode() except if called on a C buffer it doesn't require the buffer size. It is supposed to supplant msgpack.ibuf_decode() over time. - Allow to store encoded objects in a user-supplied ibuf. Syntax: buf = buffer.ibuf() len = msgpack.encode(obj, buf) ('len' is the number of bytes stored in the buffer) - Add tests. Closes #2755
- Allow to pass a C buffer to msgpack.decode(). Syntax: buf = buffer.ibuf() ... obj, rpos = msgpack.decode(buf.rpos, buf:size()) - Introduce a version of msgpack.decode() that doesn't check the supplied msgpack - msgpack.decode_unchecked(). It has the same signature as msgpack.decode() except if called on a C buffer it doesn't require the buffer size. It is supposed to supplant msgpack.ibuf_decode() over time. - Allow to store encoded objects in a user-supplied ibuf. Syntax: buf = buffer.ibuf() len = msgpack.encode(obj, buf) ('len' is the number of bytes stored in the buffer) - Add tests. Closes #2755
- Allow to pass a C buffer to msgpack.decode(). Syntax: buf = buffer.ibuf() ... obj, rpos = msgpack.decode(buf.rpos, buf:size()) - Introduce a version of msgpack.decode() that doesn't check the supplied msgpack - msgpack.decode_unchecked(). It has the same signature as msgpack.decode() except if called on a C buffer it doesn't require the buffer size. It is supposed to supplant msgpack.ibuf_decode() over time. - Allow to store encoded objects in a user-supplied ibuf. Syntax: buf = buffer.ibuf() len = msgpack.encode(obj, buf) ('len' is the number of bytes stored in the buffer) - Add tests. Closes #2755
fio => #2960 |
Rewritten the test case. There are several reasons to do so. First, the previous test case implementation uses test:iscdata() which is not sufficient to verify whether the const qualifier is applied to a cdata type, because of using ffi.istype() under hood, which ignores 'const'. Second, the previous test case was invalid, because of wrong order of ffi.cast() arguments. Third, we don't need a real ibuf object, ffi.cast(ctype, 'a string') is enough. This allows to simplify test cases. Fourth, the test case is rewritten in a declarative manner to reduce code duplication. This also allows to expand it w/o many changes for msgpack.decode() function in the following commit. I left only msgpackffi.decode_unchecked() cases. A bit context is needed to describe why. msgpack.decode() accepts two arguments: a buffer and its size (or a string and an offset, but it is out of scope here). msgpack.decode_unchecked() accepts only a buffer (or, again, a string and an offset) and does not verify whether we perform reads out of the buffer bounds. See #2755 for the formal description of the API. msgpackffi module contains only msgpackffi.decode_unchecked(). msgpackffi.decode() is just alias for decode_unchecked: it does not verify a buffer bounds. AFAIU the alias was added to unify testing code for msgpack and msgpackffi modules. Our website has no documentation about msgpackffi. I don't sure whether its API should be considered as public API. However if we'll make the module public, we'll need to implement buffer bound check. And only then state that the API is stable and can be used by users. If we don't consider msgpackffi.decode() as public function for now, it make sense to left it untested when a testing code is not unified between msgpack and msgpackffi modules. However I unified this testing code for both modules in the following commit, so it will be tested anyway: but in the commit where it looks reasonable.
Function decode of module msgpackffi was passing value of type const unsigned char * to a C function that accepts arguments of type const char *. Closes #3926 FIXUP: msgpackffi.decode can now be assigned to buf.rpos Added a note that ffi.istype() ignores the const qualifier and changed the code to make it more clear. Saved an argument cdata type to a local variable to make the logic 'return a pointer of the same type as passed one' more clear. No behaviour changes. FIXUP: msgpackffi.decode can now be assigned to buf.rpos Rewritten the test case. There are several reasons to do so. First, the previous test case implementation uses test:iscdata() which is not sufficient to verify whether the const qualifier is applied to a cdata type, because of using ffi.istype() under hood, which ignores 'const'. Second, the previous test case was invalid, because of wrong order of ffi.cast() arguments. Third, we don't need a real ibuf object, ffi.cast(ctype, 'a string') is enough. This allows to simplify test cases. Fourth, the test case is rewritten in a declarative manner to reduce code duplication. This also allows to expand it w/o many changes for msgpack.decode() function in the following commit. I left only msgpackffi.decode_unchecked() cases. A bit context is needed to describe why. msgpack.decode() accepts two arguments: a buffer and its size (or a string and an offset, but it is out of scope here). msgpack.decode_unchecked() accepts only a buffer (or, again, a string and an offset) and does not verify whether we perform reads out of the buffer bounds. See #2755 for the formal description of the API. msgpackffi module contains only msgpackffi.decode_unchecked(). msgpackffi.decode() is just alias for decode_unchecked: it does not verify a buffer bounds. AFAIU the alias was added to unify testing code for msgpack and msgpackffi modules. Our website has no documentation about msgpackffi. I don't sure whether its API should be considered as public API. However if we'll make the module public, we'll need to implement buffer bound check. And only then state that the API is stable and can be used by users. If we don't consider msgpackffi.decode() as public function for now, it make sense to left it untested when a testing code is not unified between msgpack and msgpackffi modules. However I unified this testing code for both modules in the following commit, so it will be tested anyway: but in the commit where it looks reasonable.
Function decode of module msgpackffi was passing value of type const unsigned char * to a C function that accepts arguments of type const char *. Closes #3926 FIXUPs from Totktonada/gh-3926-msgpack-decode-retval-ctype branch FIXUP: msgpackffi.decode can now be assigned to buf.rpos Added a note that ffi.istype() ignores the const qualifier and changed the code to make it more clear. Saved an argument cdata type to a local variable to make the logic 'return a pointer of the same type as passed one' more clear. No behaviour changes. FIXUP: msgpackffi.decode can now be assigned to buf.rpos Rewritten the test case. There are several reasons to do so. First, the previous test case implementation uses test:iscdata() which is not sufficient to verify whether the const qualifier is applied to a cdata type, because of using ffi.istype() under hood, which ignores 'const'. Second, the previous test case was invalid, because of wrong order of ffi.cast() arguments. Third, we don't need a real ibuf object, ffi.cast(ctype, 'a string') is enough. This allows to simplify test cases. Fourth, the test case is rewritten in a declarative manner to reduce code duplication. This also allows to expand it w/o many changes for msgpack.decode() function in the following commit. I left only msgpackffi.decode_unchecked() cases. A bit context is needed to describe why. msgpack.decode() accepts two arguments: a buffer and its size (or a string and an offset, but it is out of scope here). msgpack.decode_unchecked() accepts only a buffer (or, again, a string and an offset) and does not verify whether we perform reads out of the buffer bounds. See #2755 for the formal description of the API. msgpackffi module contains only msgpackffi.decode_unchecked(). msgpackffi.decode() is just alias for decode_unchecked: it does not verify a buffer bounds. AFAIU the alias was added to unify testing code for msgpack and msgpackffi modules. Our website has no documentation about msgpackffi. I don't sure whether its API should be considered as public API. However if we'll make the module public, we'll need to implement buffer bound check. And only then state that the API is stable and can be used by users. If we don't consider msgpackffi.decode() as public function for now, it make sense to left it untested when a testing code is not unified between msgpack and msgpackffi modules. However I unified this testing code for both modules in the following commit, so it will be tested anyway: but in the commit where it looks reasonable.
Function decode of module msgpackffi was passing value of type const unsigned char * to a C function that accepts arguments of type const char *. Closes #3926 FIXUPs from Totktonada/gh-3926-msgpack-decode-retval-ctype branch FIXUP: msgpackffi.decode can now be assigned to buf.rpos Added a note that ffi.istype() ignores the const qualifier and changed the code to make it more clear. Saved an argument cdata type to a local variable to make the logic 'return a pointer of the same type as passed one' more clear. No behaviour changes. FIXUP: msgpackffi.decode can now be assigned to buf.rpos Rewritten the test case. There are several reasons to do so. First, the previous test case implementation uses test:iscdata() which is not sufficient to verify whether the const qualifier is applied to a cdata type, because of using ffi.istype() under hood, which ignores 'const'. Second, the previous test case was invalid, because of wrong order of ffi.cast() arguments. Third, we don't need a real ibuf object, ffi.cast(ctype, 'a string') is enough. This allows to simplify test cases. Fourth, the test case is rewritten in a declarative manner to reduce code duplication. This also allows to expand it w/o many changes for msgpack.decode() function in the following commit. I left only msgpackffi.decode_unchecked() cases. A bit context is needed to describe why. msgpack.decode() accepts two arguments: a buffer and its size (or a string and an offset, but it is out of scope here). msgpack.decode_unchecked() accepts only a buffer (or, again, a string and an offset) and does not verify whether we perform reads out of the buffer bounds. See #2755 for the formal description of the API. msgpackffi module contains only msgpackffi.decode_unchecked(). msgpackffi.decode() is just alias for decode_unchecked: it does not verify a buffer bounds. AFAIU the alias was added to unify testing code for msgpack and msgpackffi modules. Our website has no documentation about msgpackffi. I don't sure whether its API should be considered as public API. However if we'll make the module public, we'll need to implement buffer bound check. And only then state that the API is stable and can be used by users. If we don't consider msgpackffi.decode() as public function for now, it make sense to left it untested when a testing code is not unified between msgpack and msgpackffi modules. However I unified this testing code for both modules in the following commit, so it will be tested anyway: but in the commit where it looks reasonable.
http://github.com/tarantool/dump currently can not perform piece-by-piece restore of a dump because there is no way to parse a partial msgpuck chunk with the built-in msgpuck.
Please extend the built-in msgpuck to not throw exceptions on error/partial parse. After that it will be bossible to improve http://github.com/tarantool/dump.
On the same token it would be nice to finish msgpackffi and make sure it has the same API as msgpuck.
Thanks.
The text was updated successfully, but these errors were encountered: