Exemplo n.º 1
0
func (dm *clusterMutation) Serialize(writer typedio.Writer) {
	writer.WriteInt64(dm.version)
	writer.WriteUint16(uint16(len(dm.nodes)))

	for _, node := range dm.nodes {
		node.Serialize(writer)
	}

	// if data were persisted to disk, we don't make the cluster
	// since its not new data
	dm.notify = false
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
func (n *Node) Serialize(writer typedio.Writer) (err os.Error) {
	err = writer.WriteUint16(n.Id) // id
	if err != nil {
		return
	}

	err = writer.WriteUint8(n.Status) // status
	if err != nil {
		return
	}

	err = writer.WriteString(n.Address.String()) // address
	if err != nil {
		return
	}

	err = writer.WriteUint16(n.TcpPort) // tcp port
	if err != nil {
		return
	}

	err = writer.WriteUint16(n.UdpPort) // udp port
	if err != nil {
		return
	}

	err = writer.WriteUint8(uint8(len(n.Rings))) // nb rings
	if err != nil {
		return
	}

	for _, ring := range n.Rings { // each ring
		err = writer.WriteUint8(ring.Ring)
		if err != nil {
			return
		}

		err = writer.WriteString(ring.Token)
		if err != nil {
			return
		}
	}

	return nil
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
func (m *Int64Mutation) Serialize(writer typedio.Writer) {
	writer.WriteInt64(m.val)
}