void serializeBlob(Symbol src) { Storage::Blob srcBlob(src); NativeNaturalType len = srcBlob.getSize(); if(len) { Symbol type = Ontology::VoidSymbol; Ontology::getUncertain(src, Ontology::BlobTypeSymbol, type); switch(type) { case Ontology::UTF8Symbol: { len /= 8; bool spaces = false; for(NativeNaturalType i = 0; i < len; ++i) { Natural8 element = srcBlob.readAt<Natural8>(i); if(element == ' ' || element == '\t' || element == '\n') { spaces = true; break; } } if(spaces) put('"'); for(NativeNaturalType i = 0; i < len; ++i) put(srcBlob.readAt<Natural8>(i)); if(spaces) put('"'); } break; case Ontology::NaturalSymbol: serializeNumber(srcBlob.readAt<NativeNaturalType>()); break; case Ontology::IntegerSymbol: serializeNumber(srcBlob.readAt<NativeIntegerType>()); break; case Ontology::FloatSymbol: serializeNumber(srcBlob.readAt<NativeFloatType>()); break; default: { puts(HRLRawBegin); len = (len+3)/4; for(NativeNaturalType i = 0; i < len; ++i) { Natural8 element = srcBlob.readAt<Natural8>(i/2), nibble = (element>>((i%2)*4))&0x0F; if(nibble < 0xA) put('0'+nibble); else put('A'+nibble-0xA); } } break; } } else {
static cx_int16 serializePrimitive(cx_serializer s, cx_value *v, void *userData) { CX_UNUSED(s); cx_type type = cx_valueType(v); cx_json_ser_t *data = userData; cx_int16 result; cx_string valueString; switch (cx_primitive(type)->kind) { case CX_BINARY: result = serializeBinary(v, &valueString); break; case CX_BITMASK: result = serializeBitmask(v, &valueString); break; case CX_BOOLEAN: result = serializeBoolean(v, &valueString); break; case CX_ENUM: result = serializeEnum(v, &valueString); break; case CX_CHARACTER: case CX_TEXT: result = serializeText(v, &valueString); break; case CX_UINTEGER: case CX_INTEGER: case CX_FLOAT: result = serializeNumber(v, &valueString); break; case CX_ALIAS: result = serializeAlias(v, &valueString); break; } if (result) { goto error; } if (!cx_ser_appendstr(data, "%s", valueString)) { goto finished; } cx_dealloc(valueString); return 0; finished: cx_dealloc(valueString); return 1; error: return -1; }