Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: Zarr driver 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef VSIKERCHUNK_INLINE_HPP 14 : #define VSIKERCHUNK_INLINE_HPP 15 : 16 : #include <string_view> 17 : 18 : inline bool 19 232 : ZARRIsLikelyStreamableKerchunkJSONRefContent(const std::string_view &str) 20 : { 21 : // v0 22 552 : for (const char *pszExpectedPrefix : {"{\".zgroup\":{", "{\".zgroup\":\"{", 23 784 : "{\".zattrs\":{", "{\".zattrs\":\"{"}) 24 : { 25 99297 : for (char ch : str) 26 : { 27 99277 : if (!(ch == ' ' || ch == '\n' || ch == '\r')) 28 : { 29 2740 : if (ch != *pszExpectedPrefix) 30 532 : break; 31 2208 : ++pszExpectedPrefix; 32 2208 : if (*pszExpectedPrefix == 0) 33 : { 34 94 : return true; 35 : } 36 : } 37 : } 38 : } 39 : 40 : { 41 : // v1 42 138 : const char *pszExpectedPrefix = "{\"version\":1,\"refs\":{"; 43 24628 : for (char ch : str) 44 : { 45 24623 : if (!(ch == ' ' || ch == '\n' || ch == '\r')) 46 : { 47 493 : if (ch != *pszExpectedPrefix) 48 129 : break; 49 364 : ++pszExpectedPrefix; 50 364 : if (*pszExpectedPrefix == 0) 51 : { 52 4 : return str.find("\".zgroup\"") != std::string::npos || 53 4 : str.find("\".zarray\"") != std::string::npos; 54 : } 55 : } 56 : } 57 : } 58 134 : return false; 59 : } 60 : 61 : #endif