def test_var_size_buffer_marshal_no_sizer():
    class MyOneMarshal(Marshal):
        def write_to_stream(self, obj, stream, context=EMPTY_CONTEXT):
            stream.write("\x01")

        def create_from_stream(self, stream, context=EMPTY_CONTEXT, *args, **kwargs):
            return ord(stream.read(1))

    marshal = VarSizeBufferMarshal(MyOneMarshal())
    assert marshal.write_to_string("ad") == "\x01ad"
    assert marshal.create_from_string("\x03abcadsfadsf") == "abc"
Esempio n. 2
0
def test_var_size_buffer_marshal_no_sizer():
    class MyOneMarshal(Marshal):
        def write_to_stream(self, obj, stream, context=EMPTY_CONTEXT):
            stream.write(b"\x01")

        def create_from_stream(self,
                               stream,
                               context=EMPTY_CONTEXT,
                               *args,
                               **kwargs):
            return ord(stream.read(1))

    marshal = VarSizeBufferMarshal(MyOneMarshal())
    assert marshal.write_to_string(b"ad") == b"\x01ad"
    assert marshal.create_from_string(b"\x03abcadsfadsf") == b"abc"
def test_var_size_buffer_marshal():
    marshal = VarSizeBufferMarshal(UBInt8Marshal)
    assert marshal.sizeof("asd") == 4
    assert marshal.min_max_sizeof() == MinMax(1, 256)
    assert marshal.write_to_string("ad") == "\x02ad"
    assert marshal.create_from_string("\x03abcadsfadsf") == "abc"
Esempio n. 4
0
def test_var_size_buffer_marshal():
    marshal = VarSizeBufferMarshal(UBInt8Marshal)
    assert marshal.sizeof(b"asd") == 4
    assert marshal.min_max_sizeof() == MinMax(1, 256)
    assert marshal.write_to_string(b"ad") == b"\x02ad"
    assert marshal.create_from_string(b"\x03abcadsfadsf") == b"abc"