def _mock_get_range(self, body):
        proto = pb2.GetRangeResponse()

        proto.consumed.capacity_unit.read = 100

        next_primary_key = proto.next_start_primary_key.add()
        next_primary_key.name = 'PK1'
        next_primary_key.value.type = pb2.STRING
        next_primary_key.value.v_string = 'NextStart'
        next_primary_key = proto.next_start_primary_key.add()
        next_primary_key.name = 'PK2'
        next_primary_key.value.type = pb2.INTEGER
        next_primary_key.value.v_int = 101

        row_item = proto.rows.add()
        primary_key = row_item.primary_key_columns.add()
        primary_key.name = 'PK1'
        primary_key.value.type = pb2.STRING
        primary_key.value.v_string = 'Hello'
        primary_key = row_item.primary_key_columns.add()
        primary_key.name = 'PK2'
        primary_key.value.type = pb2.INTEGER
        primary_key.value.v_int = 100

        column = row_item.attribute_columns.add()
        column.name = 'COL1'
        column.value.type = pb2.STRING
        column.value.v_string = 'test'
        column = row_item.attribute_columns.add()
        column.name = 'COL2'
        column.value.type = pb2.INTEGER
        column.value.v_int = 1000

        return proto
示例#2
0
    def _decode_get_range(self, body):
        proto = pb.GetRangeResponse()
        proto.ParseFromString(body)

        capacity_unit = self._parse_capacity_unit(proto.consumed.capacity_unit)

        next_start_pk = None
        row_list = []
        if len(proto.next_start_primary_key) != 0:
            inputStream = PlainBufferInputStream(proto.next_start_primary_key)
            codedInputStream = PlainBufferCodedInputStream(inputStream)
            next_start_pk, att = codedInputStream.read_row()

        if len(proto.rows) != 0:
            inputStream = PlainBufferInputStream(proto.rows)
            codedInputStream = PlainBufferCodedInputStream(inputStream)
            row_list = codedInputStream.read_rows()

        next_token = proto.next_token

        return (capacity_unit, next_start_pk, row_list, next_token), proto