qtprotobuftypes.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #pragma once
  26. #include <QList>
  27. #include <QMetaType>
  28. namespace qtprotobuf {
  29. enum WireTypes {
  30. UnknownWireType = -1,
  31. Varint = 0,
  32. Fixed64 = 1,
  33. LengthDelimited = 2,
  34. Fixed32 = 5
  35. };
  36. constexpr int NotUsedFieldIndex = -1;
  37. template<typename T, int = 0>
  38. struct transparent {
  39. transparent(T t = T()) : _t(t){}
  40. T _t;
  41. operator T&(){ return _t; }
  42. operator T() const { return _t; }
  43. };
  44. using int32 = int32_t;
  45. using int64 = int64_t;
  46. using uint32 = uint32_t;
  47. using uint64 = uint64_t;
  48. using sint32 = transparent<int32_t>;
  49. using sint64 = transparent<int64_t>;
  50. using fixed32 = transparent<uint32_t, 1>;
  51. using fixed64 = transparent<uint64_t, 1>;
  52. using sfixed32 = transparent<int32_t, 1>;
  53. using sfixed64 = transparent<int64_t, 1>;
  54. using int32List = QList<int32>;
  55. using int64List = QList<int64>;
  56. using uint32List = QList<uint32>;
  57. using uint64List = QList<uint64>;
  58. using sint32List = QList<sint32>;
  59. using sint64List = QList<sint64>;
  60. using fixed32List = QList<fixed32>;
  61. using fixed64List = QList<fixed64>;
  62. using sfixed32List = QList<sfixed32>;
  63. using sfixed64List = QList<sfixed64>;
  64. using FloatList = QList<float>;
  65. using DoubleList = QList<double>;
  66. }
  67. Q_DECLARE_METATYPE(qtprotobuf::int32)
  68. Q_DECLARE_METATYPE(qtprotobuf::int64)
  69. Q_DECLARE_METATYPE(qtprotobuf::sint32)
  70. Q_DECLARE_METATYPE(qtprotobuf::sint64)
  71. Q_DECLARE_METATYPE(qtprotobuf::uint32)
  72. Q_DECLARE_METATYPE(qtprotobuf::uint64)
  73. Q_DECLARE_METATYPE(qtprotobuf::fixed32)
  74. Q_DECLARE_METATYPE(qtprotobuf::fixed64)
  75. Q_DECLARE_METATYPE(qtprotobuf::sfixed32)
  76. Q_DECLARE_METATYPE(qtprotobuf::sfixed64)
  77. Q_DECLARE_METATYPE(qtprotobuf::int32List)
  78. Q_DECLARE_METATYPE(qtprotobuf::int64List)
  79. Q_DECLARE_METATYPE(qtprotobuf::sint32List)
  80. Q_DECLARE_METATYPE(qtprotobuf::sint64List)
  81. Q_DECLARE_METATYPE(qtprotobuf::uint32List)
  82. Q_DECLARE_METATYPE(qtprotobuf::uint64List)
  83. Q_DECLARE_METATYPE(qtprotobuf::fixed32List)
  84. Q_DECLARE_METATYPE(qtprotobuf::fixed64List)
  85. Q_DECLARE_METATYPE(qtprotobuf::sfixed32List)
  86. Q_DECLARE_METATYPE(qtprotobuf::sfixed64List)
  87. Q_DECLARE_METATYPE(qtprotobuf::FloatList)
  88. Q_DECLARE_METATYPE(qtprotobuf::DoubleList)