Baloo

coding.h
1/*
2 This file is part of the KDE Baloo project.
3 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
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
15namespace 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
23inline 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 */
34void putDifferentialVarInt32(QByteArray &temporaryStorage, QByteArray* dst, const QVector<quint32>& values);
35char* getDifferentialVarInt32(char* input, char* limit, QVector<quint32>* values);
36extern const char* getVarint32Ptr(const char* p, const char* limit, quint32* v);
37
38inline 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
47extern char* getVarint32PtrFallback(char* p, char* limit, quint32* value);
48inline 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
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QByteArray & append(QByteArrayView data)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:51:50 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.