#include "proto_weighing.h" #include namespace NUnifiedAgent::NPW { template inline size_t SizeOf(T value); using CodedOutputStream = google::protobuf::io::CodedOutputStream; template <> inline size_t SizeOf(ui64 value) { return CodedOutputStream::VarintSize64(value); } template <> inline size_t SizeOf(ui32 value) { return CodedOutputStream::VarintSize32(value); } template <> inline size_t SizeOf(i64 value) { return CodedOutputStream::VarintSize64(static_cast(value)); } TFieldLink::TFieldLink(TLengthDelimited* container, bool repeated, size_t keySize) : Container(container) , OuterSize(0) , Repeated(repeated) , KeySize(keySize) { } void TFieldLink::SetValueSize(bool empty, size_t size) { const auto newOuterSize = empty && !Repeated ? 0 : KeySize + static_cast(size); Container->IncSize(newOuterSize - OuterSize); OuterSize = newOuterSize; } TLengthDelimited::TLengthDelimited(const TFMaybe& link) : Link(link) , ByteSize(0) { } void TLengthDelimited::IncSize(int sizeDelta) { ByteSize += sizeDelta; if (Link) { const auto byteSize = static_cast(ByteSize); Link->SetValueSize(false, byteSize + SizeOf(byteSize)); } } template void TRepeatedField::Add(T value) { IncSize(static_cast(SizeOf(value))); } template TNumberField::TNumberField(const TFieldLink& link) : Link(link) { } template void TNumberField::SetValue(T value) { Link.SetValueSize(value == 0, SizeOf(value)); } template TFixedNumberField::TFixedNumberField(const TFieldLink& link) : Link(link) { } template void TFixedNumberField::SetValue() { Link.SetValueSize(false, sizeof(T)); } TStringField::TStringField(const TFieldLink& link) : Link(link) { } void TStringField::SetValue(const TString& value) { Link.SetValueSize(value.Empty(), value.Size() + SizeOf(static_cast(value.Size()))); } template class TNumberField; template class TNumberField; template class TNumberField; template class TFixedNumberField; template class TFixedNumberField; template class TFixedNumberField; template class TRepeatedField; template class TRepeatedField; template class TRepeatedField; }