def test_encode_uncompressed_header_with_max_payload(self):
     buffer = six.BytesIO()
     segment_codec_no_compression.encode_header(buffer, len(self.max_msg),
                                                -1, True)
     self.assertEqual(buffer.tell(), 6)
     self.assertEqual(self._header_to_bits(buffer.getvalue()),
                      "11111111111111111" + "1" + "000000")
 def test_encode_uncompressed_header(self):
     buffer = six.BytesIO()
     segment_codec_no_compression.encode_header(buffer, len(self.small_msg),
                                                -1, True)
     self.assertEqual(buffer.tell(), 6)
     self.assertEqual(self._header_to_bits(buffer.getvalue()),
                      "00000000000110010" + "1" + "000000")
 def test_decode_uncompressed_header(self):
     buffer = six.BytesIO()
     segment_codec_no_compression.encode_header(buffer, len(self.small_msg),
                                                -1, True)
     buffer.seek(0)
     header = segment_codec_no_compression.decode_header(buffer)
     self.assertEqual(header.uncompressed_payload_length, -1)
     self.assertEqual(header.payload_length, len(self.small_msg))
     self.assertEqual(header.is_self_contained, True)
    def test_decode_header_fails_if_corrupted(self):
        buffer = six.BytesIO()
        segment_codec_no_compression.encode_header(buffer, len(self.small_msg),
                                                   -1, True)
        # corrupt one byte
        buffer.seek(buffer.tell() - 1)
        buffer.write(b'0')
        buffer.seek(0)

        with self.assertRaises(CrcException):
            segment_codec_no_compression.decode_header(buffer)
 def test_encode_uncompressed_header_not_self_contained_msg(self):
     buffer = six.BytesIO()
     # simulate the first chunk with the max size
     segment_codec_no_compression.encode_header(buffer, len(self.max_msg),
                                                -1, False)
     self.assertEqual(buffer.tell(), 6)
     self.assertEqual(
         self._header_to_bits(buffer.getvalue()),
         (
             "11111111111111111"
             "0"  # not self contained
             "000000"))