58 """ Size of object in bytes. Size is contextual by object type. """ 59 return bsObj.__sizeof__()
68 """ RNR Byte Buffer Class. 70 The ByteBuf class provides a wrapper around the byte_t* SWIG object. 71 The byte_t is typedef'ed in C as an unsigned char. Byte buffers are used 72 in packing and unpacking buffers in function calls. 74 Note: There does not seem to be any way to advance the pointer of the 75 underlining byte_t* SWIG object, so a copy from/to a python byte 76 list (buffer) is required. 81 """ Initialize byte buffer instance. 84 size - Number of bytes of the underlining fixed sized SWIG 88 self.
_swigObj = i2ccore.new_byteArray(size)
98 """ Delete byte buffer instance. """ 99 i2ccore.delete_byteArray(self.
_swigObj)
105 """ Conversion constructor. 108 seq - Sequence of values to convert. Sequence type can be an 109 integer [0,255], a string, or a list of elements of 110 type integer, string, list. 113 New initialized ByteBuf(). 115 buf = ByteBuf.bytestring(seq)
116 bytebuf =
ByteBuf(size=len(buf))
123 """ Smart clone constructor. 125 If buf is a ByteBuf instance, then simply return buf. 126 Otherwise convert buf to a ByteBuf instance. 128 The underlining swig object contents are not touched, so swig copies 129 will need to be done prior to or after calling a byte_t* core routine. 132 buf - Either a ByteBuf instance or a sequence of values to convert. 133 Sequence type can be an integer [0,255], a string, or a list 134 of elements of type integer, string, list. 137 Existing or new ByteBuf(). 139 if isinstance(buf, ByteBuf):
142 return ByteBuf.Constructor(buf)
147 """ x.__getitem__(i) <==> x[i] """ 148 return self.buf.__getitem__(i)
153 """ x.__getslice__(i, j) <==> x[i:j] """ 154 return self.buf.__getslice__(i, j)
159 """ x.__iadd__(y) <==> x+=y """ 160 z = ByteBuf.bytestring(y)
167 """ x.__imul__(y) <==> x*=y """ 174 """ x.__iter__() <==> iter(x) """ 175 return self.buf.__iter__()
180 """ x.__len__() <==> len(x) 182 Number of bytes used in buffer. 189 """ x.__str__() <==> str(x) <==> print x """ 190 return self.buf.__str__()
195 """ x.__setitem__(i, y) <==> x[i]=y """ 197 self.buf.__setitem__(i, z)
203 """ x.__setslice__(i, j, y) <==> x[i:j]=y """ 204 z = ByteBuf.bytestring(y)
205 self.buf.__setslice__(i, j, z)
211 """ x.__sizeof__() -- size of swig object byte buffer, in bytes. """ 217 """ Available bytes in fixed swig object buffer. """ 223 """ Copy swig object buffer to python buffer. 226 n - Number of bytes to copy. 227 i - Starting source index in swig object buffer. 228 j - Starting destination index in python buffer. 230 assert i+n <= self.
_size,
"index out of range" 233 self.
buf += chr(0) * (j + n - l)
236 s += chr(i2ccore.byteArray_getitem(self.
_swigObj, i+k))
237 self.
buf = self.
buf[:j] + s
242 """ Copy python buffer to instance swig object buffer. 245 n - Number of bytes to copy. 246 i - Starting source index in python buffer. 247 j - Starting destination index in swig object buffer. 249 assert i+n <= len(self.
buf),
"index out of range" 250 assert j+n <= self.
_size,
"index out of range" 252 i2ccore.byteArray_setitem(self.
_swigObj, j+k, ord(self.
buf[i+k]))
257 """ Return raw swig object. """ 263 """ Return python buffer. """ 269 """ Size of fixed swig object byte buffer, in bytes. """ 276 """ Static method to convert a value into a byte. 279 val - Value to convert. Value type can be an integer [0,255], 280 a string of length 1, or a list of length 1 of element 281 type of integer, string, list. 284 On success, returns converted byte value. 285 On failure, a BotSenseError exception is raised. 288 assert val <= 255,
"integer too big" 290 elif type(val) == str:
291 assert len(val) == 1,
"string too long" 293 elif type(val) == list:
294 assert len(val) == 1,
"too many list eleements" 295 return ByteBuf.byte(val[0])
297 assert 0,
"unsupported type" 303 """ Static method to convert a value sequence into a byte list. 306 seq - Sequence of values to convert. Sequence type can be an 307 integer [0,255], a string, or a list of elements of 308 type integer, string, list. 311 On success, returns converted byte value list. 312 On failure, a BotSenseError exception is raised. 316 elif type(seq) == int:
317 outbuf = [ ByteBuf.byte(seq) ]
319 elif type(seq) == str
or type(seq) == list:
322 outbuf += [ ByteBuf.byte(val) ]
325 assert 0,
"unsupported type" 331 """ Static method to convert a value into a byte character string. 334 val - Value to convert. Value type can be an integer [0,255], 335 a string of length 1, or a list of length 1 of element 336 type of integer, string, list. 339 On success, returns converted byte value. 340 On failure, a BotSenseError exception is raised. 343 assert val <= 255,
"integer too big" 345 elif type(val) == str:
346 assert len(val) == 1,
"string too long" 348 elif type(val) == list:
349 assert len(val) == 1,
"too many list elements" 350 return ByteBuf.bytec(val[0])
352 assert 0,
"unsupported type" 358 """ Static method to convert a value sequence into a byte string. 361 seq - Sequence of values to convert. Sequence type can be an 362 integer [0,255], a string, or a list of elements of 363 type integer, string, list. 366 On success, returns converted byte value list. 367 On failure, a BotSenseError exception is raised. 371 elif type(seq) == int:
372 return ByteBuf.bytec(seq)
373 elif type(seq) == str
or type(seq) == list:
376 outbuf += ByteBuf.bytec(val)
379 assert 0,
"unsupported type" def __init__(self, size=256)
def __setslice__(self, i, j, y)
_size
internal swig object fixed buffer size
def copyToSwigObj(self, n, i=0, j=0)
def __setitem__(self, i, y)
def __getslice__(self, i, j)
def copyFromSwigObj(self, n, i=0, j=0)
RoadNarrows Robotics Swigged Core Python Interface Module.
_swigObj
internal swig object