@@ -224,13 +224,19 @@ int pk_decode (char *buffer, size_t blen, int count, size_t *seek, int skip_deco
224224 // skip_decode wants the raw encoded slice (type_byte + optional len/int + payload)
225225 // we still must parse with the *raw* type to know how much to skip
226226 bool skip_decode = ((skip_decode_idx >= 0 ) && (i == (size_t )skip_decode_idx ));
227+ size_t initial_bseek = bseek - 1 ; // points to type_byte
227228
228229 switch (raw_type ) {
229230 case DATABASE_TYPE_MAX_NEGATIVE_INTEGER : {
230231 // must not carry length bits
231232 if (nbytes != 0 ) return -1 ;
232- int64_t value = INT64_MIN ;
233- if (cb ) if (cb (xdata , (int )i , DBTYPE_INTEGER , value , 0.0 , NULL ) != DBRES_OK ) return -1 ;
233+ if (skip_decode ) {
234+ size_t slice_len = bseek - initial_bseek ;
235+ if (cb ) if (cb (xdata , (int )i , DBTYPE_BLOB , (int64_t )slice_len , 0.0 , (char * )(buffer + initial_bseek )) != DBRES_OK ) return -1 ;
236+ } else {
237+ int64_t value = INT64_MIN ;
238+ if (cb ) if (cb (xdata , (int )i , DBTYPE_INTEGER , value , 0.0 , NULL ) != DBRES_OK ) return -1 ;
239+ }
234240 }
235241 break ;
236242
@@ -240,9 +246,15 @@ int pk_decode (char *buffer, size_t blen, int count, size_t *seek, int skip_deco
240246 if (nbytes < 1 || nbytes > 8 ) return -1 ;
241247 uint64_t u = 0 ;
242248 if (!pk_decode_uint64 (ubuf , blen , & bseek , nbytes , & u )) return -1 ;
243- int64_t value = (int64_t )u ;
244- if (raw_type == DATABASE_TYPE_NEGATIVE_INTEGER ) value = - value ;
245- if (cb ) if (cb (xdata , (int )i , DBTYPE_INTEGER , value , 0.0 , NULL ) != DBRES_OK ) return -1 ;
249+
250+ if (skip_decode ) {
251+ size_t slice_len = bseek - initial_bseek ;
252+ if (cb ) if (cb (xdata , (int )i , DBTYPE_BLOB , (int64_t )slice_len , 0.0 , (char * )(buffer + initial_bseek )) != DBRES_OK ) return -1 ;
253+ } else {
254+ int64_t value = (int64_t )u ;
255+ if (raw_type == DATABASE_TYPE_NEGATIVE_INTEGER ) value = - value ;
256+ if (cb ) if (cb (xdata , (int )i , DBTYPE_INTEGER , value , 0.0 , NULL ) != DBRES_OK ) return -1 ;
257+ }
246258 }
247259 break ;
248260
@@ -252,16 +264,21 @@ int pk_decode (char *buffer, size_t blen, int count, size_t *seek, int skip_deco
252264 if (nbytes != 0 ) return -1 ;
253265 double value = 0.0 ;
254266 if (!pk_decode_double (ubuf , blen , & bseek , & value )) return -1 ;
255- if (raw_type == DATABASE_TYPE_NEGATIVE_FLOAT ) value = - value ;
256- if (cb ) if (cb (xdata , (int )i , DBTYPE_FLOAT , 0 , value , NULL ) != DBRES_OK ) return -1 ;
267+
268+ if (skip_decode ) {
269+ size_t slice_len = bseek - initial_bseek ;
270+ if (cb ) if (cb (xdata , (int )i , DBTYPE_BLOB , (int64_t )slice_len , 0.0 , (char * )(buffer + initial_bseek )) != DBRES_OK ) return -1 ;
271+ } else {
272+ if (raw_type == DATABASE_TYPE_NEGATIVE_FLOAT ) value = - value ;
273+ if (cb ) if (cb (xdata , (int )i , DBTYPE_FLOAT , 0 , value , NULL ) != DBRES_OK ) return -1 ;
274+ }
257275 }
258276 break ;
259277
260278 case DBTYPE_TEXT :
261279 case DBTYPE_BLOB : {
262280 // validate nbytes for length field
263281 if (nbytes < 1 || nbytes > 8 ) return -1 ;
264- size_t initial_bseek = bseek - 1 ; // points to type_byte
265282 uint64_t ulen = 0 ;
266283 if (!pk_decode_uint64 (ubuf , blen , & bseek , nbytes , & ulen )) return -1 ;
267284
@@ -283,7 +300,12 @@ int pk_decode (char *buffer, size_t blen, int count, size_t *seek, int skip_deco
283300
284301 case DBTYPE_NULL : {
285302 if (nbytes != 0 ) return -1 ;
286- if (cb ) if (cb (xdata , (int )i , DBTYPE_NULL , 0 , 0.0 , NULL ) != DBRES_OK ) return -1 ;
303+ if (skip_decode ) {
304+ size_t slice_len = bseek - initial_bseek ;
305+ if (cb ) if (cb (xdata , (int )i , DBTYPE_BLOB , (int64_t )slice_len , 0.0 , (char * )(buffer + initial_bseek )) != DBRES_OK ) return -1 ;
306+ } else {
307+ if (cb ) if (cb (xdata , (int )i , DBTYPE_NULL , 0 , 0.0 , NULL ) != DBRES_OK ) return -1 ;
308+ }
287309 }
288310 break ;
289311
0 commit comments