예제 #1
0
func (cl *CommitLog) readOne(reader typedio.Reader) (mutInfo mutationInfo, size int64) {
	// read mutation id
	id, err := reader.ReadUint8()
	if err != nil {
		log.Fatal("CommitLog: Couldn't read mutation from commit log: %s", err)
	}

	// get the right mutation for the read id
	mutInfo, found := cl.mutations[id]
	if !found {
		log.Fatal("CommitLog: Cannot find mutation id %d!", id)
	}

	// read the mutation
	mutInfo.mutation.Unserialize(reader)

	// read size of the mutation record
	size, err = reader.ReadInt64()
	if err != nil && err != os.EOF {
		log.Fatal("CommitLog: Couldn't read size of mutation from commit log: %s", err)
	}

	return mutInfo, size
}
예제 #2
0
파일: node.go 프로젝트: appaquet/gostore
func (n *Node) Unserialize(reader typedio.Reader) (err os.Error) {
	n.Id, err = reader.ReadUint16() // id
	if err != nil {
		return err
	}

	n.Status, err = reader.ReadUint8() // status
	if err != nil {
		return err
	}

	strAddr, err := reader.ReadString() // address
	if err != nil {
		return err
	}
	n.Address = net.ParseIP(strAddr)

	n.TcpPort, err = reader.ReadUint16() // tcp port
	if err != nil {
		return err
	}

	n.UdpPort, err = reader.ReadUint16() // udp port
	if err != nil {
		return err
	}

	nbRings, err := reader.ReadUint8() // nb rings
	if err != nil {
		return err
	}

	n.Rings = make([]NodeRing, nbRings)
	var i uint8
	for i = 0; i < nbRings; i++ { // each ring
		nodeRing := NodeRing{}

		nodeRing.Ring, err = reader.ReadUint8()
		if err != nil {
			return err
		}

		nodeRing.Token, err = reader.ReadString()
		if err != nil {
			return err
		}
	}

	return nil
}