Ejemplo n.º 1
0
	def _set_set_get(self):
		self._str_set = ''
		self._str_get = ''
		self._str_set_get = ''
		for mess_field in self._proto['mess_fields']:
			field_op 			= mess_field['field_op']
			field_name 			= mess_field['field_name']
			field_name_camel 	= tool.underline_to_camel(field_name)
			field_name_upper	= field_name_camel
			field_name_camel 	= field_name_camel[:1].lower() + field_name_camel[1:]
			field_name_var 		= '$' + field_name_camel
			field_name_flag 	= '$this->' + field_name_camel + 'Flag'
			field_name_this 	= '$this->' + field_name_camel

			str_set = ''
			str_get = ''

			str_set += '\tpublic function set' + field_name_upper + '(' + field_name_var + ')\n\t{\n'
			if field_op == 'optional':
				str_set += '\t\t' + field_name_flag + ' = 1;\n'
			str_set += '\t\t'  + field_name_this + ' = ' + field_name_var + ';\n\t}\n'
			str_get += '\tpublic function get' + field_name_upper + '()\n\t{\n\t\treturn ' + field_name_this + ';\n\t}\n'

			self._str_set 		+= str_set + '\n'
			self._str_get 		+= str_get + '\n'
			self._str_set_get 	+= str_set + str_get + '\n'

		self._str_set = self._str_set[:-1]
		self._str_get = self._str_get[:-1]
		self._str_set_get = self._str_set_get[:-1]
Ejemplo n.º 2
0
 def _set_proto_decode(self):
     self._str_decode = 'func ' + self._str_class_name + 'Decode(pack *packet.Packet) *' + self._str_class_name + ' {\n'
     self._str_decode += '\t' + self._str_class_name_var + ' := &' + self._str_class_name + '{}\n\n'
     for mess_field in self._proto['mess_fields']:
         field_op = mess_field['field_op']
         field_type = mess_field['field_type']
         field_type_func = field_type[:1].upper() + field_type[1:]
         field_name_var = tool.underline_to_camel(mess_field['field_name'])
         field_name_mem = field_name_var[:1].lower() + field_name_var[1:]
         field_name_flag = field_name_mem + 'Flag'
         field_name_count = field_name_mem + 'Count'
         if 'required' == field_op:
             if field_type.startswith('Msg'):
                 self._str_decode += '\t' + self._str_class_name_var + '.' + field_name_mem + ' = ' + field_type + 'Decode(pack)\n'
             else:
                 self._str_decode += '\t' + self._str_class_name_var + '.' + field_name_mem + ' = pack.Read' + field_type_func + '()\n'
         elif 'repeated' == field_op:
             self._str_decode += '\t' + field_name_count + ' := pack.ReadUint16()\n'
             self._str_decode += '\tfor ;' + field_name_count + ' > 0; ' + field_name_count + '-- {\n'
             if field_type.startswith('Msg'):
                 self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = append(' + self._str_class_name_var + '.' + field_name_mem + ', ' + field_type + 'Decode(pack))\n'
             else:
                 self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = append(' + self._str_class_name_var + '.' + field_name_mem + ', ' + 'pack.Read' + field_type_func + '())\n'
             self._str_decode += '\t}\n'
         elif 'optional' == field_op:
             self._str_decode += '\t' + self._str_class_name_var + '.' + field_name_flag + ' = pack.ReadUint8()\n'
             self._str_decode += '\tif ' + self._str_class_name_var + '.' + field_name_flag + ' == 1 {\n'
             if field_type.startswith('Msg'):
                 self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = ' + field_type + 'Decode(pack)\n'
             else:
                 self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = pack.Read' + field_type_func + '()\n'
             self._str_decode += '\t}\n'
     self._str_decode += '\treturn ' + self._str_class_name_var + '\n}\n'
Ejemplo n.º 3
0
	def _set_proto_decode(self):
		self._str_decode = 'func ' + self._str_class_name + 'Decode(pack *packet.Packet) *' + self._str_class_name + ' {\n'
		self._str_decode +='\t' + self._str_class_name_var + ' := &' + self._str_class_name + '{}\n\n'
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_type_func = field_type[:1].upper() + field_type[1:]
			field_name_var 	= tool.underline_to_camel(mess_field['field_name'])
			field_name_mem 	= field_name_var[:1].lower() + field_name_var[1:]
			field_name_flag = field_name_mem + 'Flag'
			field_name_count= field_name_mem + 'Count'
			if 'required' == field_op:
				if field_type.startswith('Msg'):
					self._str_decode += '\t' + self._str_class_name_var + '.' + field_name_mem + ' = ' + field_type + 'Decode(pack)\n'
				else:
					self._str_decode += '\t' + self._str_class_name_var + '.' + field_name_mem + ' = pack.Read' + field_type_func + '()\n'
			elif 'repeated' == field_op:
				self._str_decode += '\t' + field_name_count + ' := pack.ReadUint16()\n'
				self._str_decode += '\tfor ;' + field_name_count + ' > 0; ' + field_name_count + '-- {\n'
				if field_type.startswith('Msg'):
					self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = append(' + self._str_class_name_var + '.' + field_name_mem + ', ' + field_type + 'Decode(pack))\n'
				else:
					self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = append(' + self._str_class_name_var + '.' + field_name_mem + ', ' + 'pack.Read' + field_type_func + '())\n'
				self._str_decode += '\t}\n'
			elif 'optional' == field_op:
				self._str_decode += '\t' + self._str_class_name_var + '.' + field_name_flag + ' = pack.ReadUint8()\n'
				self._str_decode += '\tif ' + self._str_class_name_var + '.' + field_name_flag + ' == 1 {\n'
				if field_type.startswith('Msg'):
					self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = ' + field_type + 'Decode(pack)\n'
				else:
					self._str_decode += '\t\t' + self._str_class_name_var + '.' + field_name_mem + ' = pack.Read' + field_type_func + '()\n'
				self._str_decode += '\t}\n'
		self._str_decode += '\treturn ' + self._str_class_name_var + '\n}\n'
