def add_serializers(self, struct, indent): # Adhers to the packer interface fn = Function() fn.name = 'pack' fn.ret = 'void' fn.qual = 'throws IOException' arg = Variable() arg.name = 'out' arg.type = 'LittleEndianDataOutputStream' fn.args.append(arg) fn.body = self.gen_serializer_body(struct, indent) struct.methods.append(fn) fn = Function() fn.name = 'unpack' fn.ret = 'void' fn.qual = 'throws IOException' arg = Variable() arg.name = 'in' arg.type = 'LittleEndianDataInputStream' fn.args.append(arg) fn.body = self.gen_deserializer_body(struct, indent) struct.methods.append(fn)
def create_messages(xmlroot, gen, prefix, folder = ''): structs = [] for node in xmlroot.findall('struct'): structs.append(Structure(node)) for struct in structs: gen.packable_types.append(struct.name) for s in structs: '''Add automatic inheritance and virtual method implementations''' s.inherit = 'SeatracMessage' #Ptr typedef t = ('boost::shared_ptr< ' + s.name +' > ', 'Ptr') s.typedefs.append(t) t = ('boost::shared_ptr< ' + s.name +' const > ', 'ConstPtr') s.typedefs.append(t) #get_cid function f = Function() f.name = 'getCid' f.ret = 'int' f.body = 'return ' + s.name + '::CID;' f.inline = True f.qual = 'const' s.methods.append(f) #Test message type f = Function() f.name = 'isCommand' f.ret = 'bool' if prefix == "command": f.body = 'return true;' else: f.body = 'return false;' f.qual = 'const' s.methods.append(f) filebase = folder + '/' + prefix cmi = open(filebase + '_factory_initializer.h','w') cmi.write(gen_factory_initializer(structs)) cmi.close() cmi = open(filebase + '_names.h','w') cmi.write(gen_names(structs)) cmi.close() smsg = open(filebase + '_defs.h','w') smsgimpl = open(filebase + '_impl.h','w') for struct in structs: smsg.write(gen.gen_header(struct)) smsg.write('\n\n') smsgimpl.write(gen.gen_impl(struct, serialization=False)) smsgimpl.write('\n\n') smsg.close() return structs
def add_serializers(self, struct, indent): # Adhers to the packer interface fn = Function() fn.name = 'pack' fn.inline = None fn.ret = 'void' fn.qual = 'const' arg = Variable() arg.name = 'out' arg.type = 'boost::archive::binary_oarchive&' fn.args.append(arg) fn.body = self.gen_serializer_body(struct, indent) struct.methods.append(fn) fn = Function() fn.name = 'unpack' fn.ret = 'void' fn.qual = '' arg = Variable() arg.name = 'in' arg.type = 'boost::archive::binary_iarchive&' fn.args.append(arg) fn.body = self.gen_deserializer_body(struct, indent) struct.methods.append(fn)
def create_messages(xmlroot, gen, prefix, folder=''): structs = [] for node in xmlroot.findall('struct'): structs.append(Structure(node)) for struct in structs: gen.packable_types.append(struct.name) for s in structs: '''Add automatic inheritance and virtual method implementations''' s.inherit = 'SeatracMessage' #Ptr typedef t = ('boost::shared_ptr< ' + s.name + ' > ', 'Ptr') s.typedefs.append(t) t = ('boost::shared_ptr< ' + s.name + ' const > ', 'ConstPtr') s.typedefs.append(t) #get_cid function f = Function() f.name = 'getCid' f.ret = 'int' f.body = 'return ' + s.name + '::CID;' f.inline = True f.qual = 'const' s.methods.append(f) #Test message type f = Function() f.name = 'isCommand' f.ret = 'bool' if prefix == "command": f.body = 'return true;' else: f.body = 'return false;' f.qual = 'const' s.methods.append(f) filebase = folder + '/' + prefix cmi = open(filebase + '_factory_initializer.h', 'w') cmi.write(gen_factory_initializer(structs)) cmi.close() cmi = open(filebase + '_names.h', 'w') cmi.write(gen_names(structs)) cmi.close() smsg = open(filebase + '_defs.h', 'w') smsgimpl = open(filebase + '_impl.h', 'w') for struct in structs: smsg.write(gen.gen_header(struct)) smsg.write('\n\n') smsgimpl.write(gen.gen_impl(struct, serialization=False)) smsgimpl.write('\n\n') smsg.close() return structs