void AMFWriter::writeObject(const AMFObject& amfObject) { beginObject(); AbstractConfiguration::Keys keys; amfObject.keys(keys); AbstractConfiguration::Keys::const_iterator it; for(it=keys.begin();it!=keys.end();++it) { string name = *it; _writer.writeString16(name); int type = amfObject.getInt(name+".type",-1); switch(type) { case AMF_BOOLEAN: writeBool(amfObject.getBool(name)); break; case AMF_STRING: write(amfObject.getString(name)); break; case AMF_NUMBER: writeNumber(amfObject.getDouble(name)); break; case AMF_UNDEFINED: write(""); break; case AMF_NULL: writeNull(); break; default: ERROR("Unknown AMF '%d' type",type); } } endObject(); }
void File::writeHeader(bool no_extra_foot) { if (!file_ptr) { Error::addMessage(Error::NULL_REFERENCE, LIBGENS_FILE_H_ERROR_FILE_HEADER); return; } sortAddressTable(); unsigned int final_table_address=getFileSize()-root_node_address; unsigned int final_table_address_abs=getFileSize(); unsigned int final_table_size=final_address_table.size(); writeInt32BE(&final_table_size); for (list<size_t>::iterator it=final_address_table.begin(); it!=final_address_table.end(); it++) { writeInt32BE(&(*it)); } if (!no_extra_foot) writeNull(4); unsigned int size=getFileSize(); unsigned int size_foot=size-4; if (no_extra_foot) { size_foot = 0; } goToAddress(0); writeInt32BE(&size); writeInt32BE(&root_node_type); writeInt32BE(&final_table_address); writeInt32BE(&root_node_address); writeInt32BE(&final_table_address_abs); writeInt32BE(&size_foot); }
void AMFWriter::writeResponseHeader(const string& key,double callbackHandle) { _writer.write8(0x14); _writer.write32(0); write(key); writeNumber(callbackHandle); writeNull(); }
//找到一个没用的扇区,并全部写0,返回该扇区的编号 BLOCK * createBlock() { int blockPos = getFreeBlockNumber(superBlockPointer); fseek(dataFp, superBlockPointer->blockSize * blockPos, SEEK_SET); writeNull(512, dataFp); BLOCK * blockP = (BLOCK *)Malloc(sizeof(BLOCK)); blockP->blockNumber = blockPos; return blockP; }
void MessageEncoder::writeHeader(const Header& msg) { size_t fields(optimise ? optimisable(msg) : 5); if (fields) { void* token = startList8(&qpid::amqp::message::HEADER); writeBoolean(msg.isDurable()); if (fields > 1) writeUByte(msg.getPriority()); if (msg.getTtl()) writeUInt(msg.getTtl()); else if (fields > 2) writeNull(); if (msg.isFirstAcquirer()) writeBoolean(true); else if (fields > 3) writeNull(); if (msg.getDeliveryCount()) writeUInt(msg.getDeliveryCount()); else if (fields > 4) writeNull(); endList8(fields, token); } }
/** * @brief Writes the specified JSON element to `writer`. * @param writer The JSONWriter. * @param obj The JSON element to write. */ static void writeElement(JSONWriter *writer, const ident obj) { const Object *object = cast(Object, obj); if (object) { if ($(object, isKindOfClass, _Dictionary())) { writeObject(writer, (Dictionary *) object); } else if ($(object, isKindOfClass, _Array())) { writeArray(writer, (Array *) object); } else if ($(object, isKindOfClass, _String())) { writeString(writer, (String *) object); } else if ($(object, isKindOfClass, _Number())) { writeNumber(writer, (Number *) object); } else if ($(object, isKindOfClass, _Boole())) { writeBoole(writer, (Boole *) object); } else if ($(object, isKindOfClass, _Null())) { writeNull(writer, (Null *) object); } } }
//============================================================================== String StringArray::joinIntoString (StringRef separator, int start, int numberToJoin) const { auto last = (numberToJoin < 0) ? size() : jmin (size(), start + numberToJoin); if (start < 0) start = 0; if (start >= last) return {}; if (start == last - 1) return strings.getReference (start); auto separatorBytes = separator.text.sizeInBytes() - sizeof (String::CharPointerType::CharType); auto bytesNeeded = separatorBytes * (size_t) (last - start - 1); for (int i = start; i < last; ++i) bytesNeeded += strings.getReference(i).getCharPointer().sizeInBytes() - sizeof (String::CharPointerType::CharType); String result; result.preallocateBytes (bytesNeeded); auto dest = result.getCharPointer(); while (start < last) { auto& s = strings.getReference (start); if (! s.isEmpty()) dest.writeAll (s.getCharPointer()); if (++start < last && separatorBytes > 0) dest.writeAll (separator.text); } dest.writeNull(); return result; }
void Writer::write(Appender& appender, const Value& value, Size indent) { switch (value.getType()) { case Value::Type::Null: writeNull(appender); break; case Value::Type::Boolean: writeBoolean(appender, value.asBoolean()); break; case Value::Type::Number: writeNumber(appender, value.asDouble()); break; case Value::Type::String: writeString(appender, value.asString()); break; case Value::Type::Array: writeArray(appender, value, indent); break; case Value::Type::Object: writeObject(appender, value, indent); break; } }
void DataWriter::writeNullProperty(const string& name) { writePropertyName(name); writeNull(); }
void AMFWriter::writeObjectProperty(const string& name) { writePropertyName(name); writeNull(); }
void MessageEncoder::writeProperties(const Properties& msg) { size_t fields(optimise ? optimisable(msg) : 13); if (fields) { void* token = startList32(&qpid::amqp::message::PROPERTIES); if (msg.hasMessageId()) writeString(msg.getMessageId()); else writeNull(); if (msg.hasUserId()) writeBinary(msg.getUserId()); else if (fields > 1) writeNull(); if (msg.hasTo()) writeString(msg.getTo()); else if (fields > 2) writeNull(); if (msg.hasSubject()) writeString(msg.getSubject()); else if (fields > 3) writeNull(); if (msg.hasReplyTo()) writeString(msg.getReplyTo()); else if (fields > 4) writeNull(); if (msg.hasCorrelationId()) writeString(msg.getCorrelationId()); else if (fields > 5) writeNull(); if (msg.hasContentType()) writeSymbol(msg.getContentType()); else if (fields > 6) writeNull(); if (msg.hasContentEncoding()) writeSymbol(msg.getContentEncoding()); else if (fields > 7) writeNull(); if (msg.hasAbsoluteExpiryTime()) writeLong(msg.getAbsoluteExpiryTime()); else if (fields > 8) writeNull(); if (msg.hasCreationTime()) writeLong(msg.getCreationTime()); else if (fields > 9) writeNull(); if (msg.hasGroupId()) writeString(msg.getGroupId()); else if (fields > 10) writeNull(); if (msg.hasGroupSequence()) writeUInt(msg.getGroupSequence()); else if (fields > 11) writeNull(); if (msg.hasReplyToGroupId()) writeString(msg.getReplyToGroupId()); else if (fields > 12) writeNull(); endList32(fields, token); } }
void MessageEncoder::writeMap(const qpid::types::Variant::Map& properties, const Descriptor* d, bool large) { void* token = large ? startMap32(d) : startMap8(d); for (qpid::types::Variant::Map::const_iterator i = properties.begin(); i != properties.end(); ++i) { writeString(i->first); switch (i->second.getType()) { case qpid::types::VAR_MAP: case qpid::types::VAR_LIST: //not allowed (TODO: revise, only strictly true for application-properties) whereas this is now a more general method) QPID_LOG(warning, "Ignoring nested map/list; not allowed in application-properties for AMQP 1.0"); case qpid::types::VAR_VOID: writeNull(); break; case qpid::types::VAR_BOOL: writeBoolean(i->second); break; case qpid::types::VAR_UINT8: writeUByte(i->second); break; case qpid::types::VAR_UINT16: writeUShort(i->second); break; case qpid::types::VAR_UINT32: writeUInt(i->second); break; case qpid::types::VAR_UINT64: writeULong(i->second); break; case qpid::types::VAR_INT8: writeByte(i->second); break; case qpid::types::VAR_INT16: writeShort(i->second); break; case qpid::types::VAR_INT32: writeInt(i->second); break; case qpid::types::VAR_INT64: writeULong(i->second); break; case qpid::types::VAR_FLOAT: writeFloat(i->second); break; case qpid::types::VAR_DOUBLE: writeDouble(i->second); break; case qpid::types::VAR_STRING: if (i->second.getEncoding() == BINARY) { writeBinary(i->second); } else { writeString(i->second); } break; case qpid::types::VAR_UUID: writeUuid(i->second); break; } } if (large) endMap32(properties.size()*2, token); else endMap8(properties.size()*2, token); }
Writer& Writer::writeNull(const std::string& name) { setValueName(name); return writeNull(); }
void File::prepareHeader(int root_type, int root_offset) { root_node_type=root_type; root_node_address=root_offset; writeNull(LIBGENS_FILE_HEADER_ROOT_ADDRESS_DEFAULT); }
void File::writeString(string *dest) { if (!readSafeCheck(dest)) return; if (!dest->size()) writeNull(1); else fwrite(dest->c_str(), sizeof(char), dest->size()+1, file_ptr); }