Ejemplo n.º 4
0
	def _set_decode(self):
		self._str_decode = '\tpublic function decode(&$packet)\n\t{\n'
		for mess_field in self._proto['mess_fields']:
			field_op 			= mess_field['field_op']
			field_type 			= mess_field['field_type']
			field_type_big 		= field_type.capitalize()
			field_name 			= mess_field['field_name']
			field_name_camel 	= tool.underline_to_camel(field_name)
			field_name_camel 	= field_name_camel[:1].lower() + field_name_camel[1:]
			field_name_flag 	= '$this->' + field_name_camel + 'Flag'
			field_name_count 	= '$' + field_name_camel + 'Count'
			field_name_this 	= '$this->' + field_name_camel
			if field_op == 'repeated':
				self._str_decode += '\t\t' + field_name_count + ' = $packet->readU16();\n'
				self._str_decode += '\t\tfor ($i = 0; $i < ' + field_name_count + '; $i++)\n\t\t{\n'
				if field_type.startswith('Msg'):
					self._str_decode += '\t\t\t' + 'array_push(' + field_name_this + ', new ' + field_type + '($packet));\n'
				else:
					self._str_decode += '\t\t\t' + 'array_push(' + field_name_this + ', $packet->read' + field_type_big + '());\n'
				self._str_decode += '\t\t}\n'
			elif field_op == 'optional':
				self._str_decode += '\t\t' + field_name_flag + ' = $packet->readU8();\n'
				self._str_decode += '\t\tif (' + field_name_flag + ' == 1)\n'
				self._str_decode += '\t\t{\n'
				if field_type.startswith('M'):
					self._str_decode += '\t\t\t' + field_name_this + ' = new ' + field_type + '($packet);\n'
				else:
					self._str_decode += '\t\t\t' + field_name_this + ' = ' + '$packet->read' + field_type_big + '();\n'
				self._str_decode += '\t\t}\n'
			else:
				if field_type.startswith('M'):
					self._str_decode += '\t\t' + field_name_this + ' = new ' + field_type + '($packet);\n'
				else:
					self._str_decode += '\t\t' + field_name_this + ' = $packet->read' + field_type_big + '();\n'
		self._str_decode += '\t}\n'
Ejemplo n.º 5
0
 def _set_type_struct(self):
     self._str_type_struct = 'type ' + self._str_class_name + ' struct {\n'
     for mess_field in self._proto['mess_fields']:
         field_op = mess_field['field_op']
         field_type = mess_field['field_type']
         field_name = mess_field['field_name']
         field_name_var = tool.underline_to_camel(field_name)
         field_name_mem = field_name_var[:1].lower() + field_name_var[1:]
         field_name_flag = field_name_mem + 'Flag'
         if 'required' == field_op:
             if field_type.startswith('Msg'):
                 self._str_type_struct += '\t' + field_name_mem.ljust(
                     25, chr(32)) + '*' + field_type + '\n'
             else:
                 self._str_type_struct += '\t' + field_name_mem.ljust(
                     25, chr(32)) + field_type + '\n'
         elif 'repeated' == field_op:
             if field_type.startswith('Msg'):
                 self._str_type_struct += '\t' + field_name_mem.ljust(
                     25, chr(32)) + '[]*' + field_type + '\n'
             else:
                 self._str_type_struct += '\t' + field_name_mem.ljust(
                     25, chr(32)) + '[]' + field_type + '\n'
         elif 'optional' == field_op:
             self._str_type_struct += '\t' + field_name_flag.ljust(
                 25, chr(32)) + 'uint8\n'
             if field_type.startswith('Msg'):
                 self._str_type_struct += '\t' + field_name_mem.ljust(
                     25, chr(32)) + '*' + field_type + '\n'
             else:
                 self._str_type_struct += '\t' + field_name_mem.ljust(
                     25, chr(32)) + field_type + '\n'
     self._str_type_struct += '}\n'
