MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / SIValue_ToString

Function SIValue_ToString

src/value.c:312–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310}
311
312void SIValue_ToString(SIValue v, char **buf, size_t *bufferLen, size_t *bytesWritten) {
313 // uint64 max and int64 min string representation requires 21 bytes
314 // checkt for enough space
315 if(*bufferLen - *bytesWritten < 64) {
316 *bufferLen += 64;
317 *buf = rm_realloc(*buf, sizeof(char) * *bufferLen);
318 }
319
320 switch(v.type) {
321 case T_STRING:
322 _SIString_ToString(v, buf, bufferLen, bytesWritten);
323 break;
324 case T_INT64:
325 *bytesWritten += snprintf(*buf + *bytesWritten, *bufferLen, "%lld", (long long)v.longval);
326 break;
327 case T_BOOL:
328 *bytesWritten += snprintf(*buf + *bytesWritten, *bufferLen, "%s", v.longval ? "true" : "false");
329 break;
330 case T_DOUBLE:
331 {
332 size_t n = snprintf(*buf + *bytesWritten, *bufferLen - *bytesWritten, "%f", v.doubleval);
333 // check if there was enough space in the buffer
334 if(*bytesWritten + n > *bufferLen) {
335 // realloc the buffer
336 *bufferLen = *bytesWritten + n + 1;
337 *buf = rm_realloc(*buf, sizeof(char) * *bufferLen);
338
339 // write it again
340 snprintf(*buf + *bytesWritten, *bufferLen - *bytesWritten, "%f", v.doubleval);
341 }
342 *bytesWritten += n;
343 break;
344 }
345 case T_NODE:
346 Node_ToString(v.ptrval, buf, bufferLen, bytesWritten, ENTITY_ID);
347 break;
348 case T_EDGE:
349 Edge_ToString(v.ptrval, buf, bufferLen, bytesWritten, ENTITY_ID);
350 break;
351 case T_ARRAY:
352 SIArray_ToString(v, buf, bufferLen, bytesWritten);
353 break;
354 case T_MAP:
355 Map_ToString(v, buf, bufferLen, bytesWritten);
356 break;
357 case T_PATH:
358 SIPath_ToString(v, buf, bufferLen, bytesWritten);
359 break;
360 case T_NULL:
361 *bytesWritten += snprintf(*buf + *bytesWritten, *bufferLen, "NULL");
362 break;
363 case T_PTR:
364 *bytesWritten += snprintf(*buf + *bytesWritten, *bufferLen, "POINTER");
365 break;
366 case T_POINT:
367 // max string length is 32 chars of string + 10 * 2 chars for the floats
368 // = 52 bytes that already checked in the header of the function
369 *bytesWritten += snprintf(*buf + *bytesWritten, *bufferLen, "point({latitude: %f, longitude: %f})", Point_lat(v), Point_lon(v));

Callers 9

SIValue_StringJoinFunction · 0.85
_AR_EXP_ToStringFunction · 0.85
AR_TOSTRINGFunction · 0.85
SIArray_ToStringFunction · 0.85
Map_ToStringFunction · 0.85
SIPath_ToStringFunction · 0.85

Calls 9

rm_reallocFunction · 0.85
_SIString_ToStringFunction · 0.85
Node_ToStringFunction · 0.85
Edge_ToStringFunction · 0.85
SIArray_ToStringFunction · 0.85
Map_ToStringFunction · 0.85
SIPath_ToStringFunction · 0.85
Point_latFunction · 0.85
Point_lonFunction · 0.85

Tested by

no test coverage detected