// Sends marshaled data through 0mq socket. func (g *Goodbye) Send(socket *zmq.Socket) (err error) { frame, err := g.Marshal() if err != nil { return err } socType, err := socket.GetType() if err != nil { return err } // If we're sending to a ROUTER, we send the routingId first if socType == zmq.ROUTER { _, err = socket.SendBytes(g.routingId, zmq.SNDMORE) if err != nil { return err } } // Now send the data frame _, err = socket.SendBytes(frame, 0) if err != nil { return err } return err }
// Sends marshaled data through 0mq socket. func (d *Deliver) Send(socket *zmq.Socket) (err error) { frame, err := d.Marshal() if err != nil { return err } socType, err := socket.GetType() if err != nil { return err } // If we're sending to a ROUTER, we send the routingId first if socType == zmq.ROUTER { _, err = socket.SendBytes(d.routingId, zmq.SNDMORE) if err != nil { return err } } // Now send the data frame _, err = socket.SendBytes(frame, zmq.SNDMORE) if err != nil { return err } // Now send any frame fields, in order _, err = socket.SendBytes(d.Content, 0) return err }
// Send sends marshaled data through 0mq socket. func (b *Binary) Send(socket *zmq.Socket) (err error) { frame, err := b.Marshal() if err != nil { return err } socType, err := socket.GetType() if err != nil { return err } // If we're sending to a ROUTER, we send the routingID first if socType == zmq.ROUTER { _, err = socket.SendBytes(b.routingID, zmq.SNDMORE) if err != nil { return err } } // Now send the data frame _, err = socket.SendBytes(frame, zmq.SNDMORE) if err != nil { return err } // Now send any frame fields, in order _, err = socket.SendBytes(b.Address, zmq.SNDMORE) _, err = socket.SendBytes(b.Content, 0) return err }
// Receives marshaled data from 0mq socket. func recv(socket *zmq.Socket, flag zmq.Flag) (t Transit, err error) { // Read all frames frames, err := socket.RecvMessageBytes(flag) if err != nil { return nil, err } sType, err := socket.GetType() if err != nil { return nil, err } var routingId []byte // If message came from a router socket, first frame is routingId if sType == zmq.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 == zmq.ROUTER { t.SetRoutingId(routingId) } return t, err }