Exemple #1
0
def _unmarshal_method_frame(frame_data):
    """Attempt to unmarshal a method frame

    :param bytes frame_data: Raw frame data to assign to our method frame
    :return tuple: Amount of data consumed and the frame object

    """
    # Get the Method Index from the class data
    bytes_used, method_index = decode.long_int(frame_data[0:4])

    # Create an instance of the method object we're going to unmarshal
    try:
        method = specification.INDEX_MAPPING[method_index]()
    except KeyError:
        raise exceptions.UnmarshalingException(
            'Unknown', 'Unknown method index: {}'.format(str(method_index)))

    # Unmarshal the data
    try:
        method.unmarshal(frame_data[bytes_used:])
    except struct.error as error:
        raise exceptions.UnmarshalingException(method, error)

    #  Unmarshal the data in the object and return it
    return method
Exemple #2
0
def _unmarshal_method_frame(frame_data: bytes) -> base.Frame:
    """Attempt to unmarshal a method frame

    :raises: pamqp.exceptions.UnmarshalingException

    """
    bytes_used, method_index = decode.long_int(frame_data[0:4])
    try:
        method = commands.INDEX_MAPPING[method_index]()
    except KeyError:
        raise exceptions.UnmarshalingException(
            'Unknown', 'Unknown method index: {}'.format(str(method_index)))
    try:
        method.unmarshal(frame_data[bytes_used:])
    except struct.error as error:
        raise exceptions.UnmarshalingException(method, error)
    return method
 def test_decode_long_int_value(self):
     value = b'\x7f\xff\xff\xff'
     self.assertEqual(decode.long_int(value)[1], 2147483647)
 def test_decode_long_int_data_type(self):
     value = b'\x7f\xff\xff\xff'
     self.assertIsInstance(decode.long_int(value)[1], int)
 def test_decode_long_int_bytes_consumed(self):
     value = b'\x7f\xff\xff\xff'
     self.assertEqual(decode.long_int(value)[0], 4)