示例#1
0
def test_zmsg():
    m = zmsg.new()
    foo = zframe.new('foo')
    zmsg.push(m, foo)
    assert zmsg.first(m) == foo
    bar = zframe.new('bar')
    zmsg.push(m, bar)
    assert zmsg.first(m) == bar
    assert zmsg.last(m) == foo
    zmsg.append(m, zframe.new('ding'))
    assert zframe.data(zmsg.last(m)) == 'ding'

    ctx = zctx.new()
    p = zsocket.new(ctx, zmq.PUB)
    u = zsocket.new(ctx, zmq.SUB)
    zsockopt.set_subscribe(u, '')
    zsocket.bind(p, 'inproc://qer')
    zsocket.connect(u, 'inproc://qer')
    zmsg.send(m, p)
    zsocket.poll(u, 1)
    n = zmsg.recv(u)
    assert zmsg.size(n) == 3
    assert zframe.data(zmsg.next(n)) == 'bar'
    assert zframe.data(zmsg.next(n)) == 'foo'
    assert zframe.data(zmsg.next(n)) == 'ding'
    assert zmsg.next(n) is None
示例#2
0
文件: test_zmsg.py 项目: minrk/pyczmq
def test_zmsg():
    m = zmsg.new()
    foo = zframe.new('foo')
    zmsg.push(m, foo)
    assert zmsg.first(m) == foo
    bar = zframe.new('bar')
    zmsg.push(m, bar)
    assert zmsg.first(m) == bar
    assert zmsg.last(m) == foo
    zmsg.append(m, zframe.new('ding'))

    # dup and mutate the buffer view
    d = zframe.dup(zmsg.last(m))
    assert zframe.data(d)[:] == 'ding'
    zframe.data(d)[1] = 'o'
    assert zframe.data(d)[:] == 'dong'
    assert zframe.size(d) == 4
    zmsg.append(m, d)

    ctx = zctx.new()
    p = zsocket.new(ctx, zmq.PUB)
    u = zsocket.new(ctx, zmq.SUB)
    zsocket.set_subscribe(u, '')
    zsocket.bind(p, 'inproc://qer')
    zsocket.connect(u, 'inproc://qer')
    zmsg.send(m, p)
    zsocket.poll(u, 1)
    n = zmsg.recv(u)
    assert zmsg.size(n) == 4
    assert zframe.data(zmsg.next(n))[:] == 'bar'
    assert zframe.data(zmsg.next(n))[:] == 'foo'
    assert zframe.data(zmsg.next(n))[:] == 'ding'
    assert zframe.data(zmsg.next(n))[:] == 'dong'
    assert zmsg.next(n) is None

    zmsg.destroy(n)
示例#3
0
 def append(self, frame):
     if isinstance(frame, str):
         return zmsg.addstr(self.msg, frame)
     if isinstance(frame, Frame):
         frame = frame.frame
     return zmsg.append(self.msg, frame)
示例#4
0
文件: types.py 项目: zeromq/pyczmq
 def append(self, frame):
     if isinstance(frame, str):
         return zmsg.addstr(self.msg, frame)
     if isinstance(frame, Frame):
         frame = frame.frame
     return zmsg.append(self.msg, frame)