Exemple #1
0
// Send sends marshaled data through 0mq socket.
func (t *Types) Send(sock *goczmq.Sock) (err error) {
	frame, err := t.Marshal()
	if err != nil {
		return err
	}

	socType := sock.GetType()
	if err != nil {
		return err
	}

	// If we're sending to a ROUTER, we send the routingID first
	if socType == goczmq.Router {
		err = sock.SendFrame(t.routingID, goczmq.FlagMore)
		if err != nil {
			return err
		}
	}

	// Now send the data frame
	err = sock.SendFrame(frame, 0)
	if err != nil {
		return err
	}

	return err
}
Exemple #2
0
// Send sends marshaled data through 0mq socket.
func (b *Binary) Send(sock *goczmq.Sock) (err error) {
	frame, err := b.Marshal()
	if err != nil {
		return err
	}

	socType := sock.GetType()
	if err != nil {
		return err
	}

	// If we're sending to a ROUTER, we send the routingID first
	if socType == goczmq.Router {
		err = sock.SendFrame(b.routingID, goczmq.FlagMore)
		if err != nil {
			return err
		}
	}

	// Now send the data frame
	err = sock.SendFrame(frame, goczmq.FlagMore)
	if err != nil {
		return err
	}
	// Now send any frame fields, in order
	err = sock.SendFrame(b.Address, goczmq.FlagMore)
	err = sock.SendFrame(b.Content, 0)

	return err
}
Exemple #3
0
// recv receives marshaled data from 0mq socket.
func recv(sock *goczmq.Sock, flag int) (t Transit, err error) {
	var frames [][]byte

	if flag == goczmq.FlagDontWait {
		frames, err = sock.RecvMessageNoWait()
	} else {
		frames, err = sock.RecvMessage()
	}

	if err != nil {
		return nil, err
	}

	sType := sock.GetType()
	if err != nil {
		return nil, err
	}

	var routingID []byte
	// If message came from a router socket, first frame is routingID
	if sType == goczmq.Router {
		if len(frames) <= 1 {
			return nil, errors.New("no routingID")
		}
		routingID = frames[0]
		frames = frames[1:]
	}

	t, err = Unmarshal(frames...)
	if err != nil {
		return nil, err
	}

	if sType == goczmq.Router {
		t.SetRoutingID(routingID)
	}
	return t, err
}