func (e *segmentEntry) write(writer typedio.Writer) (err os.Error) { err = writer.WriteUint64(e.position) // position if err != nil { return err } buf := gsbuffer.New() err = e.mutation.serialize(buf) if err != nil { return err } e.mutsize = uint32(buf.Size) err = writer.WriteUint16(uint16(e.token)) // token if err != nil { return err } err = writer.WriteUint32(e.mutsize) // size of mutation if err != nil { return err } buf.Seek(0, 0) written, err := writer.Write(buf.Bytes()) // mutation if err != nil { return err } if written != int(e.mutsize) { return os.NewError(fmt.Sprintf("Couldn't write the whole mutation entry! Written %d of %d", written, e.mutsize)) } return }
func (mut *mutation) serialize(writer typedio.Writer) (err os.Error) { err = writer.WriteUint16(mut.typ) // type if err != nil { return } switch mut.typ { case mut_create_vs: case mut_commit_vs: case mut_rollback_vs: err = writer.WriteUint32(mut.vs) // viewstate if err != nil { return } case mut_obj_op: err = writer.WriteUint16(operation2id(mut.op.(operation))) // operation id if err != nil { return } var bytes []uint8 bytes, err = proto.Marshal(mut.op) if err != nil { return } err = writer.WriteUint32(uint32(len(bytes))) // operation size if err != nil { return } _, err = writer.Write(bytes) // operation if err != nil { return } _, err = writer.Write([]byte{mut.flags}) // flags if err != nil { return } err = writer.WriteUint64(mut.lastPos) // object last position if err != nil { return } } return }