Skip to content

Commit 81a3165

Browse files
committed
Merge pull request #46 from darvik80/phpt_str8
This is phpt for str8 from ticket #40
2 parents 50e9590 + cd3b044 commit 81a3165

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

msgpack/pack_template.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
730730
if(l < 32) {
731731
unsigned char d = 0xa0 | l;
732732
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
733+
} else if (l < 256) {
734+
unsigned char buf[2];
735+
buf[0] = 0xd9; buf[1] = (uint8_t)l;
736+
msgpack_pack_append_buffer(x, buf, 2);
733737
} else if(l < 65536) {
734738
unsigned char buf[3];
735739
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);

msgpack/unpack_define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef enum {
6565
//CS_BIG_INT_32 = 0x17,
6666
//CS_BIG_FLOAT_16 = 0x18,
6767
//CS_BIG_FLOAT_32 = 0x19,
68+
CS_RAW_8 = 0x19,
6869
CS_RAW_16 = 0x1a,
6970
CS_RAW_32 = 0x1b,
7071
CS_ARRAY_16 = 0x1c,

msgpack/unpack_template.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
227227
//case 0xd7: // big integer 32
228228
//case 0xd8: // big float 16
229229
//case 0xd9: // big float 32
230+
case 0xd9:
231+
trail = *(++p);
232+
p++;
233+
n = p; p += trail - 1;
234+
cs = CS_RAW_8;
235+
goto _raw_zero;
230236
case 0xda: // raw 16
231237
case 0xdb: // raw 32
232238
case 0xdc: // array 16

tests/137.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
unpack/pack str8
3+
--SKIPIF--
4+
<?php
5+
if (version_compare(PHP_VERSION, '5.2.0') < 0) {
6+
echo "skip tests in PHP 5.2 or newer";
7+
}
8+
--FILE--
9+
<?php
10+
function test() {
11+
if(!extension_loaded('msgpack'))
12+
{
13+
dl('msgpack.' . PHP_SHLIB_SUFFIX);
14+
}
15+
16+
$str = "Simple test for short string - type str8";
17+
$str8 = chr(0xD9) . chr(strlen($str)) . $str;
18+
echo msgpack_unpack($str8) . "\n";
19+
$data = msgpack_pack($str);
20+
echo ($data[0] == chr(0xD9) && $data[1] == chr(strlen($str)) ? "OK" : "FAILED"), PHP_EOL;
21+
}
22+
23+
test();
24+
?>
25+
--EXPECTF--
26+
Simple test for short string - type str8
27+
OK

0 commit comments

Comments
 (0)