Ejemplo n.º 6
0
	def _set_type_struct(self):
		self._str_type_struct = 'type ' + self._str_class_name + ' struct {\n'
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_name 		= mess_field['field_name']
			field_name_var	= tool.underline_to_camel(field_name)
			field_name_mem	= field_name_var[:1].lower() + field_name_var[1:]
			field_name_flag = field_name_mem + 'Flag'
			if 'required' == field_op:
				if field_type.startswith('Msg'):
					self._str_type_struct += '\t' + field_name_mem.ljust(25, chr(32)) + '*' + field_type + '\n'
				else:
					self._str_type_struct += '\t' + field_name_mem.ljust(25, chr(32)) + field_type + '\n'
			elif 'repeated' == field_op:
				if field_type.startswith('Msg'):
					self._str_type_struct += '\t' + field_name_mem.ljust(25, chr(32)) + '[]*' + field_type + '\n'
				else:
					self._str_type_struct += '\t' + field_name_mem.ljust(25, chr(32)) + '[]' + field_type + '\n'
			elif 'optional' == field_op:
				self._str_type_struct += '\t' + field_name_flag.ljust(25, chr(32)) + 'uint8\n'
				if field_type.startswith('Msg'):
					self._str_type_struct += '\t' + field_name_mem.ljust(25, chr(32)) + '*' + field_type + '\n'
				else:
					self._str_type_struct += '\t' + field_name_mem.ljust(25, chr(32)) + field_type + '\n'
		self._str_type_struct += '}\n'
Ejemplo n.º 7
0
	def _set_encode(self):
		self._str_encode = ''
		_str_tmp = ''
		for mess_field in self._proto['mess_fields']:
			field_name      = mess_field['field_name']
			field_var_name 	= tool.underline_to_camel(field_name)
			_str_tmp += field_name + '=' + field_var_name + ','

		self._str_encode = '#' + self._str_record_name + '{' + _str_tmp[:-1] + '}'
Ejemplo n.º 8
0
	def _set_set_get(self):
		self._str_set 		= ''
		self._str_get 		= ''
		self._str_set_get 	= ''
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_type_real	= field_type
			is_real			= True
			if not isinstance(field_type, basestring):
				field_type_real			= mess_field['field_type'][0]
				field_type_return		= mess_field['field_type'][1]
				field_type_return_big 	= field_type_return.capitalize()
				is_real					= False
			field_type_big 	= field_type_real.capitalize()
			if not isinstance(field_type, basestring):
				field_type 	= mess_field['field_type'][0]
			field_name 		= mess_field['field_name']
			field_name_flag = field_name + '_flag'
			field_name_func	= tool.underline_to_camel(field_name)

			str_set = ''
			str_get = ''

			if field_op == 'repeated':
				str_set += '\tpublic void set' + field_name_func + '(List<' + field_type_big + '> ' + field_name + ')\n\t{\n\t\tthis.' + field_name + ' = ' + field_name + ';\n\t}\n'

				str_get += '\tpublic List<' + field_type_big + '> get' + field_name_func + '()\n\t{\n\t\treturn this.' + field_name + ';\n\t}\n'
			elif field_op == 'optional':
				str_set += '\tpublic void set' + field_name_func + '(' + field_type + ' ' + field_name + ')\n\t{\n'
				str_set += '\t\tthis.' + field_name_flag + ' = (byte)1;\n'
				str_set += '\t\tthis.' + field_name + ' = ' + field_name + ';\n\t}\n'

				if is_real:
					str_get += '\tpublic ' + field_type_real + ' get' + field_name_func + '()\n\t{\n\t\treturn this.' + field_name + ';\n\t}\n'
				else:
					str_get += '\tpublic ' + field_type_return + ' get' + field_name_func + '()\n\t{\n'
					str_get += '\t\treturn PacketUtil.readU' + field_type_big + '(this.' + field_name + ');\n\t}\n'
			else:
				str_set += '\tpublic void set' + field_name_func + '(' + field_type + ' ' + field_name + ')\n\t{\n\t\tthis.' + field_name + ' = ' + field_name + ';\n\t}\n'

				if is_real:
					str_get += '\tpublic ' + field_type_real + ' get' + field_name_func + '()\n\t{\n\t\treturn this.' + field_name + ';\n\t}\n'
				else:
					str_get += '\tpublic ' + field_type_return + ' get' + field_name_func + '()\n\t{\n'
					str_get += '\t\treturn PacketUtil.readU' + field_type_big + '(this.' + field_name + ');\n\t}\n'

			self._str_set 		+= '\n' + str_set
			self._str_get 		+= '\n' + str_get
			self._str_set_get 	+= '\n' + str_set + str_get
