OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-storage commits / d3366fb

Add missing support for BoolValue decoding
d3366fb4b1920cb0121b0834e0ffaf1195d9d9fd
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-09T00:01:56.000Z

Changed files (1) +42 -0

opencog/persist/sexpr/ValueSexpr.cc +42 -0
……@@ -184,6 +184,48 @@ ValuePtr Sexpr::decode_value(const std::string& stv, size_t& pos)
184184 return valueserver().create(vtype, fv);
185185 }
186186
187 // BoolValue can be either "(BoolValue 1 0 1 ...)" or "(BoolValue #x...)"
188 if (nameserver().isA(vtype, BOOL_VALUE))
189 {
190 std::vector<bool> bv;
191 vos = stv.find_first_not_of(" \n\t", vos);
192
193 // Handle hex format: (BoolValue #x...)
194 if (vos < totlen and stv[vos] == '#' and vos+1 < totlen and stv[vos+1] == 'x')
195 {
196 vos += 2; // Skip "#x"
197 // Parse hex digits until we hit ')'
198 while (vos < totlen and stv[vos] != ')')
199 {
200 char c = stv[vos];
201 if (std::isxdigit(c))
202 {
203 int nibble = (c >= '0' and c <= '9') ? c - '0' :
204 (c >= 'a' and c <= 'f') ? c - 'a' + 10 :
205 (c >= 'A' and c <= 'F') ? c - 'A' + 10 : 0;
206 // Each hex digit represents 4 bits
207 for (int bit = 3; bit >= 0; bit--)
208 bv.push_back((nibble >> bit) & 1);
209 }
210 vos++;
211 }
212 }
213 else
214 {
215 // Handle individual bits: (BoolValue 1 0 1 ...)
216 while (vos < totlen and stv[vos] != ')')
217 {
218 vos = stv.find_first_not_of(" \n\t", vos);
219 if (vos >= totlen or stv[vos] == ')') break;
220 if (stv[vos] == '0') bv.push_back(false);
221 else if (stv[vos] == '1') bv.push_back(true);
222 vos++;
223 }
224 }
225 pos = vos + 1;
226 return valueserver().create(vtype, bv);
227 }
228
187229 // Unescape escaped quotes
188230 if (nameserver().isA(vtype, STRING_VALUE))
189231 {