void Hash_serialize(Hash *self, OutStream *outstream) { Obj *key; Obj *val; uint32_t charbuf_count = 0; OutStream_Write_C32(outstream, self->size); // Write CharBuf keys first. CharBuf keys are the common case; grouping // them together is a form of run-length-encoding and saves space, since // we omit the per-key class name. Hash_Iterate(self); while (Hash_Next(self, &key, &val)) { if (Obj_Is_A(key, CHARBUF)) { charbuf_count++; } } OutStream_Write_C32(outstream, charbuf_count); Hash_Iterate(self); while (Hash_Next(self, &key, &val)) { if (Obj_Is_A(key, CHARBUF)) { Obj_Serialize(key, outstream); FREEZE(val, outstream); } } // Punt on the classes of the remaining keys. Hash_Iterate(self); while (Hash_Next(self, &key, &val)) { if (!Obj_Is_A(key, CHARBUF)) { FREEZE(key, outstream); FREEZE(val, outstream); } } }
void TextTermStepper_write_key_frame(TextTermStepper *self, OutStream *outstream, Obj *value) { Obj_Serialize(value, outstream); Obj_Mimic(self->value, value); }
void DocWriter_add_inverted_doc(DocWriter *self, Inverter *inverter, int32_t doc_id) { OutStream *dat_out = S_lazy_init(self); OutStream *ix_out = self->ix_out; uint32_t num_stored = 0; int64_t start = OutStream_Tell(dat_out); int64_t expected = OutStream_Tell(ix_out) / 8; // Verify doc id. if (doc_id != expected) { THROW(ERR, "Expected doc id %i64 but got %i32", expected, doc_id); } // Write the number of stored fields. Inverter_Iterate(inverter); while (Inverter_Next(inverter)) { FieldType *type = Inverter_Get_Type(inverter); if (FType_Stored(type)) { num_stored++; } } OutStream_Write_C32(dat_out, num_stored); Inverter_Iterate(inverter); while (Inverter_Next(inverter)) { // Only store fields marked as "stored". FieldType *type = Inverter_Get_Type(inverter); if (FType_Stored(type)) { CharBuf *field = Inverter_Get_Field_Name(inverter); Obj *value = Inverter_Get_Value(inverter); CB_Serialize(field, dat_out); Obj_Serialize(value, dat_out); } } // Write file pointer. OutStream_Write_I64(ix_out, start); }
void Freezer_freeze(Obj *obj, OutStream *outstream) { CB_Serialize(Obj_Get_Class_Name(obj), outstream); Obj_Serialize(obj, outstream); }