Ejemplo n.º 1
0
 def parse_type(self, typ):
     if isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string' or typ == 'bytes':
             return 'std::string'
         elif 'int' in typ:
             return 'google::protobuf::%s' % typ
         else:
             return typ
     elif isinstance(typ, krpc.types.MessageType):
         typ = typ.protobuf_type
         if typ.startswith('KRPC.'):
             _, _, x = typ.rpartition('.')
             return 'krpc::schema::%s' % x
         elif typ.startswith('Test.'):
             _, _, x = typ.rpartition('.')
             return 'Test::%s' % x
     elif isinstance(typ, krpc.types.ListType):
         return cpp_template_fix('std::vector<%s>' %
                                 self.parse_type(self.types.as_type(typ.protobuf_type[5:-1])))
     elif isinstance(typ, krpc.types.SetType):
         return cpp_template_fix('std::set<%s>' % self.parse_type(self.types.as_type(typ.protobuf_type[4:-1])))
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return cpp_template_fix('std::map<%s, %s>' % \
             (self.parse_type(self.types.as_type(typs[0])), self.parse_type(self.types.as_type(typs[1]))))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         return cpp_template_fix('std::tuple<%s>' % \
             ', '.join(self.parse_type(self.types.as_type(t)) for t in value_types))
     elif isinstance(typ, krpc.types.ClassType):
         return typ.protobuf_type[6:-1].replace('.', '::')
     elif isinstance(typ, krpc.types.EnumType):
         return typ.protobuf_type[5:-1].replace('.', '::')
     raise RuntimeError('Unknown type ' + typ)
Ejemplo n.º 2
0
 def parse_type_specification(self, typ):
     if typ is None:
         return None
     if isinstance(typ, krpc.types.ListType):
         return 'new TypeSpecification(java.util.List.class, %s)' % \
             self.parse_type_specification(
                 self.types.as_type(typ.protobuf_type[5:-1]))
     elif isinstance(typ, krpc.types.SetType):
         return 'new TypeSpecification(java.util.Set.class, %s)' % \
             self.parse_type_specification(
                 self.types.as_type(typ.protobuf_type[4:-1]))
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return 'new TypeSpecification(java.util.Map.class, %s, %s)' % \
             (self.parse_type_specification(self.types.as_type(typs[0])),
              self.parse_type_specification(self.types.as_type(typs[1])))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         return 'new TypeSpecification(org.javatuples.%s.class, %s)' % \
             (self.get_tuple_class_name(value_types),
              ','.join(self.parse_type_specification(self.types.as_type(t))
                       for t in value_types))
     else:
         return 'new TypeSpecification(%s.class)' % \
             self.parse_type(typ, True)
Ejemplo n.º 3
0
 def parse_type(self, typ):
     if isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string' or typ == 'bytes':
             return 'std::string'
         elif 'int' in typ:
             return 'google::protobuf::%s' % typ
         else:
             return typ
     elif isinstance(typ, krpc.types.MessageType):
         typ = typ.protobuf_type
         if typ.startswith('KRPC.'):
             _, _, x = typ.rpartition('.')
             return 'krpc::schema::%s' % x
         elif typ.startswith('Test.'):
             _, _, x = typ.rpartition('.')
             return 'Test::%s' % x
     elif isinstance(typ, krpc.types.ListType):
         return cpp_template_fix('std::vector<%s>' %
                                 self.parse_type(self.types.as_type(typ.protobuf_type[5:-1])))
     elif isinstance(typ, krpc.types.SetType):
         return cpp_template_fix('std::set<%s>' % self.parse_type(self.types.as_type(typ.protobuf_type[4:-1])))
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return cpp_template_fix('std::map<%s, %s>' % \
             (self.parse_type(self.types.as_type(typs[0])), self.parse_type(self.types.as_type(typs[1]))))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         return cpp_template_fix('std::tuple<%s>' % \
             ', '.join(self.parse_type(self.types.as_type(t)) for t in value_types))
     elif isinstance(typ, krpc.types.ClassType):
         return typ.protobuf_type[6:-1].replace('.', '::')
     elif isinstance(typ, krpc.types.EnumType):
         return typ.protobuf_type[5:-1].replace('.', '::')
     raise RuntimeError('Unknown type ' + typ)