Ejemplo n.º 9
0
    def _set_set_get(self):
        self._str_set = ''
        self._str_get = ''
        self._str_set_get = ''

        for mess_field in self._proto['mess_fields']:
            field_op = mess_field['field_op']
            field_type = mess_field['field_type']
            field_name = mess_field['field_name']
            field_name_big = tool.underline_to_camel(field_name)
            field_name_m = 'm_' + field_name
            field_name_flag = field_name_m + '_flag'

            str_set = ''
            str_get = ''

            if field_op == 'repeated':
                if field_type.startswith('Msg'):
                    str_set += '\tvoid Set' + field_name_big + '(list<' + field_type + '*> ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

                    str_get += '\tlist<' + field_type + '*> Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
                else:
                    str_set += '\tvoid Set' + field_name_big + '(list<' + field_type + '> ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

                    str_get += '\tlist<' + field_type + '> Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
            elif field_op == 'optional':
                if field_type.startswith('Msg'):
                    str_set += '\tvoid Set' + field_name_big + '(' + field_type + '* ' + field_name + ')\n\t{\n'

                    str_get += '\t' + field_type + '* Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
                else:
                    str_set += '\tvoid Set' + field_name_big + '(' + field_type + ' ' + field_name + ')\n\t{\n'

                    str_get += '\t' + field_type + ' Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
                str_set += '\t\t' + field_name_flag + ' = 1;\n'
                str_set += '\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'
            else:
                if field_type.startswith('Msg'):
                    str_set += '\tvoid Set' + field_name_big + '(' + field_type + '* ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

                    str_get += '\t' + field_type + '* Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
                else:
                    str_set += '\tvoid Set' + field_name_big + '(' + field_type + ' ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

                    str_get += '\t' + field_type + ' Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'

            self._str_set += str_set + '\n'
            self._str_get += str_get + '\n'
            self._str_set_get += str_set + str_get + '\n'
Ejemplo n.º 10
0
	def _set_set_get(self):
		self._str_set 		= ''
		self._str_get 		= ''
		self._str_set_get	= ''

		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_name 		= mess_field['field_name']
			field_name_big	= tool.underline_to_camel(field_name)
			field_name_m 	= 'm_' + field_name
			field_name_flag = field_name_m + '_flag'

			str_set 	= ''
			str_get 	= ''

			if field_op == 'repeated':
				if field_type.startswith('Msg'):
					str_set += '\tvoid Set' + field_name_big + '(list<' + field_type + '*> ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

					str_get += '\tlist<' + field_type + '*> Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
				else:
					str_set += '\tvoid Set' + field_name_big + '(list<' + field_type + '> ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

					str_get += '\tlist<' + field_type + '> Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
			elif field_op == 'optional':
				if field_type.startswith('Msg'):
					str_set += '\tvoid Set' + field_name_big + '(' + field_type + '* ' + field_name + ')\n\t{\n'

					str_get += '\t' + field_type + '* Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
				else:
					str_set += '\tvoid Set' + field_name_big + '(' + field_type + ' ' + field_name + ')\n\t{\n'

					str_get += '\t' + field_type + ' Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
				str_set += '\t\t' + field_name_flag + ' = 1;\n'
				str_set += '\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'
			else:
				if field_type.startswith('Msg'):
					str_set += '\tvoid Set' + field_name_big + '(' + field_type + '* ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

					str_get += '\t' + field_type + '* Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'
				else:
					str_set += '\tvoid Set' + field_name_big + '(' + field_type + ' ' + field_name + ')\n\t{\n\t\t' + field_name_m + ' = ' + field_name + ';\n\t}\n'

					str_get += '\t' + field_type + ' Get' + field_name_big + '()\n\t{\n\t\treturn ' + field_name_m + ';\n\t}\n'

			self._str_set 		+= str_set + '\n'
			self._str_get 		+= str_get + '\n'
			self._str_set_get 	+= str_set + str_get + '\n'
Ejemplo n.º 11
0
	def _set_priv_var(self):
		self._str_priv_var = 'class ' + self._str_class_name + '\n{\n'
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_name 		= mess_field['field_name']
			field_name_camel= tool.underline_to_camel(field_name)
			field_name_var	= field_name_camel[:1].lower() + field_name_camel[1:]
			field_name_flag = field_name_var + 'Flag'

			if field_op == 'optional':
				self._str_priv_var += '\tprivate $' + field_name_flag + ' = 0;\n'

			default_value	= self.__set_default_value(field_op, field_type)

			self._str_priv_var += '\tprivate $' + field_name_var + ' = ' + default_value + ';\n'
