本文整理匯總了Golang中C.zmq_msg_data函數的典型用法代碼示例。如果您正苦於以下問題:Golang zmq_msg_data函數的具體用法?Golang zmq_msg_data怎麽用?Golang zmq_msg_data使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了zmq_msg_data函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RecvBytes
/*
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
}
示例2: RecvBytesWithMetadata
/*
Receive a message part with metadata.
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-1: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) {
if !soc.opened {
return []byte{}, map[string]string{}, ErrorSocketClosed
}
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.zmq4_memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), C.size_t(size))
}
if 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
}
示例3: Recv
// Receive a message from the socket.
// int zmq_recv (void *s, zmq_msg_t *msg, int flags);
func (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) {
// Allocate and initialise a new zmq_msg_t
var m C.zmq_msg_t
var rc C.int
if rc, err = C.zmq_msg_init(&m); rc != 0 {
err = casterr(err)
return
}
defer C.zmq_msg_close(&m)
// Receive into message
if rc, err = C.zmq_recvmsg(s.s, &m, C.int(flags)); rc == -1 {
err = casterr(err)
return
}
err = nil
// Copy message data into a byte array
// FIXME Ideally this wouldn't require a copy.
size := C.zmq_msg_size(&m)
if size > 0 {
data = make([]byte, int(size))
C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), size)
} else {
data = nil
}
return
}
示例4: Recv
// Receive a message from the socket.
// int zmq_recv (void *s, zmq_msg_t *msg, int flags);
func (s *zmqSocket) Recv(flags SendRecvOption) (data []byte, err error) {
// Allocate and initialise a new zmq_msg_t
err = nil
var m C.zmq_msg_t
if C.zmq_msg_init(&m) != 0 {
println("init")
err = errno()
return
}
defer C.zmq_msg_close(&m)
// Receive into message
if C.zmq_recvmsg(s.s, &m, C.int(flags)) != 0 {
println("recvmsg")
err = errno()
return
}
// Copy message data into a byte array
// FIXME Ideally this wouldn't require a copy.
size := C.zmq_msg_size(&m)
if size > 0 {
data = make([]byte, int(size))
C.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&m), size)
} else {
data = nil
}
return
}
示例5: RecvEvent
func (s *Socket) RecvEvent(flags SendRecvOption) (ty Event, addr string, ex int64, err error) {
// Allocate and initialise a new zmq_msg_t
var m C.zmq_msg_t
var rc C.int
if rc, err = C.zmq_msg_init(&m); rc != 0 {
err = casterr(err)
return
}
defer C.zmq_msg_close(&m)
// Receive into message
if rc, err = C.zmq_recvmsg(s.s, &m, C.int(flags)); rc == -1 {
err = casterr(err)
return
}
var ev *C.zmq_event_t
size := C.zmq_msg_size(&m)
if uintptr(size) != unsafe.Sizeof(*ev) {
err = errors.New("Invalid event message received")
return
}
err = nil
ev = (*C.zmq_event_t)(C.zmq_msg_data(&m))
ty = Event(ev.event)
addr = C.GoString(C.ev_get_addr(ev))
ex = int64(C.ev_get_extra(ev))
return
}
示例6: RecvBytes
/*
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.memcpy(unsafe.Pointer(&data[0]), C.zmq_msg_data(&msg), C.size_t(size))
return data, nil
}
示例7: Send
// Send a message to the socket.
// int zmq_send (void *s, zmq_msg_t *msg, int flags);
func (s *zmqSocket) Send(data []byte, flags SendRecvOption) error {
var m C.zmq_msg_t
// Copy data array into C-allocated buffer.
size := C.size_t(len(data))
if C.zmq_msg_init_size(&m, size) != 0 {
return errno()
}
if size > 0 {
// FIXME Ideally this wouldn't require a copy.
C.memcpy(unsafe.Pointer(C.zmq_msg_data(&m)), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)
}
if C.zmq_sendmsg(s.s, &m, C.int(flags)) != 0 {
// zmq_send did not take ownership, free message
C.zmq_msg_close(&m)
return errno()
}
return nil
}
示例8: fromMsg
func fromMsg(msg *C.zmq_msg_t) []byte {
defer C.zmq_msg_close(msg)
return C.GoBytes(C.zmq_msg_data(msg), C.int(C.zmq_msg_size(msg)))
}
示例9: toMsg
func toMsg(msg *C.zmq_msg_t, data []byte) {
C.zmq_msg_init_size(msg, C.size_t(len(data)))
if len(data) > 0 {
C.memcpy(C.zmq_msg_data(msg), unsafe.Pointer(&data[0]), C.size_t(len(data)))
}
}
示例10: MessageData
func MessageData(message ZMessage) ZMessageData {
return ZMessageData{C.zmq_msg_data(message.Ptr)}
}
示例11: data
func (p *lzmqMessage) data() uintptr {
return uintptr(C.zmq_msg_data(p.ptr()))
}