Ejemplo n.º 4
0
 def parse_type(self, typ):
     if isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string':
             return 'String'
         elif typ == 'bytes':
             return 'byte[]'
         elif typ == 'float':
             return 'Single'
         elif typ == 'double':
             return 'Double'
         elif typ == 'bool':
             return 'Boolean'
         elif 'int' in typ:
             int_type_map = {
                 'int16': 'Int16',
                 'uint16': 'UInt16',
                 'int32': 'Int32',
                 'uint32': 'UInt32',
                 'int64': 'Int64',
                 'uint64': 'UInt64'
             }
             return int_type_map[typ]
     elif isinstance(typ, krpc.types.MessageType):
         typ = typ.protobuf_type
         if typ.startswith('KRPC.'):
             _, _, x = typ.rpartition('.')
             return 'global::KRPC.Schema.KRPC.%s' % x
         elif typ.startswith('Test.'):
             _, _, x = typ.rpartition('.')
             return 'global::Test.%s' % x
     elif isinstance(typ, krpc.types.ListType):
         return 'global::System.Collections.Generic.IList<%s>' % \
             self.parse_type(self.types.as_type(typ.protobuf_type[5:-1]))
     elif isinstance(typ, krpc.types.SetType):
         return 'global::System.Collections.Generic.ISet<%s>' % \
             self.parse_type(self.types.as_type(typ.protobuf_type[4:-1]))
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return 'global::System.Collections.Generic.IDictionary<%s,%s>' % \
             (self.parse_type(self.types.as_type(typs[0])), self.parse_type(self.types.as_type(typs[1])))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         return 'global::System.Tuple<%s>' % ','.join(
             self.parse_type(self.types.as_type(t)) for t in value_types)
     elif isinstance(typ, krpc.types.ClassType):
         return 'global::KRPC.Client.Services.%s' % typ.protobuf_type[6:-1]
     elif isinstance(typ, krpc.types.EnumType):
         return 'global::KRPC.Client.Services.%s' % typ.protobuf_type[5:-1]
     raise RuntimeError('Unknown type ' + typ)
Ejemplo n.º 5
0
    def __init__(self, type_string, types):
        if not (type_string.startswith('Tuple(') and type_string.endswith(')')):
            raise ValueError('\'%s\' is not a valid type string for a tuple type' % type_string)

        self.value_types = [types.as_type(typ) for typ in split_type_string(type_string[6:-1])]

        super(TupleType, self).__init__(str(type_string), tuple)
Ejemplo n.º 6
0
    def __init__(self, type_string, types):
        if not (type_string.startswith('Dictionary(') and type_string.endswith(')')):
            raise ValueError('\'%s\' is not a valid type string for a dictionary type' % type_string)

        type_strings = split_type_string(type_string[11:-1])
        if len(type_strings) != 2:
            raise ValueError('\'%s\' is not a valid type string for a dictionary type' % type_string)
        self.key_type = types.as_type(type_strings[0])
        self.value_type = types.as_type(type_strings[1])

        super(DictionaryType, self).__init__(str(type_string), dict)
Ejemplo n.º 7
0
 def parse_type_specification(self, typ):
     if typ is None:
         return None
     if isinstance(typ, krpc.types.ListType):
         return 'new TypeSpecification(java.util.List.class, %s)' % \
             self.parse_type_specification(self.types.as_type(typ.protobuf_type[5:-1]))
     elif isinstance(typ, krpc.types.SetType):
         return 'new TypeSpecification(java.util.Set.class, %s)' % \
             self.parse_type_specification(self.types.as_type(typ.protobuf_type[4:-1]))
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return 'new TypeSpecification(java.util.Map.class, %s, %s)' % \
             (self.parse_type_specification(self.types.as_type(typs[0])),
              self.parse_type_specification(self.types.as_type(typs[1])))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         return 'new TypeSpecification(org.javatuples.%s.class, %s)' % \
             (self.get_tuple_class_name(value_types),
              ','.join(self.parse_type_specification(self.types.as_type(t)) for t in value_types))
     else:
         return 'new TypeSpecification(%s.class)' % self.parse_type(typ, True)
