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 647 : ZarrV3CodecAbstractCompressor::ZarrV3CodecAbstractCompressor( 22 647 : const std::string &osName) 23 647 : : ZarrV3Codec(osName) 24 : { 25 647 : } 26 : 27 : /************************************************************************/ 28 : /* ZarrV3CodecAbstractCompressor::Encode() */ 29 : /************************************************************************/ 30 : 31 9593 : bool ZarrV3CodecAbstractCompressor::Encode( 32 : const ZarrByteVectorQuickResize &abySrc, 33 : ZarrByteVectorQuickResize &abyDst) const 34 : { 35 9593 : abyDst.resize(abyDst.capacity()); 36 9593 : void *pOutputData = abyDst.data(); 37 9593 : size_t nOutputSize = abyDst.size(); 38 19186 : bool bRet = m_pCompressor->pfnFunc( 39 9593 : abySrc.data(), abySrc.size(), &pOutputData, &nOutputSize, 40 9593 : m_aosCompressorOptions.List(), m_pCompressor->user_data); 41 9593 : if (bRet) 42 : { 43 9593 : 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 9593 : return bRet; 52 : } 53 : 54 : /************************************************************************/ 55 : /* ZarrV3CodecAbstractCompressor::Decode() */ 56 : /************************************************************************/ 57 : 58 21950 : bool ZarrV3CodecAbstractCompressor::Decode( 59 : const ZarrByteVectorQuickResize &abySrc, 60 : ZarrByteVectorQuickResize &abyDst) const 61 : { 62 21950 : abyDst.resize(abyDst.capacity()); 63 21950 : void *pOutputData = abyDst.data(); 64 21950 : size_t nOutputSize = abyDst.size(); 65 21950 : bool bRet = m_pDecompressor->pfnFunc(abySrc.data(), abySrc.size(), 66 : &pOutputData, &nOutputSize, nullptr, 67 21950 : m_pDecompressor->user_data); 68 21950 : if (bRet) 69 : { 70 21238 : abyDst.resize(nOutputSize); 71 : } 72 712 : 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 21950 : return bRet; 79 : }