@@ -120,3 +120,64 @@ TEST(streaming, basic)
120120 msgpack_unpacked_destroy (&result);
121121 msgpack_sbuffer_free (buffer);
122122}
123+
124+ TEST (streaming, basic_with_size)
125+ {
126+ int ret;
127+ size_t bytes;
128+ size_t parsed = 0 ;
129+ msgpack_sbuffer* buffer = msgpack_sbuffer_new ();
130+ msgpack_packer* pk = msgpack_packer_new (buffer, msgpack_sbuffer_write);
131+ msgpack_unpacked result;
132+ msgpack_unpacker *unp;
133+
134+ // 1, 2, 3, "str", ["str_data"], "bin", ["bin_data"], {0.3: 0.4}
135+ msgpack_pack_int (pk, 1 );
136+ msgpack_pack_int (pk, 2 );
137+ msgpack_pack_int (pk, 3 );
138+ msgpack_pack_str (pk, 3 );
139+ msgpack_pack_str_body (pk, " str" , 3 );
140+ msgpack_pack_array (pk, 1 );
141+ msgpack_pack_str (pk, 8 );
142+ msgpack_pack_str_body (pk, " str_data" , 8 );
143+ msgpack_pack_bin (pk, 3 );
144+ msgpack_pack_bin_body (pk, " bin" , 3 );
145+ msgpack_pack_array (pk, 1 );
146+ msgpack_pack_bin (pk, 8 );
147+ msgpack_pack_bin_body (pk, " bin_data" , 8 );
148+ msgpack_pack_map (pk, 1 );
149+ msgpack_pack_float (pk, 0 .4f );
150+ msgpack_pack_double (pk, 0.8 );
151+ msgpack_packer_free (pk);
152+
153+ unp = msgpack_unpacker_new (32 * 1024 );
154+ msgpack_unpacked_init (&result);
155+
156+ const char * input = buffer->data ;
157+
158+ while (parsed < buffer->size ) {
159+ memcpy (msgpack_unpacker_buffer (unp), input, 1 );
160+ msgpack_unpacker_buffer_consumed (unp, 1 );
161+ input += 1 ;
162+
163+ bytes = 0 ;
164+ ret = msgpack_unpacker_next_with_size (unp, &result, &bytes);
165+ if (ret == MSGPACK_UNPACK_CONTINUE) {
166+ EXPECT_GT (bytes, 0 );
167+ continue ;
168+ }
169+
170+ while (ret == MSGPACK_UNPACK_SUCCESS) {
171+ EXPECT_GT (bytes, 0 );
172+ parsed += bytes;
173+ ret = msgpack_unpacker_next_with_size (unp, &result, &bytes);
174+ }
175+
176+ }
177+
178+ EXPECT_EQ (parsed, buffer->size );
179+
180+ msgpack_unpacked_destroy (&result);
181+ msgpack_unpacker_free (unp);
182+ msgpack_sbuffer_free (buffer);
183+ }
0 commit comments