def write(self, io: ByteIo, array: List[bytes]) -> None:
        if array is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        io.write_size(len(array), self.reserved_byte)
        for b in array:
            io.write(b)
    def write(self, io: ByteIo, array: List[T]) -> None:
        if array is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        io.write_size(len(array), self.reserved_byte)
        for item in array:
            self.codec.write(io, item)
Example #3
0
    def write(self, io: ByteIo, array: List[str]) -> None:
        if array is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        encoded: bytes = "".join(array).encode("UTF-8")
        io.write_size(len(encoded), self.reserved_byte)
        io.write(encoded)
    def write(self, io: ByteIo, array: List[int]) -> None:
        if array is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        io.write_size(len(array), self.reserved_byte)

        for element in array:
            io.write1(element >> 8)
            io.write1(element)
Example #5
0
    def write(self, io: ByteIo, collection: Set[T]) -> None:
        if collection is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        io.write_size(len(collection), self.reserved_byte)

        for value in collection:
            codec: Codec = self.value_codec
            if codec is None:
                codec = self.codec_cache.codec_for(value)
            codec.write(io, value)
    def write(self, io: ByteIo, collection: str) -> None:
        if collection is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        data: bytes = collection.encode("UTF-8")
        length: int = len(data)
        if length < self.size_1 - self.optimized_from:
            io.write(to_byte((self.optimized_from + length) & 0xFF))
        else:
            io.write_size(length, to_byte(self.size_1))
        if length != 0:
            io.write(data)
Example #7
0
    def write(self, io: ByteIo, dictionary: Dict[T, U]) -> None:
        if dictionary is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        io.write_size(len(dictionary), self.reserved_byte)

        for key, value in dictionary.items():
            k_codec: Codec[T] = self.key_codec
            if k_codec is None:
                k_codec = self.codec_cache.codec_for(key)

            v_codec: Codec[U] = self.value_codec
            if v_codec is None:
                v_codec = self.codec_cache.codec_for(value)

            k_codec.write(io, key)
            v_codec.write(io, value)
    def write(self, io: ByteIo, array: List[bool]) -> None:
        if array is None:
            io.write(NoneCodec.NONE_VALUE)
            return

        io.write_size(len(array), self.reserved_byte)
        current_count: int = 0
        value: int = 0

        for element in array:
            bool_int: int = 0
            if element:
                bool_int = 1
            value = value << 1 | bool_int
            if current_count == 7:
                current_count = 0
                io.write1(value)
            else:
                current_count = current_count + 1
        if current_count > 0:
            io.write1(value << (8 - current_count))