Ejemplo n.º 12
0
	def _set_encode(self):
		self._str_encode = '\tpublic function encode()\n\t{\n\t\t$packet = new Packet();\n'
		for mess_field in self._proto['mess_fields']:
			field_op 			= mess_field['field_op']
			field_type 			= mess_field['field_type']
			field_type_big		= field_type.capitalize()
			field_name 			= mess_field['field_name']
			field_name_camel 	= tool.underline_to_camel(field_name)
			field_name_camel	= field_name_camel[:1].lower() + field_name_camel[1:]
			field_name_var 		= '$' + field_name_camel
			field_name_flag 	= '$this->' + field_name_camel + 'Flag'
			field_name_count	= '$' + field_name_camel + 'Count'
			field_name_this 	= '$this->' + field_name_camel
			if field_op == 'repeated':
				self._str_encode += '\t\t' + field_name_count + ' = count(' + field_name_this + ');\n'
				self._str_encode += '\t\t$packet->writeU16(' + field_name_count + ');\n'
				self._str_encode += '\t\tforeach (' + field_name_this + ' as ' + field_name_var + ')\n\t\t{\n'
				if field_type.startswith('Msg'):
					self._str_encode += '\t\t\t$packet->writeBytes(' + field_name_var + '->getBytes());\n\t\t}\n'
				else:
					self._str_encode += '\t\t\t$packet->write' + field_type_big + '(' + field_name_var + ');\n\t\t}\n'
			elif field_op == 'optional':
				self._str_encode += '\t\t$packet->writeU8(' + field_name_flag + ');\n'
				if field_type.startswith('M'):
					self._str_encode += '\t\tif (' + field_name_flag + ' == 1)\n\t\t{\n'
					self._str_encode += '\t\t\t$packet->writeBytes(' + field_name_this + '->getBytes());\n\t\t}\n'
				else:
					self._str_encode += '\t\tif (' + field_name_flag + ' == 1)\n\t\t{\n'
					self._str_encode += '\t\t\t$packet->write' + field_type_big + '(' + field_name_this + ');\n\t\t}\n'
			else:
				if field_type.startswith('M'):
					self._str_encode += '\t\t$packet->writeBytes(' + field_name_this + '->getBytes());\n'
				else:
					self._str_encode += '\t\t$packet->write' + field_type_big + '(' + field_name_this + ');\n'
		if self._mess_name.startswith('Msg'):
			self._str_encode += '\t\treturn $packet->readBytes();\n'
		else:
			self._str_encode += '\t\treturn $packet->encode(' + 'Msg::$' + self._str_msg_name + ');\n'
		self._str_encode += '\t}\n'
Ejemplo n.º 13
0
    def _set_proto_encode(self):
        self._str_encode = 'func (this *' + self._str_class_name + ') Encode() []byte {\n'
        self._str_encode += '\t' + 'pack := packet.NewWriteBuff(64)\n\n'
        for mess_field in self._proto['mess_fields']:
            field_op = mess_field['field_op']
            field_type = mess_field['field_type']
            field_type_func = field_type[:1].upper() + field_type[1:]
            field_name_var = tool.underline_to_camel(mess_field['field_name'])
            field_name_mem = field_name_var[:1].lower() + field_name_var[1:]
            field_name_flag = field_name_mem + 'Flag'
            field_name_count = field_name_mem + 'Count'
            if 'required' == field_op:
                if field_type.startswith('Msg'):
                    self._str_encode += '\t' + 'pack.WriteBytes(this.' + field_name_mem + '.Encode())\n'
                else:
                    self._str_encode += '\t' + 'pack.Write' + field_type_func + '(this.' + field_name_mem + ')\n'
            elif 'repeated' == field_op:
                self._str_encode += '\t' + field_name_count + ' := uint16(len(this.' + field_name_mem + '))\n'
                self._str_encode += '\t' + 'pack.WriteUint16(' + field_name_count + ')\n'
                self._str_encode += '\tfor i := uint16(0); i < ' + field_name_count + '; i++ {\n'
                if field_type.startswith('Msg'):
                    self._str_encode += '\t\t' + 'pack.WriteBytes(this.' + field_name_mem + '[i].Encode())\n'
                else:
                    self._str_encode += '\t\t' + 'pack.Write' + field_type_func + '(this.' + field_name_mem + '[i])\n'
                self._str_encode += '\t}\n'
            elif 'optional' == field_op:
                self._str_encode += '\t' + 'pack.WriteUint8(this.' + field_name_flag + ')\n'
                self._str_encode += '\tif this.' + field_name_flag + ' == 1 {\n'
                if field_type.startswith('Msg'):
                    self._str_encode += '\t\t' + 'pack.WriteBytes(this.' + field_name_mem + '.Encode())\n'
                else:
                    self._str_encode += '\t\t' + 'pack.Write' + field_type_func + '(this.' + field_name_mem + ')\n'
                self._str_encode += '\t}\n'

        if self._mess_name.startswith('Msg'):
            self._str_encode += '\n\treturn pack.ReadBytes()\n}\n'
        else:
            self._str_encode += '\n\treturn pack.Encode(' + tool.golang_proto_name_msg(
                self._mess_name) + ')\n}\n'
