SerializedDataIterator.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright The kNet Project.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. */
  11. #pragma once
  12. /** @file SerializedDataIterator.h
  13. @brief The SerializedDataIterator class. */
  14. #include "SharedPtr.h"
  15. #include "MessageListParser.h"
  16. namespace kNet
  17. {
  18. class SerializedDataIterator : public RefCountable
  19. {
  20. public:
  21. SerializedDataIterator(const SerializedMessageDesc &desc_)
  22. :desc(desc_)
  23. {
  24. ResetTraversal();
  25. }
  26. BasicSerializedDataType NextElementType() const;
  27. const SerializedElementDesc *NextElementDesc() const;
  28. void ProceedToNextVariable();
  29. void ProceedNVariables(int count);
  30. /// Sets the number of instances in a varying element. When iterating over
  31. /// the message to insert data into serialized form, this information needs
  32. /// to be passed to this iterator in order to continue.
  33. void SetVaryingElemSize(u32 count);
  34. void ResetTraversal();
  35. private:
  36. struct ElemInfo
  37. {
  38. /// The element we are accessing next.
  39. SerializedElementDesc *elem;
  40. /// The index of the elem we are accessing next.
  41. int nextElem;
  42. /// The index of the instance we are accessing next.
  43. int nextIndex;
  44. /// The total number of instances of this element we are accessing.
  45. int count;
  46. /// If this element is a dynamic count -one, then this tracks whether the count has been passed in.
  47. bool dynamicCountSpecified;
  48. };
  49. void ProceedToNextElement();
  50. void DescendIntoStructure();
  51. /// Stores the tree traversal progress.
  52. std::vector<ElemInfo> currentElementStack;
  53. /// The type of the message we are building.
  54. const SerializedMessageDesc &desc;
  55. void operator =(const SerializedDataIterator&);
  56. SerializedDataIterator(const SerializedDataIterator&);
  57. };
  58. } // ~kNet