当前位置: 首页>>代码示例>>Python>>正文


Python encoder.Encoder类代码示例

本文整理汇总了Python中krpc.encoder.Encoder的典型用法代码示例。如果您正苦于以下问题:Python Encoder类的具体用法?Python Encoder怎么用?Python Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connect

def connect(address=DEFAULT_ADDRESS, rpc_port=DEFAULT_RPC_PORT, stream_port=DEFAULT_STREAM_PORT, name=None):
    """
    Connect to a kRPC server on the specified IP address and port numbers. If
    stream_port is None, does not connect to the stream server.
    Optionally give the kRPC server the supplied name to identify the client (up
    to 32 bytes of UTF-8 encoded text).
    """
    assert rpc_port != stream_port

    # Connect to RPC server
    rpc_connection = Connection(address, rpc_port)
    rpc_connection.connect(retries=10, timeout=0.1)
    rpc_connection.send(Encoder.RPC_HELLO_MESSAGE)
    rpc_connection.send(Encoder.client_name(name))
    client_identifier = rpc_connection.receive(Decoder.GUID_LENGTH)

    # Connect to Stream server
    if stream_port is not None:
        stream_connection = Connection(address, stream_port)
        stream_connection.connect(retries=10, timeout=0.1)
        stream_connection.send(Encoder.STREAM_HELLO_MESSAGE)
        stream_connection.send(client_identifier)
        ok_message = stream_connection.receive(Decoder.OK_LENGTH)
        assert ok_message == Decoder.OK_MESSAGE
    else:
        stream_connection = None

    return Client(rpc_connection, stream_connection)
开发者ID:rosalesr,项目名称:krpc,代码行数:28,代码来源:__init__.py

示例2: test_encode_message_delimited

 def test_encode_message_delimited(self):
     request = krpc.schema.KRPC.Request()
     request.service = 'ServiceName'
     request.procedure = 'ProcedureName'
     data = Encoder.encode_delimited(request, self.types.as_type('KRPC.Request'))
     expected = '1c'+'0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     self.assertEqual(expected, hexlify(data))
开发者ID:Kerbal007,项目名称:krpc,代码行数:7,代码来源:test_encoder.py

示例3: test_encode_message

 def test_encode_message(self):
     call = self.types.procedure_call_type.python_type()
     call.service = 'ServiceName'
     call.procedure = 'ProcedureName'
     data = Encoder.encode(call, self.types.procedure_call_type)
     expected = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     self.assertEqual(expected, hexlify(data))
开发者ID:Loran425,项目名称:krpc,代码行数:7,代码来源:test_encoder.py

示例4: test_encode_class

 def test_encode_class(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     class_type = typ.python_type
     self.assertTrue(issubclass(class_type, ClassBase))
     value = class_type(300)
     self.assertEqual(300, value._object_id)
     data = Encoder.encode(value, typ)
     self.assertEqual('ac02', hexlify(data))
开发者ID:Kerbal007,项目名称:krpc,代码行数:8,代码来源:test_encoder.py

示例5: encode_argument

 def encode_argument(i, value):
     typ = param_types[i]
     if type(value) != typ.python_type:
         # Try coercing to the correct type
         try:
             value = self._types.coerce_to(value, typ)
         except ValueError:
             raise TypeError('%s.%s() argument %d must be a %s, got a %s' % \
                             (service, procedure, i, typ.python_type, type(value)))
     return Encoder.encode(value, typ)
开发者ID:asmigala,项目名称:krpc,代码行数:10,代码来源:client.py

示例6: _build_request

    def _build_request(self, service, procedure, args,
                       param_names, param_types, return_type): #pylint: disable=unused-argument
        """ Build a KRPC.Request object """

        request = krpc.schema.KRPC.Request(service=service, procedure=procedure)

        for i, (value, typ) in enumerate(itertools.izip(args, param_types)):
            if isinstance(value, DefaultArgument):
                continue
            if not isinstance(value, typ.python_type):
                try:
                    value = self._types.coerce_to(value, typ)
                except ValueError:
                    raise TypeError('%s.%s() argument %d must be a %s, got a %s' % \
                                    (service, procedure, i, typ.python_type, type(value)))
            request.arguments.add(position=i, value=Encoder.encode(value, typ))

        return request
开发者ID:chippydip,项目名称:krpc,代码行数:18,代码来源:client.py

示例7: _send_request

 def _send_request(self, request):
     """ Send a KRPC.Request object to the server """
     data = Encoder.encode_delimited(request, self._request_type)
     self._rpc_connection.send(data)
开发者ID:602p,项目名称:krpc,代码行数:4,代码来源:client.py

示例8: _run_test_encode_value

 def _run_test_encode_value(self, typ, cases):
     for decoded, encoded in cases:
         data = Encoder.encode(decoded, self.types.as_type(typ))
         self.assertEqual(encoded, hexlify(data))
开发者ID:Kerbal007,项目名称:krpc,代码行数:4,代码来源:test_encodedecode.py

示例9: test_encode_class_none

 def test_encode_class_none(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     value = None
     data = Encoder.encode(value, typ)
     self.assertEqual('00', hexlify(data))
开发者ID:Kerbal007,项目名称:krpc,代码行数:5,代码来源:test_encoder.py

示例10: test_encode_value_delimited

 def test_encode_value_delimited(self):
     data = Encoder.encode_delimited(300, self.types.as_type('int32'))
     self.assertEqual('02'+'ac02', hexlify(data))
开发者ID:Kerbal007,项目名称:krpc,代码行数:3,代码来源:test_encoder.py

示例11: test_encode_unicode_string

 def test_encode_unicode_string(self):
     data = Encoder.encode(b'\xe2\x84\xa2'.decode('utf-8'), self.types.as_type('string'))
     self.assertEqual('03e284a2', hexlify(data))
开发者ID:Kerbal007,项目名称:krpc,代码行数:3,代码来源:test_encoder.py

示例12: test_long_client_name

 def test_long_client_name(self):
     message = Encoder.client_name('a'*33)
     self.assertEqual (32, len(message))
     self.assertEqual ('61'*32, hexlify(message))
开发者ID:Kerbal007,项目名称:krpc,代码行数:4,代码来源:test_encoder.py

示例13: test_empty_client_name

 def test_empty_client_name(self):
     message = Encoder.client_name()
     self.assertEqual (32, len(message))
     self.assertEqual ('00'*32, hexlify(message))
开发者ID:Kerbal007,项目名称:krpc,代码行数:4,代码来源:test_encoder.py

示例14: test_client_name

 def test_client_name(self):
     message = Encoder.client_name('foo')
     self.assertEqual (32, len(message))
     self.assertEqual ('666f6f'+'00'*29, hexlify(message))
开发者ID:Kerbal007,项目名称:krpc,代码行数:4,代码来源:test_encoder.py

示例15: test_encode_value

 def test_encode_value(self):
     data = Encoder.encode(300, self.types.uint32_type)
     self.assertEqual('ac02', hexlify(data))
开发者ID:Loran425,项目名称:krpc,代码行数:3,代码来源:test_encoder.py


注:本文中的krpc.encoder.Encoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。