Updated ring buffer examples
authorYann Collet <yann.collet.73@gmail.com>
Mon, 3 Nov 2014 08:29:45 +0000 (09:29 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 3 Nov 2014 08:29:45 +0000 (09:29 +0100)
examples/HCStreaming_ringBuffer.c [changed mode: 0755->0644]
examples/blockStreaming_ringBuffer.c

old mode 100755 (executable)
new mode 100644 (file)
index 53e14ca..afe77ae
@@ -3,8 +3,8 @@
 
 
 /**************************************
-Compiler Options
-**************************************/
+ * Compiler Options
+ **************************************/
 #ifdef _MSC_VER    /* Visual Studio */
 #  define _CRT_SECURE_NO_WARNINGS // for MSVC
 #  define snprintf sprintf_s
@@ -16,10 +16,9 @@ Compiler Options
 #endif
 
 
-
 /**************************************
-Includes
-**************************************/
+ * Includes
+ **************************************/
 #include "lz4hc.h"
 #include "lz4.h"
 
@@ -98,7 +97,7 @@ void test_decompress(FILE* outFp, FILE* inpFp)
     LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;
     unsigned done = 0;
 
-    for(;;) 
+    for(;;)
     {
         int  cmpBytes = 0;
         char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];
@@ -106,11 +105,11 @@ void test_decompress(FILE* outFp, FILE* inpFp)
         {
             const size_t r0 = read_int32(inpFp, &cmpBytes);
             size_t r1;
-            if(r0 != 1 || cmpBytes <= 0) 
+            if(r0 != 1 || cmpBytes <= 0)
                 break;
 
             r1 = read_bin(inpFp, cmpBuf, cmpBytes);
-            if(r1 != (size_t) cmpBytes) 
+            if(r1 != (size_t) cmpBytes)
                 break;
         }
 
@@ -118,7 +117,7 @@ void test_decompress(FILE* outFp, FILE* inpFp)
             char* const decPtr = &decBuf[decOffset];
             const int decBytes = LZ4_decompress_safe_continue(
                 lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES);
-            if(decBytes <= 0) 
+            if(decBytes <= 0)
                 break;
 
             done += decBytes;
@@ -126,7 +125,7 @@ void test_decompress(FILE* outFp, FILE* inpFp)
             write_bin(outFp, decPtr, decBytes);
 
             // Wraparound the ringbuffer offset
-            if(decOffset >= DEC_BUFFER_BYTES - MESSAGE_MAX_BYTES) 
+            if(decOffset >= DEC_BUFFER_BYTES - MESSAGE_MAX_BYTES)
                 decOffset = 0;
         }
     }
@@ -192,9 +191,9 @@ int main(int argc, char** argv)
     snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[fileID], 9);
     snprintf(decFilename, 256, "%s.lz4s-%d.dec", argv[fileID], 9);
 
-    printf("inp = [%s]\n", inpFilename);
-    printf("lz4 = [%s]\n", lz4Filename);
-    printf("dec = [%s]\n", decFilename);
+    printf("input   = [%s]\n", inpFilename);
+    printf("lz4     = [%s]\n", lz4Filename);
+    printf("decoded = [%s]\n", decFilename);
 
     // compress
     {
index bfdbed1..eda721f 100644 (file)
@@ -1,18 +1,32 @@
 // LZ4 streaming API example : ring buffer
-// Copyright : Takayuki Matsuoka
+// Based on sample code from Takayuki Matsuoka
 
 
-#define _CRT_SECURE_NO_WARNINGS // for MSVC
-#include "lz4.h"
+/**************************************
+ * Compiler Options
+ **************************************/
+#ifdef _MSC_VER    /* Visual Studio */
+#  define _CRT_SECURE_NO_WARNINGS // for MSVC
+#  define snprintf sprintf_s
+#endif
+#ifdef __GNUC__
+#  pragma GCC diagnostic ignored "-Wmissing-braces"   /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
+#endif
+
 
+/**************************************
+ * Includes
+ **************************************/
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include "lz4.h"
+
 
 enum {
     MESSAGE_MAX_BYTES   = 1024,
-    RING_BUFFER_BYTES   = 1024 * 256 + MESSAGE_MAX_BYTES,
+    RING_BUFFER_BYTES   = 1024 * 8 + MESSAGE_MAX_BYTES,
     DICT_BYTES          = 65536,
 };