MCPcopy Create free account
hub / github.com/OSGeo/gdal / LoadMemory

Method LoadMemory

port/cpl_json.cpp:227–265  ·  view source on GitHub ↗

* Load json document from memory buffer. * @param pabyData Buffer.data. * @param nLength Buffer size. * @return true on success. If error occurred it can be received using * CPLGetLastErrorMsg method. * */

Source from the content-addressed store, hash-verified

225 *
226 */
227bool CPLJSONDocument::LoadMemory(const GByte *pabyData, int nLength)
228{
229 if (nullptr == pabyData)
230 {
231 return false;
232 }
233
234 if (m_poRootJsonObject)
235 json_object_put(TO_JSONOBJ(m_poRootJsonObject));
236
237 if (nLength == 4 &&
238 memcmp(reinterpret_cast<const char *>(pabyData), "true", nLength) == 0)
239 {
240 m_poRootJsonObject = json_object_new_boolean(true);
241 return true;
242 }
243
244 if (nLength == 5 &&
245 memcmp(reinterpret_cast<const char *>(pabyData), "false", nLength) == 0)
246 {
247 m_poRootJsonObject = json_object_new_boolean(false);
248 return true;
249 }
250
251 json_tokener *jstok = json_tokener_new();
252 m_poRootJsonObject = json_tokener_parse_ex(
253 jstok, reinterpret_cast<const char *>(pabyData), nLength);
254 bool bParsed = jstok->err == json_tokener_success;
255 if (!bParsed)
256 {
257 CPLError(CE_Failure, CPLE_AppDefined,
258 "JSON parsing error: %s (at offset %d)",
259 json_tokener_error_desc(jstok->err), jstok->char_offset);
260 json_tokener_free(jstok);
261 return false;
262 }
263 json_tokener_free(jstok);
264 return bParsed;
265}
266
267/**
268 * Load json document from memory buffer.

Callers 15

LoadFromJSONMethod · 0.80
createFromGeoJsonMethod · 0.80
SetFromUserInputMethod · 0.80
CreateSchemaCommonMethod · 0.80
LoadGDALSchemaMethod · 0.80
LoadGDALMetadataMethod · 0.80
LoadGeoMetadataMethod · 0.80
EstablishFeatureDefnMethod · 0.80
GetLayerByNameMethod · 0.80
BuildLayerDefnMethod · 0.80
ProcessMetadataFunction · 0.80
OpenMethod · 0.80

Calls 10

json_object_putFunction · 0.85
json_object_new_booleanFunction · 0.85
json_tokener_newFunction · 0.85
json_tokener_parse_exFunction · 0.85
CPLErrorFunction · 0.85
json_tokener_error_descFunction · 0.85
json_tokener_freeFunction · 0.85
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.64