From kde-commits Mon Nov 28 17:23:10 2016 From: Andreas Hartmetz Date: Mon, 28 Nov 2016 17:23:10 +0000 To: kde-commits Subject: [dferry] serialization: Extend and publicize skipCurrentAggregate to skipCurrentElement. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=148035380006839 Git commit aad29311ca3e6062e17255975138d26c2d554e42 by Andreas Hartmetz. Committed on 28/11/2016 at 17:20. Pushed by ahartmetz into branch 'master'. Extend and publicize skipCurrentAggregate to skipCurrentElement. This is needed somewhere in QtDBus - would be nice to have some tests here but low priority for now. M +18 -13 serialization/arguments.cpp M +3 -1 serialization/arguments.h https://commits.kde.org/dferry/aad29311ca3e6062e17255975138d26c2d554e42 diff --git a/serialization/arguments.cpp b/serialization/arguments.cpp index 1fc78f5..44d5033 100644 --- a/serialization/arguments.cpp +++ b/serialization/arguments.cpp @@ -1703,7 +1703,7 @@ void Arguments::Reader::skipStruct() m_state =3D InvalidData; d->m_error.setCode(Error::ReadWrongType); } else { - skipCurrentAggregate(); + skipCurrentElement(); } } = @@ -1739,7 +1739,7 @@ void Arguments::Reader::skipVariant() m_state =3D InvalidData; d->m_error.setCode(Error::ReadWrongType); } else { - skipCurrentAggregate(); + skipCurrentElement(); } } = @@ -1758,12 +1758,11 @@ void Arguments::Reader::endVariant() advanceState(); } = -void Arguments::Reader::skipCurrentAggregate() +void Arguments::Reader::skipCurrentElement() { - // ### the serialized format has no quick way to do this and it makes = little sense to implement - // a "fast path" just to do this slow thing a little faster, so ju= st use public API! + // ### We could implement a skipping fast path for more aggregates, bu= t it would be a lot of work, so + // until it's proven to be a problem, just reuse what we have. = - assert(m_state =3D=3D BeginStruct || m_state =3D=3D BeginVariant); #ifndef NDEBUG Arguments::IoState stateOnEntry =3D m_state; #endif @@ -1773,8 +1772,9 @@ void Arguments::Reader::skipCurrentAggregate() while (!isDone) { switch(state()) { case Arguments::Finished: - // We should never get here because we should have already qui= t when leaving the main aggregate - // that this was called on, i.e. in state EndStruct / EndVaria= nt, which come before Finished + // Okay, that's a bit weird. I guess the graceful way to handl= e it is do nothing in release + // mode, and explode in debug mode in order to warn the API cl= ient. + // (We could use a warning message facility here, make one?) assert(false); isDone =3D true; break; @@ -1787,7 +1787,6 @@ void Arguments::Reader::skipCurrentAggregate() nestingLevel--; if (!nestingLevel) { assert(stateOnEntry =3D=3D BeginStruct); - isDone =3D true; } break; case Arguments::BeginVariant: @@ -1799,20 +1798,23 @@ void Arguments::Reader::skipCurrentAggregate() nestingLevel--; if (!nestingLevel) { assert(stateOnEntry =3D=3D BeginVariant); - isDone =3D true; } break; case Arguments::BeginArray: skipArray(); break; case Arguments::EndArray: - assert(false); // can't happen because we skip all arrays + assert(stateOnEntry =3D=3D EndArray); // only way this can hap= pen - we gracefully skip EndArray + // and DON'T decrease nestin= gLevel b/c it would go negative. + endArray(); break; case Arguments::BeginDict: skipDict(); break; case Arguments::EndDict: - assert(false); // can't happen because we skip all dicts + assert(stateOnEntry =3D=3D EndDict); // only way this can happ= en - we gracefully "skip" EndDict + // and DON'T decrease nesting= Level b/c it would go negative. + endDict(); break; case Arguments::Boolean: readBoolean(); @@ -1851,7 +1853,7 @@ void Arguments::Reader::skipCurrentAggregate() readSignature(); break; case Arguments::UnixFd: - // TODO + readUnixFd(); break; case Arguments::NeedMoreData: // TODO handle this properly: rewind the state to before the a= ggregate - or get fancy and support @@ -1865,6 +1867,9 @@ void Arguments::Reader::skipCurrentAggregate() isDone =3D true; break; } + if (!nestingLevel) { + isDone =3D true; + } } } = diff --git a/serialization/arguments.h b/serialization/arguments.h index 781baed..a4b28c0 100644 --- a/serialization/arguments.h +++ b/serialization/arguments.h @@ -240,6 +240,9 @@ public: cstring readSignature() { cstring ret(m_u.String.ptr, m_u.String.l= ength); advanceState(); return ret; } uint32 readUnixFd() { uint32 ret =3D m_u.Uint32; advanceState(); r= eturn ret; } = + void skipCurrentElement(); // works on single values and Begin... = states. In the Begin... states, + // skips the whole aggregate. + // Returns primitive type and the raw array data if in BeginArray = state of an array containing only a // primitive type. You must copy the data before destroying the Re= ader or changing its backing store // with replaceData(). @@ -265,7 +268,6 @@ public: void beginArrayOrDict(bool isDict, EmptyArrayOption option); void skipArrayOrDictSignature(bool isDict); void skipArrayOrDict(bool isDict); - void skipCurrentAggregate(); = Private *d; =20