コード例 #1
0
 def create_from_bytes(cls, buffer):
     fid = decode_varint(buffer)
     field_type = FieldType.by_code(read_byte(buffer).decode("ascii"))
     field_encoding = FieldEncoding.by_code(
         read_byte(buffer).decode("ascii"))
     scale = decode_varint(buffer)
     name = decode_string(buffer)
     return cls(fid, field_type, field_encoding, scale, name)
コード例 #2
0
    def test_subscription_sync_compressed_encode_with_control_block(self):
        control_block = {
            0: ControlOperations.REFRESH,
            1: ControlOperations.TOGGLE
        }
        subj_mess = SubscriptionSyncMessage(
            self.price_sync_edition_sequence_number,
            self.subjects,
            is_compressed=True,
            is_controls=True,
            sids=control_block,
        )

        encoded_message = subj_mess.to_bytes()
        self.assertEqual(decode_varint(encoded_message), 70)
        self.assertEqual(read_byte(encoded_message),
                         PixieMessageType.SubscriptionSyncMessage)
        self.assertEqual(decode_varint(encoded_message), 3)
        self.assertEqual(decode_varint(encoded_message),
                         self.price_sync_edition_sequence_number)
        self.assertEqual(decode_varint(encoded_message), len(self.subjects))
        decompressed = self.decompressor.decompress(encoded_message)
        self.assertEqual(
            bytearray(
                b"\004\011Quantity\0102500000\007Symbol\007EURGBP\004\011Quantity\0105600000\007Symbol\007USDJPY\002\000R\001T"
            ),
            decompressed,
        )
コード例 #3
0
 def test_second_welcome_message(self):
     data_dictionary_bytes = bytearray.fromhex(
         self.data_dictionary_message2_bytes)
     self.assertEqual(read_byte(data_dictionary_bytes),
                      PixieMessageType.DataDictionaryMessage)
     data_dict = DataDictionaryMessage(data_dictionary_bytes,
                                       self.decompressor)
     self.assertEqual(data_dict.is_updated, True)
コード例 #4
0
 def test_status_from_price_sync(self):
     price_sync_message_bytes = bytearray.fromhex(
         self.price_sync_with_status)
     self.assertEqual(read_byte(price_sync_message_bytes),
                      PixieMessageType.PriceSyncMessage)
     price_sync = PriceSyncMessage(price_sync_message_bytes,
                                   self.decompressor)
     self.assertEqual(price_sync.is_compressed, True)
コード例 #5
0
 def test_second_welcome_message(self):
     welcome_message_bytes = bytearray.fromhex(self.welcome_message2_bytes)
     self.assertEqual(read_byte(welcome_message_bytes), b"W")
     welcome_message = WelcomeMessage(welcome_message_bytes)
     self.assertEqual(welcome_message.options, 7)
     self.assertEqual(welcome_message.version, 1)
     self.assertEqual(welcome_message.client_id, 4321)
     self.assertEqual(welcome_message.server_id, 9902)
コード例 #6
0
    def test_first_data_dictionary_message(self):
        data_dictionary_bytes = bytearray.fromhex(
            self.data_dictionary_message1_bytes)
        self.assertEqual(read_byte(data_dictionary_bytes),
                         PixieMessageType.DataDictionaryMessage)
        data_dict = DataDictionaryMessage(data_dictionary_bytes,
                                          self.compressor)

        self.assertListEqual(self.data_dict_data,
                             [i.__dict__ for i in data_dict.definitions])
        self.assertEqual(data_dict.is_updated, False)
        self.assertEqual(data_dict.is_compressed, False)
