[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [dferry] serialization: Rework getting the current signature of a Reader.
From: Andreas Hartmetz <ahartmetz () gmail ! com>
Date: 2016-11-17 1:34:24
Message-ID: E1c7Baq-0002rY-Rf () code ! kde ! org
[Download RAW message or body]
Git commit 7ab2162e82e41b39063af430ad44d1f21ea437ac by Andreas Hartmetz.
Committed on 17/11/2016 at 00:46.
Pushed by ahartmetz into branch 'master'.
Rework getting the current signature of a Reader.
There are really two use cases, one of which needs a new method.
Also reorder the arguments.h header for more consistent grouping,
no functional change intended there.
M +15 -4 serialization/arguments.cpp
M +41 -40 serialization/arguments.h
http://commits.kde.org/dferry/7ab2162e82e41b39063af430ad44d1f21ea437ac
diff --git a/serialization/arguments.cpp b/serialization/arguments.cpp
index 2919219..731f23b 100644
--- a/serialization/arguments.cpp
+++ b/serialization/arguments.cpp
@@ -949,10 +949,21 @@ bool Arguments::Reader::isInsideEmptyArray() const
cstring Arguments::Reader::currentSignature() const
{
- // ### not sure if determining length like that is the best way, should probably be as similar to
- // libdbus-1 as possible (unless we can do much better).
- return cstring(d->m_signature.ptr,
- std::max(uint32(0), std::min(d->m_signature.length, d->m_signaturePosition)));
+ return d->m_signature;
+}
+
+cstring Arguments::Reader::currentSingleCompleteTypeSignature() const
+{
+ const uint32 startingLength = d->m_signature.length - d->m_signaturePosition;
+ cstring sigCopy = { d->m_signature.ptr + d->m_signaturePosition, startingLength };
+ Nesting nest;
+ if (!parseSingleCompleteType(&sigCopy, &nest)) {
+ // the signature should have been validated before, but e.g. in Finished state this may happen
+ return cstring();
+ }
+ sigCopy.ptr = d->m_signature.ptr + d->m_signaturePosition;
+ sigCopy.length = startingLength - sigCopy.length;
+ return sigCopy;
}
void Arguments::Reader::replaceData(chunk data)
diff --git a/serialization/arguments.h b/serialization/arguments.h
index 4081e26..5d86866 100644
--- a/serialization/arguments.h
+++ b/serialization/arguments.h
@@ -37,53 +37,19 @@ class Message;
class DFERRY_EXPORT Arguments
{
public:
- Arguments(); // constructs an empty argument list
- // constructs an argument list to deserialize data in @p data with signature @p signature;
- // if memOwnership is non-null, this means that signature and data's memory is contained in
- // a malloc()ed block starting at memOwnership, and ~Arguments will free it.
- // Otherwise, the instance assumes that @p signature and @p data live in "borrowed" memory and
- // you need to make sure that the memory lives as long as the Arguments.
- // (A notable user of this is Message - you can only get a const ref to its internal Arguments
- // so you need to copy to take the Arguments away from the Message, which copies out of the
- // borrowed memory into heap memory so the copy is safe)
- // The copy contructor and assignment operator will always copy the data, so copying is safe
- // regarding memory correctness but has a significant performance impact.
- Arguments(byte *memOwnership, cstring signature, chunk data, bool isByteSwapped = false);
-
- // use these wherever possible if you care at all about efficiency!!
- Arguments(Arguments &&other);
- Arguments &operator=(Arguments &&other);
-
- // copying needs special treatment due to the d-pointer
- Arguments(const Arguments &other);
- Arguments &operator=(const Arguments &other);
-
- ~Arguments();
-
- // error (if any) propagates to Message, so it is still available later
- Error error() const;
-
- std::string prettyPrint() const;
-
- cstring signature() const;
- chunk data() const;
-
enum SignatureType
{
MethodSignature = 0,
VariantSignature
};
- static bool isStringValid(cstring string);
- static bool isObjectPathValid(cstring objectPath);
- static bool isObjectPathElementValid(cstring pathElement);
- static bool isSignatureValid(cstring signature, SignatureType type = MethodSignature);
-
- enum {
+ enum
+ {
MaxSignatureLength = 255
};
- enum IoState {
+ enum IoState
+ {
// "exceptional" states
NotStarted = 0,
Finished,
@@ -124,8 +90,43 @@ public:
UnixFd
};
-private:
+ Arguments(); // constructs an empty argument list
+ // constructs an argument list to deserialize data in @p data with signature @p signature;
+ // if memOwnership is non-null, this means that signature and data's memory is contained in
+ // a malloc()ed block starting at memOwnership, and ~Arguments will free it.
+ // Otherwise, the instance assumes that @p signature and @p data live in "borrowed" memory and
+ // you need to make sure that the memory lives as long as the Arguments.
+ // (A notable user of this is Message - you can only get a const ref to its internal Arguments
+ // so you need to copy to take the Arguments away from the Message, which copies out of the
+ // borrowed memory into heap memory so the copy is safe)
+ // The copy contructor and assignment operator will always copy the data, so copying is safe
+ // regarding memory correctness but has a significant performance impact.
+ Arguments(byte *memOwnership, cstring signature, chunk data, bool isByteSwapped = false);
+
+ // use these wherever possible if you care at all about efficiency!!
+ Arguments(Arguments &&other);
+ Arguments &operator=(Arguments &&other);
+
+ // copying needs special treatment due to the d-pointer
+ Arguments(const Arguments &other);
+ Arguments &operator=(const Arguments &other);
+
+ ~Arguments();
+
+ // error (if any) propagates to Message, so it is still available later
+ Error error() const;
+ std::string prettyPrint() const;
+
+ cstring signature() const;
+ chunk data() const;
+
+ static bool isStringValid(cstring string);
+ static bool isObjectPathValid(cstring objectPath);
+ static bool isObjectPathElementValid(cstring pathElement);
+ static bool isSignatureValid(cstring signature, SignatureType type = MethodSignature);
+
+private:
struct podCstring // Same as cstring but without ctor.
// Can't put the cstring type into a union because it has a constructor :/
{
@@ -148,7 +149,6 @@ private:
} DataUnion;
public:
-
// error handling is done by asking state() or isError(), not by method return values.
// occasionally looking at isError() is less work than checking every call.
class DFERRY_EXPORT Reader
@@ -171,6 +171,7 @@ public:
cstring stateString() const;
bool isInsideEmptyArray() const;
cstring currentSignature() const; // current signature, either main signature or current variant
+ cstring currentSingleCompleteTypeSignature() const;
// HACK call this in NeedMoreData state when more data has been added; this replaces m_data
// WARNING: calling replaceData() invalidates copies (if any) of this Reader
void replaceData(chunk data);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic