std::vector<char> serializeDictionary(const T& dic) { std::vector<char> buffer; buffer.reserve(512); serializeDictionary(buffer, dic); return buffer; }
/** * Serialize a benc object into a bencoded string. * This is not exposed to the world because it is expected that one would * know what type they are serializing to begin with. * * @param writer a Writer which to write the output to. * @param obj the object to serialize. * @return -2 if the type of object cannot be determined, otherwise * whatever is returned by the Writer. */ static int32_t serializeGeneric(const struct Writer* writer, const Object* obj) { switch (obj->type) { case Object_STRING: return serializeString(writer, obj->as.string); break; case Object_DICT: return serializeDictionary(writer, obj->as.dictionary); break; case Object_LIST: return serializeList(writer, obj->as.list); break; case Object_INTEGER: return serializeint64_t(writer, obj->as.number); break; default: return -2; } }