Baloo

coding.h
1 /*
2  This file is part of the KDE Baloo project.
3  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
4  SPDX-FileCopyrightText: 2011 The LevelDB Authors. All rights reserved.
5 
6  SPDX-License-Identifier: LGPL-2.1-or-later AND BSD-3-Clause
7 */
8 
9 #ifndef BALOO_STORAGE_LEVELDB_UTIL_CODING_H
10 #define BALOO_STORAGE_LEVELDB_UTIL_CODING_H
11 
12 #include <QByteArray>
13 #include <QVector>
14 
15 namespace Baloo {
16 
17 /*
18  * This is a stripped down version of various encode/decode functions for
19  * 32/64 bit fixed/variable data types. If you need other functions than the
20  * ones available here you can take a look in the git baloo history
21  */
22 
23 inline void putFixed64(QByteArray* dst, quint64 value)
24 {
25  dst->append(reinterpret_cast<const char*>(&value), sizeof(value));
26 }
27 
28 /*
29  * temporaryStorage is used to avoid an internal allocation of a temporary
30  * buffer which is needed for serialization. Since this function is normally
31  * called inside a loop, the temporary buffer must not be reallocated on every
32  * call.
33  */
34 void putDifferentialVarInt32(QByteArray &temporaryStorage, QByteArray* dst, const QVector<quint32>& values);
35 char* getDifferentialVarInt32(char* input, char* limit, QVector<quint32>* values);
36 extern const char* getVarint32Ptr(const char* p, const char* limit, quint32* v);
37 
38 inline quint64 decodeFixed64(const char* ptr)
39 {
40  // Load the raw bytes
41  quint64 result;
42  memcpy(&result, ptr, sizeof(result)); // gcc optimizes this to a plain load
43  return result;
44 }
45 
46 // Internal routine for use by fallback path of GetVarint32Ptr
47 extern char* getVarint32PtrFallback(char* p, char* limit, quint32* value);
48 inline char* getVarint32Ptr(char* p, char* limit, quint32* value)
49 {
50  if (p >= limit) {
51  return nullptr;
52  }
53 
54  quint32 result = *(reinterpret_cast<const unsigned char*>(p));
55  if ((result & 128) == 0) {
56  *value = result;
57  return p + 1;
58  }
59 
60  return getVarint32PtrFallback(p, limit, value);
61 }
62 
63 }
64 
65 #endif
QByteArray & append(char ch)
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
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.