/* Receive a message part from a socket. For a description of flags, see: http://api.zeromq.org/2-2:zmq-recv#toc2 */ func (soc *Socket) RecvBytes(flags Flag) ([]byte, error) { if !soc.opened { return []byte{}, ErrorSocketClosed } var msg C.zmq_msg_t if i, err := C.zmq_msg_init(&msg); i != 0 { return []byte{}, errget(err) } defer C.zmq_msg_close(&msg) var size C.int var err error var i C.int i, err = C.zmq_recv(soc.soc, &msg, C.int(flags)) if i == 0 { size = C.int(C.zmq_msg_size(&msg)) } else { size = -1 } if size < 0 { return []byte{}, errget(err) } if size == 0 { return []byte{}, nil } data := make([]byte, int(size)) C.my_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&msg), C.size_t(size)) return data, nil }
/* Receive a message part with metadata. Metadata is added to messages that go through the 0MQ security mechanism. Standard metadata properties are: Identity, Socket-Type, User-Id. This requires ZeroMQ version 4.1.0. Lower versions will return the message part without metadata. The returned metadata map contains only those properties that exist on the message. For a description of flags, see: http://api.zeromq.org/4-0:zmq-msg-recv#toc2 For a description of metadata, see: http://api.zeromq.org/4-1:zmq-msg-gets#toc3 */ func (soc *Socket) RecvBytesWithMetadata(flags Flag, properties ...string) (msg []byte, metadata map[string]string, err error) { metadata = make(map[string]string) var m C.zmq_msg_t if i, err := C.zmq_msg_init(&m); i != 0 { return []byte{}, metadata, errget(err) } defer C.zmq_msg_close(&m) size, err := C.zmq_msg_recv(&m, soc.soc, C.int(flags)) if size < 0 { return []byte{}, metadata, errget(err) } data := make([]byte, int(size)) if size > 0 { C.my_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), C.size_t(size)) } if _, minor, _ := Version(); minor > 0 { for _, p := range properties { ps := C.CString(p) s, err := C.zmq_msg_gets(&m, ps) if err == nil { metadata[p] = C.GoString(s) } C.free(unsafe.Pointer(ps)) } } return data, metadata, nil }
/* Receive a message part from a socket. For a description of flags, see: http://api.zeromq.org/3-2:zmq-msg-recv#toc2 */ func (soc *Socket) RecvBytes(flags Flag) ([]byte, error) { var msg C.zmq_msg_t if i, err := C.zmq_msg_init(&msg); i != 0 { return []byte{}, errget(err) } defer C.zmq_msg_close(&msg) size, err := C.zmq_msg_recv(&msg, soc.soc, C.int(flags)) if size < 0 { return []byte{}, errget(err) } if size == 0 { return []byte{}, nil } data := make([]byte, int(size)) C.my_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&msg), C.size_t(size)) return data, nil }