Ejemplo n.º 8
0
Archivo: csharp.py Proyecto: krpc/krpc
 def parse_type(self, typ, interface=True):
     if isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string':
             return 'String'
         elif typ == 'bytes':
             return 'byte[]'
         elif typ == 'float':
             return 'Single'
         elif typ == 'double':
             return 'Double'
         elif typ == 'bool':
             return 'Boolean'
         elif 'int' in typ:
             int_type_map = {
                 'int16' : 'Int16',
                 'uint16': 'UInt16',
                 'int32' : 'Int32',
                 'uint32': 'UInt32',
                 'int64' : 'Int64',
                 'uint64': 'UInt64'
             }
             return int_type_map[typ]
     elif isinstance(typ, krpc.types.MessageType):
         typ = typ.protobuf_type
         if typ.startswith('KRPC.'):
             _, _, x = typ.rpartition('.')
             return 'global::KRPC.Schema.KRPC.%s' % x
         elif typ.startswith('Test.'):
             _, _, x = typ.rpartition('.')
             return 'global::Test.%s' % x
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         return 'global::System.Tuple<%s>' % ','.join(self.parse_type(self.types.as_type(t))
                                                      for t in value_types)
     elif isinstance(typ, krpc.types.ListType):
         if interface:
             name = 'IList'
         else:
             name = 'List'
         return 'global::System.Collections.Generic.%s<%s>' % \
             (name, self.parse_type(self.types.as_type(typ.protobuf_type[5:-1])))
     elif isinstance(typ, krpc.types.SetType):
         if interface:
             name = 'ISet'
         else:
             name = 'HashSet'
         return 'global::System.Collections.Generic.%s<%s>' % \
             (name, self.parse_type(self.types.as_type(typ.protobuf_type[4:-1])))
     elif isinstance(typ, krpc.types.DictionaryType):
         if interface:
             name = 'IDictionary'
         else:
             name = 'Dictionary'
         typs = split_type_string(typ.protobuf_type[11:-1])
         return 'global::System.Collections.Generic.%s<%s,%s>' % \
             (name, self.parse_type(self.types.as_type(typs[0])), self.parse_type(self.types.as_type(typs[1])))
     elif isinstance(typ, krpc.types.ClassType):
         return 'global::KRPC.Client.Services.%s' % typ.protobuf_type[6:-1]
     elif isinstance(typ, krpc.types.EnumType):
         return 'global::KRPC.Client.Services.%s' % typ.protobuf_type[5:-1]
     raise RuntimeError('Unknown type ' + typ)
