Skip to content

Commit e90ba30

Browse files
committed
Support str 8
1 parent 88ad86d commit e90ba30

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lua_cmsgpack.c

+13
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ void mp_encode_bytes(mp_buf *buf, const unsigned char *s, size_t len) {
180180
if (len < 32) {
181181
hdr[0] = 0xa0 | (len&0xff); /* fix raw */
182182
hdrlen = 1;
183+
} else if (len <= 0xff) {
184+
hdr[0] = 0xd9;
185+
hdr[1] = len;
186+
hdrlen = 2;
183187
} else if (len <= 0xffff) {
184188
hdr[0] = 0xda;
185189
hdr[1] = (len&0xff00)>>8;
@@ -687,6 +691,15 @@ void mp_decode_to_lua_type(lua_State *L, mp_cur *c) {
687691
mp_cur_consume(c,9);
688692
}
689693
break;
694+
case 0xd9: /* raw 8 */
695+
mp_cur_need(c,2);
696+
{
697+
size_t l = c->p[1];
698+
mp_cur_need(c,2+l);
699+
lua_pushlstring(L,(char*)c->p+2,l);
700+
mp_cur_consume(c,2+l);
701+
}
702+
break;
690703
case 0xda: /* raw 16 */
691704
mp_cur_need(c,3);
692705
{

test.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ test_pack_and_unpack("int8",-64,"d0c0")
378378
test_pack_and_unpack("int16",-1024,"d1fc00")
379379
test_pack_and_unpack("int32",-1048576,"d2fff00000")
380380
test_pack_and_unpack("int64",-1099511627776,"d3ffffff0000000000")
381-
test_pack_and_unpack("raw16"," ","da002820202020202020202020202020202020202020202020202020202020202020202020202020202020")
381+
test_pack_and_unpack("raw8"," ","d921202020202020202020202020202020202020202020202020202020202020202020")
382+
test_pack_and_unpack("raw16"," ","da01012020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020")
382383
test_pack_and_unpack("array 16",{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},"dc001000000000000000000000000000000000")
383384

384385
-- Regression test for issue #4, cyclic references in tables.

0 commit comments

Comments
 (0)