Rename 'length delimited' to 'length prefixed'

PiperOrigin-RevId: 621597812
pull/16404/head
Protobuf Team Bot 2024-04-03 12:02:54 -07:00 committed by Copybara-Service
parent 19417f19ae
commit d5a435fb4b
7 changed files with 29 additions and 30 deletions

View File

@ -588,7 +588,7 @@ TEST(MessageTest, Freeze) {
//
// static void DecodeEncodeArbitrarySchemaAndPayload(
// const upb::fuzz::MiniTableFuzzInput& input, std::string_view proto_payload,
// int decode_options, int encode_options, bool length_delimited = false) {
// int decode_options, int encode_options, bool length_prefixed = false) {
// // Lexan does not have setenv
// #ifndef _MSC_VER
// setenv("FUZZTEST_STACK_LIMIT", "262144", 1);
@ -605,9 +605,9 @@ TEST(MessageTest, Freeze) {
// upb::fuzz::BuildMiniTable(input, &exts, arena.ptr());
// if (!mini_table) return;
// upb_Message* msg = upb_Message_New(mini_table, arena.ptr());
// if (length_delimited) {
// if (length_prefixed) {
// size_t num_bytes_read = 0;
// upb_DecodeStatus status = upb_DecodeLengthDelimited(
// upb_DecodeStatus status = upb_DecodeLengthPrefixed(
// proto_payload.data(), proto_payload.size(), msg, &num_bytes_read,
// mini_table, exts, decode_options, arena.ptr());
// ASSERT_TRUE(status != kUpb_DecodeStatus_Ok ||
@ -618,9 +618,9 @@ TEST(MessageTest, Freeze) {
// }
// char* ptr;
// size_t size;
// if (length_delimited) {
// upb_EncodeLengthDelimited(msg, mini_table, encode_options, arena.ptr(),
// &ptr, &size);
// if (length_prefixed) {
// upb_EncodeLengthPrefixed(msg, mini_table, encode_options, arena.ptr(), &ptr,
// &size);
// } else {
// upb_Encode(msg, mini_table, encode_options, arena.ptr(), &ptr, &size);
// }

View File

@ -202,8 +202,8 @@ cc_test(
)
cc_test(
name = "length_delimited_test",
srcs = ["length_delimited_test.cc"],
name = "length_prefixed_test",
srcs = ["length_prefixed_test.cc"],
copts = UPB_DEFAULT_CPPOPTS,
deps = [
":test_messages_proto2_upb_minitable",

View File

@ -28,9 +28,9 @@ static void TestEncodeDecodeRoundTrip(
for (auto msg : msgs) {
char* buf;
size_t size;
ASSERT_TRUE(upb_EncodeLengthDelimited(UPB_UPCAST(msg), kTestMiniTable, 0,
arena, &buf,
&size) == kUpb_EncodeStatus_Ok);
ASSERT_TRUE(upb_EncodeLengthPrefixed(UPB_UPCAST(msg), kTestMiniTable, 0,
arena, &buf,
&size) == kUpb_EncodeStatus_Ok);
ASSERT_GT(size, 0); // Even empty messages are 1 byte in this encoding.
s.append(std::string(buf, size));
}
@ -41,7 +41,7 @@ static void TestEncodeDecodeRoundTrip(
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
size_t num_bytes_read;
ASSERT_TRUE(upb_DecodeLengthDelimited(
ASSERT_TRUE(upb_DecodeLengthPrefixed(
s.data(), s.length(), UPB_UPCAST(msg), &num_bytes_read,
kTestMiniTable, nullptr, 0, arena) == kUpb_DecodeStatus_Ok);
ASSERT_GT(num_bytes_read, 0);
@ -57,7 +57,7 @@ static void TestEncodeDecodeRoundTrip(
}
}
TEST(LengthDelimitedTest, OneEmptyMessage) {
TEST(LengthPrefixedTest, OneEmptyMessage) {
upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
@ -65,7 +65,7 @@ TEST(LengthDelimitedTest, OneEmptyMessage) {
upb_Arena_Free(arena);
}
TEST(LengthDelimitedTest, AFewMessages) {
TEST(LengthPrefixedTest, AFewMessages) {
upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* a =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);

View File

@ -1394,12 +1394,12 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
return upb_Decoder_Decode(&decoder, buf, msg, mt, arena);
}
upb_DecodeStatus upb_DecodeLengthDelimited(const char* buf, size_t size,
upb_Message* msg,
size_t* num_bytes_read,
const upb_MiniTable* mt,
const upb_ExtensionRegistry* extreg,
int options, upb_Arena* arena) {
upb_DecodeStatus upb_DecodeLengthPrefixed(const char* buf, size_t size,
upb_Message* msg,
size_t* num_bytes_read,
const upb_MiniTable* mt,
const upb_ExtensionRegistry* extreg,
int options, upb_Arena* arena) {
// To avoid needing to make a Decoder just to decode the initial length,
// hand-decode the leading varint for the message length here.
uint64_t msg_len = 0;

View File

@ -136,7 +136,7 @@ UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size,
// Same as upb_Decode but with a varint-encoded length prepended.
// On success 'num_bytes_read' will be set to the how many bytes were read,
// on failure the contents of num_bytes_read is undefined.
UPB_API upb_DecodeStatus upb_DecodeLengthDelimited(
UPB_API upb_DecodeStatus upb_DecodeLengthPrefixed(
const char* buf, size_t size, upb_Message* msg, size_t* num_bytes_read,
const upb_MiniTable* mt, const upb_ExtensionRegistry* extreg, int options,
upb_Arena* arena);

View File

@ -662,9 +662,9 @@ upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
return _upb_Encode(msg, l, options, arena, buf, size, false);
}
upb_EncodeStatus upb_EncodeLengthDelimited(const upb_Message* msg,
const upb_MiniTable* l, int options,
upb_Arena* arena, char** buf,
size_t* size) {
upb_EncodeStatus upb_EncodeLengthPrefixed(const upb_Message* msg,
const upb_MiniTable* l, int options,
upb_Arena* arena, char** buf,
size_t* size) {
return _upb_Encode(msg, l, options, arena, buf, size, true);
}

View File

@ -69,11 +69,10 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg,
upb_Arena* arena, char** buf, size_t* size);
// Encodes the message prepended by a varint of the serialized length.
UPB_API upb_EncodeStatus upb_EncodeLengthDelimited(const upb_Message* msg,
const upb_MiniTable* l,
int options,
upb_Arena* arena, char** buf,
size_t* size);
UPB_API upb_EncodeStatus upb_EncodeLengthPrefixed(const upb_Message* msg,
const upb_MiniTable* l,
int options, upb_Arena* arena,
char** buf, size_t* size);
#ifdef __cplusplus
} /* extern "C" */