From: Marius Gavrilescu Date: Sat, 27 Aug 2016 23:01:50 +0000 (+0100) Subject: Use ALIAS: for setting encoder parameters too X-Git-Tag: 0.002~8 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=2574e61c271349c0a1562d2f1449797dbbbfc55d;p=io-compress-brotli.git Use ALIAS: for setting encoder parameters too --- diff --git a/Brotli.xs b/Brotli.xs index 10beb1c..5b7d008 100644 --- 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)