Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: Zarr driver, ZarrV3CodecAbstractCompressor class 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2023, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "zarr_v3_codec.h" 14 : 15 : #include "cpl_compressor.h" 16 : 17 : /************************************************************************/ 18 : /* ZarrV3CodecAbstractCompressor() */ 19 : /************************************************************************/ 20 : 21 563 : ZarrV3CodecAbstractCompressor::ZarrV3CodecAbstractCompressor( 22 563 : const std::string &osName) 23 563 : : ZarrV3Codec(osName) 24 : { 25 563 : } 26 : 27 : /************************************************************************/ 28 : /* ZarrV3CodecAbstractCompressor::Encode() */ 29 : /************************************************************************/ 30 : 31 5367 : bool ZarrV3CodecAbstractCompressor::Encode( 32 : const ZarrByteVectorQuickResize &abySrc, 33 : ZarrByteVectorQuickResize &abyDst) const 34 : { 35 5367 : abyDst.resize(abyDst.capacity()); 36 5367 : void *pOutputData = abyDst.data(); 37 5367 : size_t nOutputSize = abyDst.size(); 38 10734 : bool bRet = m_pCompressor->pfnFunc( 39 5367 : abySrc.data(), abySrc.size(), &pOutputData, &nOutputSize, 40 5367 : m_aosCompressorOptions.List(), m_pCompressor->user_data); 41 5367 : if (bRet) 42 : { 43 5367 : abyDst.resize(nOutputSize); 44 : } 45 0 : else if (nOutputSize > abyDst.size()) 46 : { 47 0 : CPLError(CE_Failure, CPLE_AppDefined, 48 : "%s codec:Encode(): output buffer too small", 49 : m_osName.c_str()); 50 : } 51 5367 : return bRet; 52 : } 53 : 54 : /************************************************************************/ 55 : /* ZarrV3CodecAbstractCompressor::Decode() */ 56 : /************************************************************************/ 57 : 58 17383 : bool ZarrV3CodecAbstractCompressor::Decode( 59 : const ZarrByteVectorQuickResize &abySrc, 60 : ZarrByteVectorQuickResize &abyDst) const 61 : { 62 17383 : abyDst.resize(abyDst.capacity()); 63 17383 : void *pOutputData = abyDst.data(); 64 17383 : size_t nOutputSize = abyDst.size(); 65 17383 : bool bRet = m_pDecompressor->pfnFunc(abySrc.data(), abySrc.size(), 66 : &pOutputData, &nOutputSize, nullptr, 67 17383 : m_pDecompressor->user_data); 68 17383 : if (bRet) 69 : { 70 16657 : abyDst.resize(nOutputSize); 71 : } 72 726 : else if (nOutputSize > abyDst.size()) 73 : { 74 0 : CPLError(CE_Failure, CPLE_AppDefined, 75 : "%s codec:Decode(): output buffer too small", 76 : m_osName.c_str()); 77 : } 78 17383 : return bRet; 79 : }