} while (val);
}
+void OutputStream::write_uuid(const struct uuid &u)
+{
+ write(u.bytes, 16);
+}
+
/* Write an arbitrary string by first writing out the length, followed by the
* data itself. */
void OutputStream::write_string(const string &s)
return s.contents();
}
+string encode_objref(const struct uuid &segment, uint32_t object)
+{
+ StringOutputStream s;
+ s.write_uuid(segment);
+ s.write_u32(object);
+ return s.contents();
+}
+
SegmentWriter::SegmentWriter(OutputStream *output, struct uuid u)
: raw_out(output),
id(u),
/* Write out the segment header first. */
static const char signature[] = "LBSSEG0\n";
out->write(signature, strlen(signature));
- out->write(id.bytes, sizeof(struct uuid));
+ out->write_uuid(id);
}
SegmentWriter::~SegmentWriter()
for (object_table::const_iterator i = objects.begin();
i != objects.end(); ++i) {
- out->write_s64(i->first);
- out->write_s64(i->second);
+ out->write_s64(i->offset);
+ out->write_s64(i->size);
+ out->write(i->type, sizeof(i->type));
}
static const char signature2[] = "LBSEND";
delete raw_out;
}
-OutputStream *SegmentWriter::new_object()
+OutputStream *SegmentWriter::new_object(int *id, const char *type)
{
if (object_stream)
finish_object();
- object_start_offset = out->get_pos();
- object_stream = new WrapperOutputStream(*out);
+ if (id != NULL)
+ *id = objects.size();
+ struct index_info info;
+ info.offset = out->get_pos();
+ info.size = -1; // Will be filled in when object is finished
+ strncpy(info.type, type, sizeof(info.type));
+ objects.push_back(info);
+
+ object_stream = new WrapperOutputStream(*out);
return object_stream;
}
{
assert(object_stream != NULL);
- // store (start, length) information for locating this object
- objects.push_back(std::make_pair(object_start_offset,
- object_stream->get_pos()));
+ // Fill in object size, which could not be stored at start
+ objects.back().size = object_stream->get_pos();
delete object_stream;
object_stream = NULL;
delete segment;
}
-OutputStream *SegmentPartitioner::new_object()
+OutputStream *SegmentPartitioner::new_object(struct uuid *uuid, int *id,
+ const char *type)
{
if (segment != NULL && segment->get_size() > target_size) {
delete segment;
if (segment == NULL)
segment = store->new_segment();
- return segment->new_object();
+ if (uuid != NULL)
+ *uuid = segment->get_uuid();
+
+ return segment->new_object(id, type);
}