Baloo

positioncodec.cpp
1 /*
2  This file is part of the KDE Baloo Project
3  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
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 
12 using namespace Baloo;
13 
14 QByteArray 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 
27 QVector<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
int size() const const
const QList< QKeySequence > & end()
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.