Ejemplo n.º 14
0
	def _set_proto_encode(self):
		self._str_encode = 'func (this *' + self._str_class_name + ') Encode() []byte {\n'
		self._str_encode += '\t' + 'pack := packet.NewWriteBuff(64)\n\n'
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_type_func = field_type[:1].upper() + field_type[1:]
			field_name_var 	= tool.underline_to_camel(mess_field['field_name'])
			field_name_mem 	= field_name_var[:1].lower() + field_name_var[1:]
			field_name_flag = field_name_mem + 'Flag'
			field_name_count= field_name_mem + 'Count'
			if 'required' == field_op:
				if field_type.startswith('Msg'):
					self._str_encode += '\t' + 'pack.WriteBytes(this.' + field_name_mem + '.Encode())\n'
				else:
					self._str_encode += '\t' + 'pack.Write' + field_type_func + '(this.' + field_name_mem + ')\n'
			elif 'repeated' == field_op:
				self._str_encode += '\t' + field_name_count + ' := uint16(len(this.' + field_name_mem + '))\n'
				self._str_encode += '\t' + 'pack.WriteUint16(' + field_name_count + ')\n'
				self._str_encode += '\tfor i := uint16(0); i < ' + field_name_count + '; i++ {\n'
				if field_type.startswith('Msg'):
					self._str_encode += '\t\t' + 'pack.WriteBytes(this.' + field_name_mem + '[i].Encode())\n'
				else:
					self._str_encode += '\t\t' + 'pack.Write' + field_type_func + '(this.' + field_name_mem + '[i])\n'
				self._str_encode += '\t}\n'
			elif 'optional' == field_op:
				self._str_encode += '\t' + 'pack.WriteUint8(this.' + field_name_flag + ')\n'
				self._str_encode += '\tif this.' + field_name_flag + ' == 1 {\n'
				if field_type.startswith('Msg'):
					self._str_encode += '\t\t' + 'pack.WriteBytes(this.' + field_name_mem + '.Encode())\n'
				else:
					self._str_encode += '\t\t' + 'pack.Write' + field_type_func + '(this.' + field_name_mem + ')\n'
				self._str_encode += '\t}\n'

		if self._mess_name.startswith('Msg'):
			self._str_encode += '\n\treturn pack.ReadBytes()\n}\n'
		else:
			self._str_encode += '\n\treturn pack.Encode(' + tool.golang_proto_name_msg(self._mess_name) + ')\n}\n'
Ejemplo n.º 15
0
    def _set_set_get(self):
        self._str_set = ''
        self._str_get = ''
        self._str_set_get = ''
        for mess_field in self._proto['mess_fields']:
            field_op = mess_field['field_op']
            field_name = mess_field['field_name']
            field_name_func = tool.underline_to_camel(field_name)
            field_name_flag = field_name + '_flag'

            str_set = 'function set' + field_name_func + '(self, ' + field_name + ')\n'
            str_get = 'function get' + field_name_func + '(self)\n\treturn self.' + field_name + '\n'

            if field_op == 'optional':
                str_set += '\tself.' + field_name_flag + ' = 1\n'
            str_set += '\tself.' + field_name + ' = ' + field_name + '\n'

            str_set += 'end'
            str_get += 'end'

            self._str_set += str_set + '\n\n'
            self._str_get += str_get + '\n\n'
            self._str_set_get += str_set + '\n' + str_get + '\n\n'
Ejemplo n.º 16
0
	def _set_set_get(self):
		self._str_set = ''
		self._str_get = ''
		self._str_set_get = ''
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_name 		= mess_field['field_name']
			field_name_func	= tool.underline_to_camel(field_name)
			field_name_flag = field_name + '_flag'

			str_set = 'function set' + field_name_func + '(self, ' + field_name + ')\n'
			str_get = 'function get' + field_name_func + '(self)\n\treturn self.' + field_name + '\n'

			if field_op == 'optional':
				str_set += '\tself.' + field_name_flag + ' = 1\n'
			str_set += '\tself.' + field_name + ' = ' + field_name + '\n'

			str_set += 'end'
			str_get += 'end'

			self._str_set += str_set + '\n\n'
			self._str_get += str_get + '\n\n'
			self._str_set_get += str_set + '\n' + str_get + '\n\n'
Ejemplo n.º 17
0
    def _set_proto_set_get(self):
        self._str_set = ''
        self._str_get = ''
        self._str_set_get = ''
        for mess_field in self._proto['mess_fields']:
            field_op = mess_field['field_op']
            field_type = mess_field['field_type']
            field_name_big = tool.underline_to_camel(mess_field['field_name'])
            field_name_mem = field_name_big[:1].lower() + field_name_big[1:]
            field_name_flag = field_name_mem + 'Flag'

            str_get = 'func (this *' + self._str_class_name + ') Get' + field_name_big + '() '
            str_set = 'func (this *' + self._str_class_name + ') Set' + field_name_big + '('
            if field_type.startswith('Msg'):
                if 'repeated' == field_op:
                    str_get += '[]*' + field_type + ' {\n'
                    str_set += field_name_mem + ' []*' + field_type + ') {\n'
                else:
                    str_get += '*' + field_type + ' {\n'
                    str_set += field_name_mem + ' *' + field_type + ') {\n'
            else:
                if 'repeated' == field_op:
                    str_get += '[]' + field_type + ' {\n'
                    str_set += field_name_mem + ' []' + field_type + ') {\n'
                else:
                    str_get += field_type + ' {\n'
                    str_set += field_name_mem + ' ' + field_type + ') {\n'

            str_get += '\treturn this.' + field_name_mem + '\n}\n'
            if 'optional' == field_op:
                str_set += '\tthis.' + field_name_flag + ' = 1\n'
            str_set += '\tthis.' + field_name_mem + ' = ' + field_name_mem + '\n}\n'

            self._str_set += str_set + '\n'
            self._str_get += str_get + '\n'
            self._str_set_get += str_set + '\n' + str_get + '\n'
