Exemple #1
0
def encode_frame(frame_type: int, frame_data: bytes) -> bytes:
    frame_length = len(frame_data)
    buf = Buffer(capacity=frame_length + 16)
    buf.push_uint_var(frame_type)
    buf.push_uint_var(frame_length)
    buf.push_bytes(frame_data)
    return buf.data
Exemple #2
0
 def test_push_uint_var_too_big(self):
     buf = Buffer(capacity=8)
     with self.assertRaises(ValueError) as cm:
         buf.push_uint_var(4611686018427387904)
     self.assertEqual(
         str(cm.exception), "Integer is too big for a variable-length integer"
     )
Exemple #3
0
    def roundtrip(self, data, value):
        buf = Buffer(data=data)
        self.assertEqual(buf.pull_uint_var(), value)
        self.assertEqual(buf.tell(), len(data))

        buf = Buffer(capacity=8)
        buf.push_uint_var(value)
        self.assertEqual(buf.data, data)
Exemple #4
0
 def encode(self) -> bytes:
     """
     Encodes this H3Capsule and return the bytes.
     """
     buffer = Buffer(capacity=len(self.data) + 2 * UINT_VAR_MAX_SIZE)
     buffer.push_uint_var(self.type)
     buffer.push_uint_var(len(self.data))
     buffer.push_bytes(self.data)
     return buffer.data
Exemple #5
0
def encode_settings(settings: Dict[int, int]) -> bytes:
    buf = Buffer(capacity=1024)
    for setting, value in settings.items():
        buf.push_uint_var(setting)
        buf.push_uint_var(value)
    return buf.data
Exemple #6
0
def encode_uint_var(v):
    buf = Buffer(capacity=8)
    buf.push_uint_var(v)
    return buf.data