Exemplo n.º 1
0
    def decode(msg):
        from hazelcast.sql import SqlColumnType, _SqlPage

        # begin frame
        msg.next_frame()

        # read the "last" flag
        is_last = LE_INT8.unpack_from(msg.next_frame().buf, 0)[0] == 1

        # read column types
        column_type_ids = ListIntegerCodec.decode(msg)
        column_count = len(column_type_ids)

        # read columns
        columns = [None] * column_count

        for i in range(column_count):
            column_type_id = column_type_ids[i]

            if column_type_id == SqlColumnType.VARCHAR:
                columns[i] = ListMultiFrameCodec.decode_contains_nullable(
                    msg, StringCodec.decode)
            elif column_type_id == SqlColumnType.BOOLEAN:
                columns[i] = ListCNBooleanCodec.decode(msg)
            elif column_type_id == SqlColumnType.TINYINT:
                columns[i] = ListCNByteCodec.decode(msg)
            elif column_type_id == SqlColumnType.SMALLINT:
                columns[i] = ListCNShortCodec.decode(msg)
            elif column_type_id == SqlColumnType.INTEGER:
                columns[i] = ListCNIntegerCodec.decode(msg)
            elif column_type_id == SqlColumnType.BIGINT:
                columns[i] = ListCNLongCodec.decode(msg)
            elif column_type_id == SqlColumnType.REAL:
                columns[i] = ListCNFloatCodec.decode(msg)
            elif column_type_id == SqlColumnType.DOUBLE:
                columns[i] = ListCNDoubleCodec.decode(msg)
            elif column_type_id == SqlColumnType.DATE:
                columns[i] = ListCNLocalDateCodec.decode(msg)
            elif column_type_id == SqlColumnType.TIME:
                columns[i] = ListCNLocalTimeCodec.decode(msg)
            elif column_type_id == SqlColumnType.TIMESTAMP:
                columns[i] = ListCNLocalDateTimeCodec.decode(msg)
            elif column_type_id == SqlColumnType.TIMESTAMP_WITH_TIME_ZONE:
                columns[i] = ListCNOffsetDateTimeCodec.decode(msg)
            elif column_type_id == SqlColumnType.DECIMAL:
                columns[i] = ListMultiFrameCodec.decode_contains_nullable(
                    msg, BigDecimalCodec.decode)
            elif column_type_id == SqlColumnType.NULL:
                frame = msg.next_frame()
                size = FixSizedTypesCodec.decode_int(frame.buf, 0)
                column = [None for _ in range(size)]
                columns[i] = column
            elif column_type_id == SqlColumnType.OBJECT:
                columns[i] = ListMultiFrameCodec.decode_contains_nullable(
                    msg, DataCodec.decode)
            else:
                raise ValueError("Unknown type %s" % column_type_id)

        CodecUtil.fast_forward_to_end_frame(msg)

        return _SqlPage(column_type_ids, columns, is_last)
Exemplo n.º 2
0
 def decode_byte(buf, offset):
     return LE_INT8.unpack_from(buf, offset)[0]
Exemplo n.º 3
0
 def decode_boolean(buf, offset):
     return LE_INT8.unpack_from(buf, offset)[0] == 1
Exemplo n.º 4
0
 def encode_byte(buf, offset, value):
     LE_INT8.pack_into(buf, offset, value)
Exemplo n.º 5
0
 def encode_boolean(buf, offset, value):
     if value:
         LE_INT8.pack_into(buf, offset, 1)
     else:
         LE_INT8.pack_into(buf, offset, 0)