Ejemplo n.º 18
0
	def _set_proto_set_get(self):
		self._str_set 		= ''
		self._str_get 		= ''
		self._str_set_get	= ''
		for mess_field in self._proto['mess_fields']:
			field_op 		= mess_field['field_op']
			field_type 		= mess_field['field_type']
			field_name_big	= tool.underline_to_camel(mess_field['field_name'])
			field_name_mem 	= field_name_big[:1].lower() + field_name_big[1:]
			field_name_flag = field_name_mem + 'Flag'

			str_get = 'func (this *' + self._str_class_name + ') Get' + field_name_big + '() '
			str_set = 'func (this *' + self._str_class_name + ') Set' + field_name_big + '('
			if field_type.startswith('Msg'):
				if 'repeated' == field_op:
					str_get += '[]*' + field_type + ' {\n'
					str_set += field_name_mem + ' []*' + field_type + ') {\n'
				else:
					str_get += '*' + field_type + ' {\n'
					str_set += field_name_mem + ' *' + field_type + ') {\n'
			else:
				if 'repeated' == field_op:
					str_get += '[]' + field_type + ' {\n'
					str_set += field_name_mem + ' []' + field_type + ') {\n'
				else:
					str_get += field_type + ' {\n'
					str_set += field_name_mem + ' ' + field_type + ') {\n'

			str_get += '\treturn this.' + field_name_mem + '\n}\n'
			if 'optional' == field_op:
				str_set += '\tthis.' + field_name_flag + ' = 1\n'
			str_set += '\tthis.' + field_name_mem + ' = ' + field_name_mem + '\n}\n'

			self._str_set 		+= str_set + '\n'
			self._str_get 		+= str_get + '\n'
			self._str_set_get 	+= str_set + '\n' + str_get + '\n'
Ejemplo n.º 19
0
	def _set_proto_encode(self):
		self._str_proto_encode = ''
		_idx_bin    = 0
		for mess_field in self._proto['mess_fields']:
			_idx_bin 	+= 1

			field_op 	= mess_field['field_op']
			field_type 	= mess_field['field_type']
			field_name 	= mess_field['field_name']

			_field_var_name = tool.underline_to_camel(field_name)

			if 'required' == field_op:
				if field_type.startswith('Msg'):
					_str_tmp = 'Bin' + str(_idx_bin) + ' = ' + tool.camel_to_underline(
						field_type) + '_encode(' + _field_var_name + '),\n\t'
				else:
					_str_tmp = 'Bin' + str(_idx_bin) + ' = ?E(' + field_type + ', ' + _field_var_name + '),\n\t'

				self._str_proto_encode += _str_tmp

			if 'repeated' == field_op:
				_str_tmp = ''

				_str_fun_name = 'Fun' + _field_var_name
				_str_tmp += _str_fun_name + ' = fun(F' + _field_var_name + ', {CountAcc, BinAcc}) ->\n\t\t\t'
				if field_type.startswith('Msg'):
					_str_tmp += 'FBin = ' + tool.camel_to_underline(
						field_type) + '_encode(F' + _field_var_name + '),\n\t\t\t'
				else:
					_str_tmp += 'FBin = ?E(' + field_type + ', F' + _field_var_name + '),\n\t\t\t'

				_str_tmp += '{CountAcc + 1, <<BinAcc/binary,FBin/binary>>}\n\t'
				_str_tmp += 'end,\n\t'
				_str_tmp += '{Count' + _field_var_name + ', Bin' + _field_var_name + '} = lists:foldl(' + _str_fun_name + ', {0, <<>>}, ' + _field_var_name + '),\n\t'
				_str_tmp += 'Bin' + str(_idx_bin) + ' = ?E(u16, ' + 'Count' + _field_var_name + '),\n\t'

				_idx_bin += 1

				_str_tmp += 'Bin' + str(_idx_bin) + ' = Bin' + _field_var_name + ',\n\t'

				self._str_proto_encode += _str_tmp

			if 'optional' == field_op:
				_str_tmp = 'Bin' + str(_idx_bin) + ' = \n\t\t'

				_str_tmp += 'case ' + _field_var_name + ' of\n\t\t\t'
				_str_tmp += 'undefined ->\n\t\t\t\t'
				_str_tmp += '?E(u8, 0);\n\t\t\t'
				_str_tmp += '_ ->\n\t\t\t\t'
				_str_tmp += 'Bin' + _field_var_name + 'Flag = ?E(u8, 1),\n\t\t\t\t'
				if field_type.startswith('Msg'):
					_str_tmp += 'Bin' + _field_var_name + ' = ' + tool.camel_to_underline(
						field_type) + '_encode(' + _field_var_name + '),\n\t\t\t\t'
				else:
					_str_tmp += 'Bin' + _field_var_name + '= ?E(' + field_type + ', ' + _field_var_name + '),\n\t\t\t\t'

				_str_tmp += '<<Bin' + _field_var_name + 'Flag/binary,Bin' + _field_var_name + '/binary>>\n\t\t'
				_str_tmp += 'end,\n\t'
				self._str_proto_encode += _str_tmp

		self._str_bin_encode = ''
		for i in range(1, _idx_bin + 1):
			self._str_bin_encode += 'Bin' + str(i) + '/binary,'

		self._str_bin_encode = '<<' + self._str_bin_encode[:-1] + '>>'
