@@ -319,6 +319,75 @@ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdCompressCtx_loadCDict0
319
319
return result ;
320
320
}
321
321
322
+ /*
323
+ * Class: com_github_luben_zstd_ZstdCompressCtx
324
+ * Method: reset0
325
+ * Signature: (L)J
326
+ */
327
+ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdCompressCtx_reset0
328
+ (JNIEnv * env , jclass jctx ) {
329
+ ZSTD_CCtx * cctx = (ZSTD_CCtx * )(intptr_t )(* env )-> GetLongField (env , jctx , compress_ctx_nativePtr );
330
+ return ZSTD_CCtx_reset (cctx , ZSTD_reset_session_and_parameters );
331
+ }
332
+
333
+ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdCompressCtx_setPledgedSrcSize0
334
+ (JNIEnv * env , jclass jctx , jlong src_size ) {
335
+ if (src_size < 0 ) {
336
+ return ZSTD_error_srcSize_wrong ;
337
+ }
338
+ ZSTD_CCtx * cctx = (ZSTD_CCtx * )(intptr_t )(* env )-> GetLongField (env , jctx , compress_ctx_nativePtr );
339
+ return ZSTD_CCtx_setPledgedSrcSize (cctx , (unsigned long long )src_size );
340
+ }
341
+
342
+ static size_t compress_direct_buffer_stream
343
+ (JNIEnv * env , jclass jctx , jobject dst , jint * dst_offset , jint dst_size , jobject src , jint * src_offset , jint src_size , jint end_op ) {
344
+ if (NULL == dst ) return ZSTD_ERROR (dstSize_tooSmall );
345
+ if (NULL == src ) return ZSTD_ERROR (srcSize_wrong );
346
+ if (0 > * dst_offset ) return ZSTD_ERROR (dstSize_tooSmall );
347
+ if (0 > * src_offset ) return ZSTD_ERROR (srcSize_wrong );
348
+ if (0 > src_size ) return ZSTD_ERROR (srcSize_wrong );
349
+
350
+ jsize dst_cap = (* env )-> GetDirectBufferCapacity (env , dst );
351
+ if (dst_size > dst_cap ) return ZSTD_ERROR (dstSize_tooSmall );
352
+ jsize src_cap = (* env )-> GetDirectBufferCapacity (env , src );
353
+ if (src_size > src_cap ) return ZSTD_ERROR (srcSize_wrong );
354
+ ZSTD_CCtx * cctx = (ZSTD_CCtx * )(intptr_t )(* env )-> GetLongField (env , jctx , compress_ctx_nativePtr );
355
+
356
+ ZSTD_outBuffer out ;
357
+ out .pos = * dst_offset ;
358
+ out .size = dst_size ;
359
+ out .dst = (* env )-> GetDirectBufferAddress (env , dst );
360
+ if (out .dst == NULL ) return ZSTD_ERROR (memory_allocation );
361
+ ZSTD_inBuffer in ;
362
+ in .pos = * src_offset ;
363
+ in .size = src_size ;
364
+ in .src = (* env )-> GetDirectBufferAddress (env , src );
365
+ if (in .src == NULL ) return ZSTD_ERROR (memory_allocation );
366
+
367
+ size_t result = ZSTD_compressStream2 (cctx , & out , & in , end_op );
368
+ * dst_offset = out .pos ;
369
+ * src_offset = in .pos ;
370
+ return result ;
371
+ }
372
+
373
+ /*
374
+ * Class: com_github_luben_zstd_ZstdCompressCtx
375
+ * Method: compressDirectByteBufferStream0
376
+ * Signature: (Ljava/nio/ByteBuffer;IILjava/nio/ByteBuffer;III)J
377
+ */
378
+ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdCompressCtx_compressDirectByteBufferStream0
379
+ (JNIEnv * env , jclass jctx , jobject dst , jint dst_offset , jint dst_size , jobject src , jint src_offset , jint src_size , jint end_op ) {
380
+ size_t result = compress_direct_buffer_stream (env , jctx , dst , & dst_offset , dst_size , src , & src_offset , src_size , end_op );
381
+ if (ZSTD_isError (result )) {
382
+ return (1ULL << 31 ) | ZSTD_getErrorCode (result );
383
+ }
384
+ jlong encoded_result = ((jlong )dst_offset << 32 ) | src_offset ;
385
+ if (result == 0 ) {
386
+ encoded_result |= 1ULL << 63 ;
387
+ }
388
+ return encoded_result ;
389
+ }
390
+
322
391
/*
323
392
* Class: com_github_luben_zstd_ZstdCompressCtx
324
393
* Method: compressDirectByteBuffer0
@@ -450,10 +519,74 @@ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdDecompressCtx_loadDDict0
450
519
return result ;
451
520
}
452
521
522
+ /*
523
+ * Class: com_github_luben_zstd_ZstdDecompressCtx
524
+ * Method: reset0
525
+ * Signature: (L)J
526
+ */
527
+ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdDecompressCtx_reset0
528
+ (JNIEnv * env , jclass jctx ) {
529
+ ZSTD_DCtx * dctx = (ZSTD_DCtx * )(intptr_t )(* env )-> GetLongField (env , jctx , compress_ctx_nativePtr );
530
+ return ZSTD_DCtx_reset (dctx , ZSTD_reset_session_and_parameters );
531
+ }
532
+
533
+ static size_t decompress_direct_buffer_stream
534
+ (JNIEnv * env , jclass jctx , jobject dst , jint * dst_offset , jint dst_size , jobject src , jint * src_offset , jint src_size )
535
+ {
536
+ if (NULL == dst ) return ZSTD_ERROR (dstSize_tooSmall );
537
+ if (NULL == src ) return ZSTD_ERROR (srcSize_wrong );
538
+ if (0 > * dst_offset ) return ZSTD_ERROR (dstSize_tooSmall );
539
+ if (0 > * src_offset ) return ZSTD_ERROR (srcSize_wrong );
540
+ if (0 > dst_size ) return ZSTD_ERROR (dstSize_tooSmall );
541
+ if (0 > src_size ) return ZSTD_ERROR (srcSize_wrong );
542
+
543
+ jsize dst_cap = (* env )-> GetDirectBufferCapacity (env , dst );
544
+ if (dst_size > dst_cap ) return ZSTD_ERROR (dstSize_tooSmall );
545
+ jsize src_cap = (* env )-> GetDirectBufferCapacity (env , src );
546
+ if (src_size > src_cap ) return ZSTD_ERROR (srcSize_wrong );
547
+
548
+ ZSTD_DCtx * dctx = (ZSTD_DCtx * )(intptr_t )(* env )-> GetLongField (env , jctx , decompress_ctx_nativePtr );
549
+
550
+ ZSTD_outBuffer out ;
551
+ out .pos = * dst_offset ;
552
+ out .size = dst_size ;
553
+ out .dst = (* env )-> GetDirectBufferAddress (env , dst );
554
+ if (out .dst == NULL ) return ZSTD_ERROR (memory_allocation );
555
+ ZSTD_inBuffer in ;
556
+ in .pos = * src_offset ;
557
+ in .size = src_size ;
558
+ in .src = (* env )-> GetDirectBufferAddress (env , src );
559
+ if (in .src == NULL ) return ZSTD_ERROR (memory_allocation );
560
+
561
+ size_t result = ZSTD_decompressStream (dctx , & out , & in );
562
+ * dst_offset = out .pos ;
563
+ * src_offset = in .pos ;
564
+ return result ;
565
+ }
566
+
567
+ /*
568
+ * Class: com_github_luben_zstd_ZstdDecompressCtx
569
+ * Method: decompressDirectByteBufferStream0
570
+ * Signature: (Ljava/nio/ByteBuffer;IILjava/nio/ByteBuffer;II)J
571
+ */
572
+ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdDecompressCtx_decompressDirectByteBufferStream0
573
+ (JNIEnv * env , jclass jctx , jobject dst , jint dst_offset , jint dst_size , jobject src , jint src_offset , jint src_size )
574
+ {
575
+ size_t result = decompress_direct_buffer_stream (env , jctx , dst , & dst_offset , dst_size , src , & src_offset , src_size );
576
+ if (ZSTD_isError (result )) {
577
+ return (1ULL << 31 ) | ZSTD_getErrorCode (result );
578
+ }
579
+ jlong encoded_result = ((jlong )dst_offset << 32 ) | src_offset ;
580
+ if (result == 0 ) {
581
+ encoded_result |= 1ULL << 63 ;
582
+ }
583
+ return encoded_result ;
584
+ }
585
+
453
586
454
587
/*
455
588
* Class: com_github_luben_zstd_ZstdDecompressCtx
456
- * Method: decompressDirectByteBuffe0
589
+ * Method: decompressDirectByteBuffer0
457
590
* Signature: (Ljava/nio/ByteBuffer;IILjava/nio/ByteBuffer;II)J
458
591
*/
459
592
JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_ZstdDecompressCtx_decompressDirectByteBuffer0
0 commit comments