
This method is already deprecated in protobuf, but because of a Chromium patch that's intended to remove [[deprecated]] annotations from C++ accessors for deprecated proto fields, this deprecation annotation was also silenced. Newer versions of protobuf don't use the same macro for deprecation and unconditionally use [[deprecated]]. The preferred replacement is ByteSizeLong(), which returns size_t instead of int. This patch backports that change to Chromium's old version of protobuf. The purpose is to flush out uses of ByteSize() in anticipation of updating Chromium's protobuf, i.e. to slice off a part of the impending roll into a bite sized chunk. It also has the effect of making sure that there are no new ByteSize() calls added between when this CL lands and protobuf is rolled. Bug: 328417294 Change-Id: I9cae7f7558a9799feff2db0f5ea57eb5dd74f305 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6184653 Reviewed-by: Gary Kacmarcik <garykac@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Auto-Submit: Evan Stade <estade@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Commit-Queue: Gary Kacmarcik <garykac@chromium.org> Cr-Commit-Position: refs/heads/main@{#1409869}
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
// Copyright 2014 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifdef UNSAFE_BUFFERS_BUILD
|
|
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
|
|
#pragma allow_unsafe_buffers
|
|
#endif
|
|
|
|
#include "remoting/protocol/message_serialization.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "net/base/io_buffer.h"
|
|
#include "third_party/webrtc/rtc_base/byte_order.h"
|
|
|
|
namespace remoting::protocol {
|
|
|
|
scoped_refptr<net::IOBufferWithSize> SerializeAndFrameMessage(
|
|
const google::protobuf::MessageLite& msg) {
|
|
// Create a buffer with 4 extra bytes. This is used as prefix to write an
|
|
// int32_t of the serialized message size for framing.
|
|
const int kExtraBytes = sizeof(int32_t);
|
|
size_t size = msg.ByteSizeLong() + kExtraBytes;
|
|
scoped_refptr<net::IOBufferWithSize> buffer =
|
|
base::MakeRefCounted<net::IOBufferWithSize>(size);
|
|
rtc::SetBE32(buffer->data(), msg.GetCachedSize());
|
|
msg.SerializeWithCachedSizesToArray(buffer->bytes() + kExtraBytes);
|
|
return buffer;
|
|
}
|
|
|
|
} // namespace remoting::protocol
|