| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- /*
- * Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
- *
- * This file is part of Embedded Proto.
- *
- * Embedded Proto is open source software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published
- * by the Free Software Foundation, version 3 of the license.
- *
- * Embedded Proto is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
- *
- * For commercial and closed source application please visit:
- * <https://EmbeddedProto.com/license/>.
- *
- * Embedded AMS B.V.
- * Info:
- * info at EmbeddedProto dot com
- *
- * Postal address:
- * Johan Huizingalaan 763a
- * 1066 VH, Amsterdam
- * the Netherlands
- */
- #include "Fields.h"
- #include "MessageSizeCalculator.h"
- namespace EmbeddedProto
- {
- uint32_t Field::serialized_size() const
- {
- ::EmbeddedProto::MessageSizeCalculator calcBuffer;
- this->serialize(calcBuffer);
- return calcBuffer.get_size();
- }
- bool int32::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool int64::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool uint32::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool uint64::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool sint32::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool sint64::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool boolean::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::VARINT), buffer) && serialize(buffer);
- }
- bool fixed32::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::FIXED32), buffer) && serialize(buffer);
- }
- bool fixed64::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::FIXED64), buffer) && serialize(buffer);
- }
- bool sfixed32::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::FIXED32), buffer) && serialize(buffer);
- }
- bool sfixed64::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::FIXED64), buffer) && serialize(buffer);
- }
- bool floatfixed::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::FIXED32), buffer) && serialize(buffer);
- }
- bool doublefixed::serialize_with_id(uint32_t field_number, WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::MakeTag(field_number, WireFormatter::WireType::FIXED64), buffer) && serialize(buffer);
- }
- bool int32::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(static_cast<uint32_t>(get()), buffer);
- }
- bool int64::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(static_cast<uint64_t>(get()), buffer);
- }
- bool uint32::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(get(), buffer);
- }
- bool uint64::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(get(), buffer);
- }
- bool sint32::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::ZigZagEncode(get()), buffer);
- }
- bool sint64::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerializeVarint(WireFormatter::ZigZagEncode(get()), buffer);
- }
- bool boolean::serialize(WriteBufferInterface& buffer) const
- {
- return buffer.push(get() ? 0x01 : 0x00);
- }
- bool fixed32::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerialzieFixedNoTag(get(), buffer);
- }
- bool fixed64::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerialzieFixedNoTag(get(), buffer);
- }
- bool sfixed32::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerialzieSFixedNoTag(get(), buffer);
- }
- bool sfixed64::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerialzieSFixedNoTag(get(), buffer);
- }
- bool floatfixed::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerialzieFloatNoTag(get(), buffer);
- }
- bool doublefixed::serialize(WriteBufferInterface& buffer) const
- {
- return WireFormatter::SerialzieDoubleNoTag(get(), buffer);
- }
- bool int32::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeInt(buffer, get());
- }
- bool int64::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeInt(buffer, get());
- }
- bool uint32::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeUInt(buffer, get());
- }
- bool uint64::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeUInt(buffer, get());
- }
- bool sint32::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeSInt(buffer, get());
- }
- bool sint64::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeSInt(buffer, get());
- }
- bool boolean::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeBool(buffer, get());
- }
- bool fixed32::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeFixed(buffer, get());
- }
- bool fixed64::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeFixed(buffer, get());
- }
- bool sfixed32::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeSFixed(buffer, get());
- }
- bool sfixed64::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeSFixed(buffer, get());
- }
- bool floatfixed::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeFloat(buffer, get());
- }
- bool doublefixed::deserialize(ReadBufferInterface& buffer)
- {
- return WireFormatter::DeserializeDouble(buffer, get());
- }
-
- } // End of namespace EmbeddedProto
|