Ejemplo n.º 20
0
	def _set_proto_decode(self):
		self._str_proto_decode = ''

		_idx_bin = 0
		for mess_field in self._proto['mess_fields']:
			_idx_bin_pre= _idx_bin
			_idx_bin 	+= 1

			field_op 	= mess_field['field_op']
			field_type 	= mess_field['field_type']
			field_name 	= mess_field['field_name']

			_field_var_name = tool.underline_to_camel(field_name)

			if 'required' == field_op:
				if field_type.startswith('Msg'):
					_str_tmp = '{' + _field_var_name + ', Bin' + str(_idx_bin) + '} = ' + tool.camel_to_underline(
						field_type) + '_decode(Bin' + str(_idx_bin_pre) + '),\n\t'
				else:
					_str_tmp = '{' + _field_var_name + ', Bin' + str(_idx_bin) + '} = ?D(' + field_type + ', Bin' + str(
						_idx_bin_pre) + '),\n\t'

				self._str_proto_decode += _str_tmp

			if 'repeated' == field_op:
				_str_tmp = '{' + _field_var_name + 'Count, Bin' + str(_idx_bin) + '} = ?D(u16' + ', Bin' + str(
					_idx_bin_pre) + '),\n\t'

				_idx_bin_pre = _idx_bin
				_idx_bin += 1

				_str_fun_name = 'Fun' + _field_var_name
				_str_tmp += _str_fun_name + ' = fun(_, {' + _field_var_name + 'Acc, Bin' + _field_var_name + 'Acc}) ->\n\t\t\t\t'
				_str_tmp += '{Fun' + _field_var_name + ', Bin' + _field_var_name + 'Acc2} = '
				if field_type.startswith('Msg'):
					_str_tmp += tool.camel_to_underline(field_type) + '_decode(Bin' + _field_var_name + 'Acc),\n\t\t\t\t'
				else:
					_str_tmp += '?D(' + field_type + ', Bin' + _field_var_name + 'Acc),\n\t\t\t\t'

				_str_tmp += '{[Fun' + _field_var_name + '|' + _field_var_name + 'Acc], Bin' + _field_var_name + 'Acc2}\n\t\t\t'
				_str_tmp += 'end,\n\t'
				_str_tmp += '{' + _field_var_name + ', Bin' + str(
					_idx_bin) + '} = lists:foldl(' + _str_fun_name + ', {[], Bin' + str(
					_idx_bin_pre) + '}, lists:duplicate(' + _field_var_name + 'Count, 0)),\n\t'

				self._str_proto_decode += _str_tmp

			if 'optional' == field_op:
				_str_tmp = '{' + _field_var_name + 'Flag, Bin' + str(_idx_bin) + '} = ?D(u8' + ', Bin' + str(
					_idx_bin_pre) + '),\n\t'

				_idx_bin_pre = _idx_bin
				_idx_bin += 1

				_str_tmp += '{' + _field_var_name + ', Bin' + str(_idx_bin) + '} =\n\t'
				_str_tmp += 'case ' + _field_var_name + 'Flag of\n\t\t'
				_str_tmp += '0 ->\n\t\t\t'
				_str_tmp += '{undefined, Bin' + str(_idx_bin_pre) + '};\n\t\t'
				_str_tmp += '1 ->\n\t\t\t'
				if field_type.startswith('Msg'):
					_str_tmp += '' + tool.camel_to_underline(field_type) + '_decode(Bin' + str(_idx_bin_pre) + ')\n\t'
				else:
					_str_tmp += '?D(' + field_type + ', Bin' + str(_idx_bin_pre) + ')\n\t'

				_str_tmp += 'end,\n\t'
				self._str_proto_decode += _str_tmp

		self._str_return_bin = 'Bin' + str(_idx_bin)