Class DapPacker
source code
object --+
|
DapPacker
Pack variable data into XDR.
This is a faster reimplementation of xdrlib using the native module
"array".
>>> from dap.dtypes import *
>>> dapvar = BaseType(data=1, type='Int32')
>>> xdrdata = DapPacker(dapvar)
>>> for i in xdrdata:
... print repr(i)
'\x00\x00\x00\x01'
>>> dapvar = ArrayType(data=['one', 'two'], shape=[2], type='String')
>>> xdrdata = DapPacker(dapvar)
>>> for i in xdrdata:
... print repr(i)
'\x00\x00\x00\x02'
'\x00\x00\x00\x03one\x00'
'\x00\x00\x00\x03two\x00'
>>> dapvar = ArrayType(data=range(2), shape=[2], type='Int32')
>>> xdrdata = DapPacker(dapvar)
>>> for i in xdrdata:
... print repr(i)
'\x00\x00\x00\x02\x00\x00\x00\x02'
'\x00\x00\x00\x00\x00\x00\x00\x01'
>>> dapvar = ArrayType(data=range(2), shape=[2], type='Float64')
>>> xdrdata = DapPacker(dapvar)
>>> for i in xdrdata:
... print repr(i)
'\x00\x00\x00\x02\x00\x00\x00\x02'
'\x00\x00\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00'
|
__init__(self,
dapvar,
data=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
|
|
__iter__(self)
Iterate over the XDR encoded data.
|
|
_pack_length(self)
Yield array length.
|
|
_yield_bytes(self)
Yield bytes.
|
|
_pack_string(self,
s)
Pack a string.
|
|
Inherited from object:
__delattr__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__str__
|
|
Inherited from object:
__class__
|
__init__(self,
dapvar,
data=None)
(Constructor)
| source code |
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
-
- Overrides:
object.__init__
- (inherited documentation)
|
Iterate over the XDR encoded data.
-
|
|
Yield bytes.
Bytes are encoded as is, padded to a four-byte boundary. An array of
five bytes, eg, is encoded as eight bytes:
>>> from dap.dtypes import *
>>> dapvar = ArrayType(data=range(5), shape=[5], type='Byte')
>>> xdrdata = DapPacker(dapvar)
>>> for i in xdrdata:
... print repr(i)
'\x00\x00\x00\x05\x00\x00\x00\x05'
'\x00'
'\x01'
'\x02'
'\x03'
'\x04'
'\x00\x00\x00'
Again, the first line correponds to the array size packed twice,
followed by the bytes and the padding.
-
|
|
Pack a string.
We first pack the string length, followed by the string padded to size
4n.
-
|