def serialize(self): sb = StringBuffer(16 + self.total_size) sb.pack('<BBHIQ', self.mfs_type, 0, 0, self.entry_no, self.total_size) for symbol in self.symbols: sb.write(symbol.serialize()) sb.seek(0) return sb
def serialize(self): sb = StringBuffer(16 + self.total_size) sb.pack('<BBBBIQ', self.mfs_type, self.ver, self.dims, self.flags, 0, self.total_size) for ds in self.dataspaces: sb.write(ds.serialize()) sb.seek(0) return sb
def serialize(self): sb = StringBuffer(24) sb.pack('<BBH', self.mfs_type, self.mode, self.flags) sb.write(self.sha) sb.seek(0) return sb
def serialize(self): sb = StringBuffer(16 + self.total_size) sb.pack('<BBHHHQ', self.mfs_type, self.ver, self.name_size, self.datatype_size, self.dataspace_size, self.total_size) if self.attr is not None: sb.write(self.attr.serialize()) sb.seek(0) return sb
def serialize(self): sb = StringBuffer(8 + self.symbol_length) sb.pack('<HHI', self.idx, 0, max(len(self.symbol) + 1, self.symbol_length)) # Account for null-terminator sb.write(self.symbol) sb.seek(0) return sb
def serialize(self): sb = StringBuffer(16 + self.total_size) sb.pack('<BBH', self.mfs_type, self.version, self.children) sb.write(self.signature) sb.pack('<Q', self.total_size) for o in self.objects: sb.write(o.serialize()) return sb
def test_write_sb(self): container = StringBuffer(24) el = StringBuffer(16) el.set('hello world') container.write(el) container.seek(0) self.assertEquals(container.read(), 'hello world')
def test_overflow(self): sb = StringBuffer(24) with self.assertRaises(BufferOverflow): sb.write('this string is definitely longer than 24 characters and should raise an error') self.assertRaises(OverflowError, sb.seek, -1) sb = StringBuffer(8) sb.set('01234567') sb.seek(0) buf = sb.raw_read(8) self.assertEquals(buf, '01234567') self.assertRaises(BufferOverflow, sb.raw_read, 1)
def test_buffer(self): sb = StringBuffer(128) sb.write('hello world') sb.seek(0) self.assertEquals(sb.read(), 'hello world') self.assertEquals(sb.offset(), 0) sb.write('jello') self.assertEquals(sb.offset(), 5) sb.seek(0) self.assertEquals(sb.read(), 'jello world') sb.set('hi') self.assertEquals(sb.offset(), 0) self.assertEquals(sb.read(), 'hi') sb = StringBuffer("Hello World") self.assertEquals(sb.read(), 'Hello World') sb = StringBuffer(sb) self.assertEquals(sb.read(), 'Hello World')
def serialize(self): sb = StringBuffer(8 + self.symbol_length) sb.pack('<HHI', self.idx, 0, max(len(self.symbol)+1, self.symbol_length)) # Account for null-terminator sb.write(self.symbol) sb.seek(0) return sb