]> iEval git - io-compress-brotli.git/commitdiff
Use ALIAS: for setting encoder parameters too
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 27 Aug 2016 23:01:50 +0000 (00:01 +0100)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 27 Aug 2016 23:01:50 +0000 (00:01 +0100)
Brotli.xs

index 10beb1c6fd891e2903f44539ef189002c4f01726..5b7d008594a958e07e8a12f5be841a9655bd52d8 100644 (file)
--- a/Brotli.xs
+++ b/Brotli.xs
@@ -157,47 +157,42 @@ create(class)
   OUTPUT:
     RETVAL
 
-SV*
-window(self, window)
-    IO::Compress::Brotli self
-    U32 window
-  CODE:
-    if( window < kBrotliMinWindowBits || window > kBrotliMaxWindowBits ) {
-        croak("Invalid window value");
-    }
-    if( BrotliEncoderSetParameter(self->encoder, BROTLI_PARAM_LGWIN, window) )
-        RETVAL = newSVuv(1);
-    else
-        RETVAL = newSVuv(0);
-  OUTPUT:
-    RETVAL
-
-SV*
-quality(self, quality)
+bool BrotliEncoderSetParameter(self, value)
     IO::Compress::Brotli self
-    U32 quality
-  CODE:
-    if( quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY ) {
-        croak("Invalid quality value");
+    U32 value
+  ALIAS:
+    window  = 1
+    quality = 2
+    _mode   = 3
+  PREINIT:
+    BrotliEncoderParameter param;
+  INIT:
+    switch(ix){
+    case 0:
+        croak("BrotliEncoderSetParameter may not be called directly");
+        break;
+    case 1:
+        if( value < kBrotliMinWindowBits || value > kBrotliMaxWindowBits ) {
+            croak("Invalid window value");
+        }
+        param = BROTLI_PARAM_LGWIN;
+        break;
+    case 2:
+        if( value < BROTLI_MIN_QUALITY || value > BROTLI_MAX_QUALITY ) {
+            croak("Invalid quality value");
+        }
+        param = BROTLI_PARAM_QUALITY;
+        break;
+    case 3:
+        /* Validation done on Perl side */
+        param = BROTLI_PARAM_MODE;
+        break;
+    default:
+        croak("Impossible ix in BrotliEncoderSetParameter");
+        break;
     }
-    if( BrotliEncoderSetParameter(self->encoder, BROTLI_PARAM_QUALITY, quality) )
-        RETVAL = newSVuv(1);
-    else
-        RETVAL = newSVuv(0);
-  OUTPUT:
-    RETVAL
-
-SV*
-_mode(self, mode)
-    IO::Compress::Brotli self
-    U32 mode
-  CODE:
-    if( BrotliEncoderSetParameter(self->encoder, BROTLI_PARAM_MODE, mode) )
-        RETVAL = newSVuv(1);
-    else
-        RETVAL = newSVuv(0);
-  OUTPUT:
-    RETVAL
+  C_ARGS:
+    self->encoder, param, value
 
 SV*
 _compress(self, in = &PL_sv_undef)
This page took 0.032068 seconds and 4 git commands to generate.