Skip to content

Commit 6e1df1c

Browse files
HDFS-15947. Replace deprecated protobuf APIs (#2856)
1 parent 9e2d5d6 commit 6e1df1c

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/util.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ std::string SerializeDelimitedProtobufMessage(const ::google::protobuf::MessageL
5656

5757
std::string buf;
5858

59-
int size = msg->ByteSize();
59+
const auto size = msg->ByteSizeLong();
6060
buf.reserve(pbio::CodedOutputStream::VarintSize32(size) + size);
6161
pbio::StringOutputStream ss(&buf);
6262
pbio::CodedOutputStream os(&ss);
@@ -68,9 +68,9 @@ std::string SerializeDelimitedProtobufMessage(const ::google::protobuf::MessageL
6868
return buf;
6969
}
7070

71-
int DelimitedPBMessageSize(const ::google::protobuf::MessageLite *msg) {
72-
size_t size = msg->ByteSize();
73-
return ::google::protobuf::io::CodedOutputStream::VarintSize32(size) + size;
71+
size_t DelimitedPBMessageSize(const ::google::protobuf::MessageLite *msg) {
72+
const auto size = msg->ByteSizeLong();
73+
return ::google::protobuf::io::CodedOutputStream::VarintSize64(size) + size;
7474
}
7575

7676
std::shared_ptr<std::string> GetRandomClientName() {

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Status ToStatus(const boost::system::error_code &ec);
4747

4848
// Determine size of buffer that needs to be allocated in order to serialize msg
4949
// in delimited format
50-
int DelimitedPBMessageSize(const ::google::protobuf::MessageLite *msg);
50+
size_t DelimitedPBMessageSize(const ::google::protobuf::MessageLite *msg);
5151

5252
// Construct msg from the input held in the CodedInputStream
5353
// return false on failure, otherwise return true

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/request.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static const int kNoRetry = -1;
4747
static void AddHeadersToPacket(std::string *res,
4848
std::initializer_list<const pb::MessageLite *> headers,
4949
const std::string *payload) {
50-
int len = 0;
50+
size_t len = 0;
5151
std::for_each(
5252
headers.begin(), headers.end(),
5353
[&len](const pb::MessageLite *v) { len += DelimitedPBMessageSize(v); });
@@ -68,7 +68,7 @@ static void AddHeadersToPacket(std::string *res,
6868

6969
std::for_each(
7070
headers.begin(), headers.end(), [&buf](const pb::MessageLite *v) {
71-
buf = pbio::CodedOutputStream::WriteVarint32ToArray(v->ByteSize(), buf);
71+
buf = pbio::CodedOutputStream::WriteVarint64ToArray(v->ByteSizeLong(), buf);
7272
buf = v->SerializeWithCachedSizesToArray(buf);
7373
});
7474

@@ -78,13 +78,13 @@ static void AddHeadersToPacket(std::string *res,
7878
}
7979

8080
static void ConstructPayload(std::string *res, const pb::MessageLite *header) {
81-
int len = DelimitedPBMessageSize(header);
81+
const auto len = DelimitedPBMessageSize(header);
8282
res->reserve(len);
8383
pbio::StringOutputStream ss(res);
8484
pbio::CodedOutputStream os(&ss);
8585
uint8_t *buf = os.GetDirectBufferForNBytesAndAdvance(len);
8686
assert(buf);
87-
buf = pbio::CodedOutputStream::WriteVarint32ToArray(header->ByteSize(), buf);
87+
buf = pbio::CodedOutputStream::WriteVarint64ToArray(header->ByteSizeLong(), buf);
8888
buf = header->SerializeWithCachedSizesToArray(buf);
8989
}
9090

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/rpc_connection_impl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace ::std::placeholders;
3636
static void AddHeadersToPacket(
3737
std::string *res, std::initializer_list<const pb::MessageLite *> headers,
3838
const std::string *payload) {
39-
int len = 0;
39+
size_t len = 0;
4040
std::for_each(
4141
headers.begin(), headers.end(),
4242
[&len](const pb::MessageLite *v) { len += DelimitedPBMessageSize(v); });
@@ -57,7 +57,7 @@ static void AddHeadersToPacket(
5757

5858
std::for_each(
5959
headers.begin(), headers.end(), [&buf](const pb::MessageLite *v) {
60-
buf = pbio::CodedOutputStream::WriteVarint32ToArray(v->ByteSize(), buf);
60+
buf = pbio::CodedOutputStream::WriteVarint64ToArray(v->ByteSizeLong(), buf);
6161
buf = v->SerializeWithCachedSizesToArray(buf);
6262
});
6363

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/remote_block_reader_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static inline string ToDelimitedString(const pb::MessageLite *msg) {
119119
res.reserve(hdfs::DelimitedPBMessageSize(msg));
120120
pbio::StringOutputStream os(&res);
121121
pbio::CodedOutputStream out(&os);
122-
out.WriteVarint32(msg->ByteSize());
122+
out.WriteVarint64(msg->ByteSizeLong());
123123
msg->SerializeToCodedStream(&out);
124124
return res;
125125
}
@@ -141,9 +141,9 @@ static inline std::pair<error_code, string> ProducePacket(
141141
*reinterpret_cast<unsigned *>(prefix) =
142142
htonl(data.size() + checksum.size() + sizeof(int32_t));
143143
*reinterpret_cast<short *>(prefix + sizeof(int32_t)) =
144-
htons(proto.ByteSize());
144+
htons(static_cast<uint16_t>(proto.ByteSizeLong()));
145145
std::string payload(prefix, sizeof(prefix));
146-
payload.reserve(payload.size() + proto.ByteSize() + checksum.size() +
146+
payload.reserve(payload.size() + proto.ByteSizeLong() + checksum.size() +
147147
data.size());
148148
proto.AppendToString(&payload);
149149
payload += checksum;

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/rpc_engine_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class SharedConnectionEngine : public RpcEngine {
8888
static inline std::pair<boost::system::error_code, string> RpcResponse(
8989
const RpcResponseHeaderProto &h, const std::string &data,
9090
const boost::system::error_code &ec = boost::system::error_code()) {
91-
uint32_t payload_length =
92-
pbio::CodedOutputStream::VarintSize32(h.ByteSize()) +
93-
pbio::CodedOutputStream::VarintSize32(data.size()) + h.ByteSize() +
91+
const auto payload_length =
92+
pbio::CodedOutputStream::VarintSize64(h.ByteSizeLong()) +
93+
pbio::CodedOutputStream::VarintSize64(data.size()) + h.ByteSizeLong() +
9494
data.size();
9595

9696
std::string res;
@@ -99,9 +99,9 @@ static inline std::pair<boost::system::error_code, string> RpcResponse(
9999

100100
buf = pbio::CodedOutputStream::WriteLittleEndian32ToArray(
101101
htonl(payload_length), buf);
102-
buf = pbio::CodedOutputStream::WriteVarint32ToArray(h.ByteSize(), buf);
102+
buf = pbio::CodedOutputStream::WriteVarint64ToArray(h.ByteSizeLong(), buf);
103103
buf = h.SerializeWithCachedSizesToArray(buf);
104-
buf = pbio::CodedOutputStream::WriteVarint32ToArray(data.size(), buf);
104+
buf = pbio::CodedOutputStream::WriteVarint64ToArray(data.size(), buf);
105105
buf = pbio::CodedOutputStream::WriteStringToArray(data, buf);
106106

107107
return std::make_pair(ec, std::move(res));

0 commit comments

Comments
 (0)