コード例 #7
0
    def test_not_compressed_message(self):
        price_sync_message_bytes = bytearray.fromhex(
            self.price_sync_not_compressed)
        self.assertEqual(read_byte(price_sync_message_bytes),
                         PixieMessageType.PriceSyncMessage)
        price_sync = PriceSyncMessage(price_sync_message_bytes,
                                      self.decompressor)
        self.assertEqual(price_sync.is_compressed, False)

        self.assertEqual(price_sync.revision, 7)
        self.assertEqual(price_sync.revision_time, 1542372218934)
        self.assertEqual(price_sync.conflation_latency, 47)
        self.assertEqual(price_sync.edition, 4)
        self.assertEqual(price_sync.size, 3)
コード例 #8
0
    def test_compressed_message(self):
        price_sync_message_bytes = bytearray.fromhex(
            self.price_sync_compressed)
        self.assertEqual(read_byte(price_sync_message_bytes),
                         PixieMessageType.PriceSyncMessage)
        price_sync = PriceSyncMessage(price_sync_message_bytes,
                                      self.decompressor)
        self.assertEqual(price_sync.is_compressed, True)

        self.assertEqual(price_sync.revision, 3)
        self.assertEqual(price_sync.revision_time, 1539777135877)
        self.assertEqual(price_sync.conflation_latency, 99)
        self.assertEqual(55, price_sync.edition, 55)
        self.assertEqual(price_sync.size, 3)
コード例 #9
0
 def test_compressed_data_dictionary(self):
     bytes_message = bytearray.fromhex(self.data_dictionary_message2_bytes)
     header = bytearray(b"D\x03\t")  # Update + compressed
     body = bytes_message[3:]
     compressed_body = self.compressor.compress(body)
     compressed_data_dict_message = header + compressed_body
     self.assertEqual(
         read_byte(compressed_data_dict_message),
         PixieMessageType.DataDictionaryMessage,
     )
     data_dict = DataDictionaryMessage(compressed_data_dict_message,
                                       self.decompressor)
     self.assertListEqual(self.data_dict_data,
                          [i.__dict__ for i in data_dict.definitions])
     self.assertEqual(data_dict.is_updated, True)
     self.assertEqual(data_dict.is_compressed, True)
コード例 #10
0
    def test_subscription_sync_compressed_encode_without_control_block(self):
        subj_mess = SubscriptionSyncMessage(
            self.price_sync_edition_sequence_number,
            self.subjects,
            is_compressed=True)

        encoded_message = subj_mess.to_bytes()
        self.assertEqual(decode_varint(encoded_message), 59)
        self.assertEqual(read_byte(encoded_message),
                         PixieMessageType.SubscriptionSyncMessage)
        self.assertEqual(decode_varint(encoded_message), 1)
        self.assertEqual(decode_varint(encoded_message),
                         self.price_sync_edition_sequence_number)
        self.assertEqual(decode_varint(encoded_message), len(self.subjects))
        decompressed = self.decompressor.decompress(encoded_message)
        self.assertEqual(
            bytearray(
                b"\004\011Quantity\0102500000\007Symbol\007EURGBP\004\011Quantity\0105600000\007Symbol\007USDJPY"
            ),
            decompressed,
        )
コード例 #11
0
 def test_deny_bytes(self):
     grant_message_bytes = bytearray.fromhex(self.deny_bytes)
     self.assertEqual(read_byte(grant_message_bytes), b"G")
     grant_message = GrantMessage(grant_message_bytes)
     self.assertEqual(grant_message.granted, b"f")
     self.assertEqual(grant_message.reason, "invalid credentials")
コード例 #12
0
 def test_granted_bytes(self):
     grant_message_bytes = bytearray.fromhex(self.granted_bytes)
     self.assertEqual(read_byte(grant_message_bytes), b"G")
     grant_message = GrantMessage(grant_message_bytes)
     self.assertEqual(grant_message.granted, b"t")
コード例 #13
0
 def test_heartbeat_message(self):
     heartbeat_message_bytes = bytearray.fromhex(self.heartbeat_message)
     self.assertEqual(read_byte(heartbeat_message_bytes),
                      PixieMessageType.HeartbeatMessage)
     self.assertEqual(heartbeat_message_bytes, b"")