Baloo

positioncodec.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "positioncodec.h"
9#include "positioninfo.h"
10#include "coding.h"
11
12using namespace Baloo;
13
14QByteArray PositionCodec::encode(const QVector<PositionInfo>& list)
15{
16 QByteArray data;
17 QByteArray temporaryStorage;
18
19 for (const PositionInfo& pos : list) {
20 putFixed64(&data, pos.docId);
21 putDifferentialVarInt32(temporaryStorage, &data, pos.positions);
22 }
23
24 return data;
25}
26
27QVector<PositionInfo> PositionCodec::decode(const QByteArray& arr)
28{
29 char* data = const_cast<char*>(arr.data());
30 char* end = data + arr.size();
31
33 while (data < end) {
34 PositionInfo info;
35
36 info.docId = decodeFixed64(data);
37 data += sizeof(quint64);
38 data = getDifferentialVarInt32(data, end, &info.positions);
39 if (!data) {
40 return QVector<PositionInfo>();
41 }
42
43 vec << info;
44 }
45
46 return vec;
47}
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & end()
char * data()
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:54:09 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.