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

Function GraphEntity_PropertiesToString

src/graph/entities/graph_entity.c:85–128  ·  view source on GitHub ↗

prints the attribute set into a buffer, returns what is the string length buffer can be re-allocated if needed

Source from the content-addressed store, hash-verified

83// prints the attribute set into a buffer, returns what is the string length
84// buffer can be re-allocated if needed
85size_t GraphEntity_PropertiesToString
86(
87 const GraphEntity *e,
88 char **buffer,
89 size_t *bufferLen,
90 size_t *bytesWritten
91) {
92 // make sure there is enough space for "{...}\0"
93 if(*bufferLen - *bytesWritten < 64) {
94 *bufferLen += 64;
95 *buffer = rm_realloc(*buffer, *bufferLen);
96 }
97 *bytesWritten += snprintf(*buffer, *bufferLen, "{");
98 GraphContext *gc = QueryCtx_GetGraphCtx();
99 const AttributeSet set = GraphEntity_GetAttributes(e);
100 int propCount = AttributeSet_Count(set);
101 for(int i = 0; i < propCount; i++) {
102 Attribute_ID attr_id;
103 SIValue value = AttributeSet_GetIdx(set, i, &attr_id);
104 // print key
105 const char *key = GraphContext_GetAttributeString(gc, attr_id);
106 // check for enough space
107 size_t keyLen = strlen(key);
108 if(*bufferLen - *bytesWritten < keyLen) {
109 *bufferLen += keyLen;
110 *buffer = rm_realloc(*buffer, *bufferLen);
111 }
112 *bytesWritten += snprintf(*buffer + *bytesWritten, *bufferLen, "%s:", key);
113
114 // print value
115 SIValue_ToString(value, buffer, bufferLen, bytesWritten);
116
117 // if not the last element print ", "
118 if(i != propCount - 1) *bytesWritten = snprintf(*buffer + *bytesWritten, *bufferLen, ", ");
119
120 }
121 // check for enough space for close with "}\0"
122 if(*bufferLen - *bytesWritten < 2) {
123 *bufferLen += 2;
124 *buffer = rm_realloc(*buffer, *bufferLen);
125 }
126 *bytesWritten += snprintf(*buffer + *bytesWritten, *bufferLen, "}");
127 return *bytesWritten;
128}
129
130void GraphEntity_ToString
131(

Callers 1

GraphEntity_ToStringFunction · 0.85

Calls 7

rm_reallocFunction · 0.85
QueryCtx_GetGraphCtxFunction · 0.85
AttributeSet_CountFunction · 0.85
AttributeSet_GetIdxFunction · 0.85
SIValue_ToStringFunction · 0.85

Tested by

no test coverage detected