Ejemplo n.º 9
0
 def parse_type(self, typ, in_collection=False):
     if not in_collection and isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string':
             return 'String'
         elif typ == 'bytes':
             return 'byte[]'
         elif typ == 'float':
             return 'float'
         elif typ == 'double':
             return 'double'
         elif typ == 'bool':
             return 'boolean'
         elif 'int' in typ:
             int_type_map = {
                 'int32' : 'int',
                 'uint32': 'int',
                 'int64' : 'long',
                 'uint64': 'long'
             }
             return int_type_map[typ]
     elif isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string':
             return 'String'
         elif typ == 'bytes':
             return 'byte[]'
         elif typ == 'float':
             return 'Float'
         elif typ == 'double':
             return 'Double'
         elif typ == 'bool':
             return 'Boolean'
         elif 'int' in typ:
             int_type_map = {
                 'int32' : 'Integer',
                 'uint32': 'Integer',
                 'int64' : 'Long',
                 'uint64': 'Long'
             }
             return int_type_map[typ]
     elif isinstance(typ, krpc.types.MessageType):
         typ = typ.protobuf_type
         if typ.startswith('KRPC.'):
             _, _, x = typ.rpartition('.')
             return 'krpc.schema.KRPC.%s' % x
         elif typ.startswith('Test.'):
             _, _, x = typ.rpartition('.')
             return 'test.Test.%s' % x
     elif isinstance(typ, krpc.types.ListType):
         return 'java.util.List<%s>' % \
             self.parse_type(self.types.as_type(typ.protobuf_type[5:-1]), True)
     elif isinstance(typ, krpc.types.SetType):
         return 'java.util.Set<%s>' % \
             self.parse_type(self.types.as_type(typ.protobuf_type[4:-1]), True)
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return 'java.util.Map<%s,%s>' % (self.parse_type(self.types.as_type(typs[0]), True),
                                          self.parse_type(self.types.as_type(typs[1]), True))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         name = self.get_tuple_class_name(value_types)
         return 'org.javatuples.'+name+'<%s>' % (','.join(self.parse_type(self.types.as_type(t), True)
                                                          for t in value_types))
     elif isinstance(typ, krpc.types.ClassType):
         return 'krpc.client.services.%s' % typ.protobuf_type[6:-1]
     elif isinstance(typ, krpc.types.EnumType):
         return 'krpc.client.services.%s' % typ.protobuf_type[5:-1]
     raise RuntimeError('Unknown type ' + typ)
Ejemplo n.º 10
0
 def parse_type(self, typ, in_collection=False):
     if not in_collection and isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string':
             return 'String'
         elif typ == 'bytes':
             return 'byte[]'
         elif typ == 'float':
             return 'float'
         elif typ == 'double':
             return 'double'
         elif typ == 'bool':
             return 'boolean'
         elif 'int' in typ:
             int_type_map = {
                 'int32': 'int',
                 'uint32': 'int',
                 'int64': 'long',
                 'uint64': 'long'
             }
             return int_type_map[typ]
     elif isinstance(typ, krpc.types.ValueType):
         typ = typ.protobuf_type
         if typ == 'string':
             return 'String'
         elif typ == 'bytes':
             return 'byte[]'
         elif typ == 'float':
             return 'Float'
         elif typ == 'double':
             return 'Double'
         elif typ == 'bool':
             return 'Boolean'
         elif 'int' in typ:
             int_type_map = {
                 'int32': 'Integer',
                 'uint32': 'Integer',
                 'int64': 'Long',
                 'uint64': 'Long'
             }
             return int_type_map[typ]
     elif isinstance(typ, krpc.types.MessageType):
         typ = typ.protobuf_type
         if typ.startswith('KRPC.'):
             _, _, x = typ.rpartition('.')
             return 'krpc.schema.KRPC.%s' % x
         elif typ.startswith('Test.'):
             _, _, x = typ.rpartition('.')
             return 'test.Test.%s' % x
     elif isinstance(typ, krpc.types.ListType):
         return 'java.util.List<%s>' % \
             self.parse_type(self.types.as_type(typ.protobuf_type[5:-1]), True)
     elif isinstance(typ, krpc.types.SetType):
         return 'java.util.Set<%s>' % \
             self.parse_type(self.types.as_type(typ.protobuf_type[4:-1]), True)
     elif isinstance(typ, krpc.types.DictionaryType):
         typs = split_type_string(typ.protobuf_type[11:-1])
         return 'java.util.Map<%s,%s>' % (self.parse_type(
             self.types.as_type(typs[0]),
             True), self.parse_type(self.types.as_type(typs[1]), True))
     elif isinstance(typ, krpc.types.TupleType):
         value_types = split_type_string(typ.protobuf_type[6:-1])
         name = self.get_tuple_class_name(value_types)
         return 'org.javatuples.' + name + '<%s>' % (','.join(
             self.parse_type(self.types.as_type(t), True)
             for t in value_types))
     elif isinstance(typ, krpc.types.ClassType):
         return 'krpc.client.services.%s' % typ.protobuf_type[6:-1]
     elif isinstance(typ, krpc.types.EnumType):
         return 'krpc.client.services.%s' % typ.protobuf_type[5:-1]
     raise RuntimeError('Unknown type ' + typ)