amessage.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
  3. *
  4. * This file is part of Embedded Proto.
  5. *
  6. * Embedded Proto is open source software: you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as published
  8. * by the Free Software Foundation, version 3 of the license.
  9. *
  10. * Embedded Proto is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. * For commercial and closed source application please visit:
  19. * <https://EmbeddedProto.com/license/>.
  20. *
  21. * Embedded AMS B.V.
  22. * Info:
  23. * info at EmbeddedProto dot com
  24. *
  25. * Postal address:
  26. * Johan Huizingalaan 763a
  27. * 1066 VH, Amsterdam
  28. * the Netherlands
  29. */
  30. // This file is generated. Please do not edit!
  31. #ifndef _AMESSAGE_H_
  32. #define _AMESSAGE_H_
  33. #include <cstdint>
  34. #include <MessageInterface.h>
  35. #include <WireFormatter.h>
  36. #include <Fields.h>
  37. #include <MessageSizeCalculator.h>
  38. #include <ReadBufferSection.h>
  39. #include <RepeatedFieldFixedSize.h>
  40. #include <FieldStringBytes.h>
  41. #include <Errors.h>
  42. // Include external proto definitions
  43. class AMessage final: public ::EmbeddedProto::MessageInterface
  44. {
  45. public:
  46. AMessage() :
  47. a_(0),
  48. b_(0)
  49. {
  50. };
  51. ~AMessage() override = default;
  52. enum class id
  53. {
  54. NOT_SET = 0,
  55. A = 1,
  56. B = 2
  57. };
  58. AMessage& operator=(const AMessage& rhs)
  59. {
  60. set_a(rhs.get_a());
  61. set_b(rhs.get_b());
  62. return *this;
  63. }
  64. inline void clear_a() { a_.clear(); }
  65. inline void set_a(const EmbeddedProto::int32& value) { a_ = value; }
  66. inline void set_a(const EmbeddedProto::int32&& value) { a_ = value; }
  67. inline EmbeddedProto::int32& mutable_a() { return a_; }
  68. inline const EmbeddedProto::int32& get_a() const { return a_; }
  69. inline EmbeddedProto::int32::FIELD_TYPE a() const { return a_.get(); }
  70. inline void clear_b() { b_.clear(); }
  71. inline void set_b(const EmbeddedProto::int32& value) { b_ = value; }
  72. inline void set_b(const EmbeddedProto::int32&& value) { b_ = value; }
  73. inline EmbeddedProto::int32& mutable_b() { return b_; }
  74. inline const EmbeddedProto::int32& get_b() const { return b_; }
  75. inline EmbeddedProto::int32::FIELD_TYPE b() const { return b_.get(); }
  76. ::EmbeddedProto::Error serialize(::EmbeddedProto::WriteBufferInterface& buffer) const final
  77. {
  78. ::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
  79. if((0 != a_.get()) && (::EmbeddedProto::Error::NO_ERRORS == return_value))
  80. {
  81. return_value = a_.serialize_with_id(static_cast<uint32_t>(id::A), buffer);
  82. }
  83. if((0 != b_.get()) && (::EmbeddedProto::Error::NO_ERRORS == return_value))
  84. {
  85. return_value = b_.serialize_with_id(static_cast<uint32_t>(id::B), buffer);
  86. }
  87. return return_value;
  88. };
  89. ::EmbeddedProto::Error deserialize(::EmbeddedProto::ReadBufferInterface& buffer) final
  90. {
  91. ::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
  92. ::EmbeddedProto::WireFormatter::WireType wire_type;
  93. uint32_t id_number = 0;
  94. ::EmbeddedProto::Error tag_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, wire_type, id_number);
  95. while((::EmbeddedProto::Error::NO_ERRORS == return_value) && (::EmbeddedProto::Error::NO_ERRORS == tag_value))
  96. {
  97. switch(id_number)
  98. {
  99. case static_cast<uint32_t>(id::A):
  100. {
  101. if(::EmbeddedProto::WireFormatter::WireType::VARINT == wire_type)
  102. {
  103. return_value = a_.deserialize(buffer);
  104. }
  105. else
  106. {
  107. // Wire type does not match field.
  108. return_value = ::EmbeddedProto::Error::INVALID_WIRETYPE;
  109. }
  110. break;
  111. }
  112. case static_cast<uint32_t>(id::B):
  113. {
  114. if(::EmbeddedProto::WireFormatter::WireType::VARINT == wire_type)
  115. {
  116. return_value = b_.deserialize(buffer);
  117. }
  118. else
  119. {
  120. // Wire type does not match field.
  121. return_value = ::EmbeddedProto::Error::INVALID_WIRETYPE;
  122. }
  123. break;
  124. }
  125. default:
  126. break;
  127. }
  128. if(::EmbeddedProto::Error::NO_ERRORS == return_value)
  129. {
  130. // Read the next tag.
  131. tag_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, wire_type, id_number);
  132. }
  133. }
  134. // When an error was detect while reading the tag but no other errors where found, set it in the return value.
  135. if((::EmbeddedProto::Error::NO_ERRORS == return_value)
  136. && (::EmbeddedProto::Error::NO_ERRORS != tag_value)
  137. && (::EmbeddedProto::Error::END_OF_BUFFER != tag_value)) // The end of the buffer is not an array in this case.
  138. {
  139. return_value = tag_value;
  140. }
  141. return return_value;
  142. };
  143. void clear() final
  144. {
  145. clear_a();
  146. clear_b();
  147. }
  148. private:
  149. EmbeddedProto::int32 a_;
  150. EmbeddedProto::int32 b_;
  151. };
  152. #endif // _AMESSAGE_H_