Heart
1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
streambase.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2018-2025 QuasarApp.
3
* Distributed under the lgplv3 software license, see the accompanying
4
* Everyone is permitted to copy and distribute verbatim copies
5
* of this license document, but changing it is not allowed.
6
*/
7
8
#include "
streambase.h
"
9
10
#include <QDataStream>
11
#include <QIODevice>
12
#include <QSharedPointer>
13
14
namespace
QH
{
15
16
17
StreamBase::StreamBase
() =
default
;
18
19
StreamBase::~StreamBase
() =
default
;
20
21
bool
StreamBase::fromBytes
(
const
QByteArray &data) {
22
if
(data.isEmpty())
23
return
false
;
24
25
QDataStream stream(data);
26
27
if
(
parsingVersion
()) {
28
stream.setVersion(
parsingVersion
());
29
}
30
31
fromStream
(stream);
32
33
Q_ASSERT_X(isValid(), __FUNCTION__,
"Parsing error detected, check your parsing chain"
);
34
35
return
true
;
36
}
37
38
QByteArray
StreamBase::toBytes
()
const
{
39
QByteArray res;
40
QDataStream stream(&res, QIODevice::WriteOnly);
41
42
if
(
parsingVersion
()) {
43
stream.setVersion(
parsingVersion
());
44
}
45
46
Q_ASSERT_X(isValid(), __FUNCTION__,
"Parsing error detected, check your parsing chain"
);
47
48
toStream
(stream);
49
return
res;
50
}
51
52
bool
StreamBase::fromBase64
(
const
QString &data) {
53
return
fromBase64
(data.toLatin1());
54
}
55
56
bool
StreamBase::fromBase64
(
const
QByteArray &data) {
57
return
fromBytes
(QByteArray::fromBase64(data, QByteArray::Base64UrlEncoding));
58
}
59
60
QByteArray
StreamBase::toBase64
()
const
{
61
return
toBytes
().toBase64(QByteArray::Base64UrlEncoding);
62
}
63
64
int
StreamBase::parsingVersion
()
const
{
65
return
0;
66
}
67
68
unsigned
int
StreamBase::typeId
()
const
{
69
return
typeid
(
this
).hash_code();
70
}
71
72
QDataStream &
operator<<
(QDataStream &stream,
const
StreamBase
&obj) {
73
74
Q_ASSERT_X(obj.isValid(), __FUNCTION__,
"Parsing error detected, check your parsing chain"
);
75
76
return
(&obj)->toStream(stream);
77
}
78
79
QDataStream &
operator>>
(QDataStream &stream,
StreamBase
&obj) {
80
(&obj)->
fromStream
(stream);
81
Q_ASSERT_X(obj.isValid(), __FUNCTION__,
"Parsing error detected, check your parsing chain"
);
82
return
stream;
83
}
84
85
}
QH::StreamBase::typeId
virtual unsigned int typeId() const
typeId This method return id of type.
Definition
streambase.cpp:68
QH::StreamBase::parsingVersion
virtual int parsingVersion() const
parsingVersion this method return parsing version of Qt. By Default is 0 (last available parsing)....
Definition
streambase.cpp:64
QH::StreamBase::toBytes
QByteArray toBytes() const
toBytes This method convert a current object to bytes array.
Definition
streambase.cpp:38
QH::StreamBase::operator>>
HEARTSHARED_EXPORT friend QDataStream & operator>>(QDataStream &stream, StreamBase &obj)
This is wraper over fromStream. For see more information see toStream method.
Definition
streambase.cpp:79
QH::StreamBase::fromStream
virtual QDataStream & fromStream(QDataStream &stream)=0
fromStream This method should be read all bytes from the stream object and full the current object.
QH::StreamBase::toStream
virtual QDataStream & toStream(QDataStream &stream) const =0
fromStream This method should be write all members of the current object to the stream object.
QH::StreamBase::fromBase64
bool fromBase64(const QString &data)
fromBase64 This method provide initialization of object from the base64 string.
Definition
streambase.cpp:52
QH::StreamBase::operator<<
HEARTSHARED_EXPORT friend QDataStream & operator<<(QDataStream &stream, const StreamBase &obj)
This is wrapper over toStream.
Definition
streambase.cpp:72
QH::StreamBase::StreamBase
StreamBase()
QH::StreamBase::~StreamBase
virtual ~StreamBase()
QH::StreamBase::toBase64
QByteArray toBase64() const
toBase64 This method convert a current object to the base64 string.
Definition
streambase.cpp:60
QH::StreamBase::fromBytes
bool fromBytes(const QByteArray &dataz)
fromBytes This method provide initialization of object from byte array.
Definition
streambase.cpp:21
QH
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition
heart.cpp:13
streambase.h
src
public
streambase.cpp
Generated by
1.18.0