Esempio n. 1
0
func (e *segmentEntry) read(reader typedio.Reader) (err os.Error) {
	e.position, err = reader.ReadUint64() // position
	if err != nil {
		return err
	}

	tokenInt, err := reader.ReadUint16() // token
	if err != nil {
		return err
	}
	e.token = Token(tokenInt)

	e.mutsize, err = reader.ReadUint32() // size of mutation
	if err != nil {
		return err
	}

	e.mutation, err = mutationUnserialize(reader) // mutation
	if err != nil {
		return err
	}
	e.mutation.segEntry = e
	e.mutation.token = e.token
	e.mutation.seg = e.segment

	return
}
Esempio n. 2
0
func mutationUnserialize(reader typedio.Reader) (mut *mutation, err os.Error) {
	mut = &mutation{}

	mut.typ, err = reader.ReadUint16() // type
	if err != nil {
		return mut, err
	}

	switch mut.typ {

	case mut_create_vs:
	case mut_commit_vs:
	case mut_rollback_vs:
		mut.vs, err = reader.ReadUint32() // viewstate
		if err != nil {
			return mut, err
		}

	case mut_obj_op:
		opid, err := reader.ReadUint16() // operation id
		if err != nil {
			return mut, err
		}
		mut.op = id2operation(opid).(mutationOperation)

		var bytes []byte
		var bytecount uint32

		bytecount, err = reader.ReadUint32() // operation size
		if err != nil {
			return mut, err
		}

		bytes = make([]byte, int(bytecount))
		_, err = reader.Read(bytes) // operation
		if err != nil {
			return mut, err
		}

		err = proto.Unmarshal(bytes, mut.op)
		if err != nil {
			return mut, err
		}

		bytes = make([]byte, 1)
		_, err = reader.Read(bytes) // flags
		if err != nil {
			return mut, err
		}
		mut.flags = bytes[0]

		mut.lastPos, err = reader.ReadUint64() // object last position
		if err != nil {
			return mut, err
		}

	default:
		return nil, os.NewError(fmt.Sprintf("Unknown mutation type to unserialize: %d", mut.typ))
	}

	return mut, err
}