Auto-generate files after cl/621510731

pull/16377/head
Protobuf Team Bot 2024-04-03 14:19:48 +00:00
parent c6f6a3291e
commit d86fe39f04
5 changed files with 157 additions and 20 deletions

View File

@ -8930,7 +8930,7 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder,
}
upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTable* mt,
const upb_ExtensionRegistry* extreg, int options,
upb_Arena* arena) {
UPB_ASSERT(!upb_Message_IsFrozen(msg));
@ -8955,7 +8955,42 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
// (particularly parent_or_count).
UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena);
return upb_Decoder_Decode(&decoder, buf, msg, m, arena);
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) {
// 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;
for (size_t i = 0;; ++i) {
if (i >= size || i > 9) {
return kUpb_DecodeStatus_Malformed;
}
uint64_t b = *buf;
buf++;
msg_len += (b & 0x7f) << (i * 7);
if ((b & 0x80) == 0) {
*num_bytes_read = i + 1 + msg_len;
break;
}
}
// If the total number of bytes we would read (= the bytes from the varint
// plus however many bytes that varint says we should read) is larger then the
// input buffer then error as malformed.
if (*num_bytes_read > size) {
return kUpb_DecodeStatus_Malformed;
}
if (msg_len > INT32_MAX) {
return kUpb_DecodeStatus_Malformed;
}
return upb_Decode(buf, msg_len, msg, mt, extreg, options, arena);
}
#undef OP_FIXPCK_LG2
@ -9536,14 +9571,18 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
const upb_Message* const msg,
const upb_MiniTable* const l,
char** const buf,
size_t* const size) {
char** const buf, size_t* const size,
bool prepend_len) {
// Unfortunately we must continue to perform hackery here because there are
// code paths which blindly copy the returned pointer without bothering to
// check for errors until much later (b/235839510). So we still set *buf to
// NULL on error and we still set it to non-NULL on a successful empty result.
if (UPB_SETJMP(encoder->err) == 0) {
encode_message(encoder, msg, l, size);
size_t encoded_msg_size;
encode_message(encoder, msg, l, &encoded_msg_size);
if (prepend_len) {
encode_varint(encoder, encoded_msg_size);
}
*size = encoder->limit - encoder->ptr;
if (*size == 0) {
static char ch;
@ -9562,9 +9601,10 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
return encoder->status;
}
upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
int options, upb_Arena* arena, char** buf,
size_t* size) {
static upb_EncodeStatus _upb_Encode(const upb_Message* msg,
const upb_MiniTable* l, int options,
upb_Arena* arena, char** buf, size_t* size,
bool prepend_len) {
upb_encstate e;
unsigned depth = (unsigned)options >> 16;
@ -9577,7 +9617,20 @@ upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
e.options = options;
_upb_mapsorter_init(&e.sorter);
return upb_Encoder_Encode(&e, msg, l, buf, size);
return upb_Encoder_Encode(&e, msg, l, buf, size, prepend_len);
}
upb_EncodeStatus upb_Encode(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, false);
}
upb_EncodeStatus upb_EncodeLengthDelimited(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);
}
// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64.

View File

@ -4141,10 +4141,18 @@ typedef enum {
} upb_DecodeStatus;
UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size,
upb_Message* msg, const upb_MiniTable* l,
upb_Message* msg, const upb_MiniTable* mt,
const upb_ExtensionRegistry* extreg,
int options, upb_Arena* arena);
// 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(
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);
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -4211,6 +4219,13 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg,
const upb_MiniTable* l, int options,
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);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@ -8423,7 +8423,7 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder,
}
upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTable* mt,
const upb_ExtensionRegistry* extreg, int options,
upb_Arena* arena) {
UPB_ASSERT(!upb_Message_IsFrozen(msg));
@ -8448,7 +8448,42 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
// (particularly parent_or_count).
UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena);
return upb_Decoder_Decode(&decoder, buf, msg, m, arena);
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) {
// 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;
for (size_t i = 0;; ++i) {
if (i >= size || i > 9) {
return kUpb_DecodeStatus_Malformed;
}
uint64_t b = *buf;
buf++;
msg_len += (b & 0x7f) << (i * 7);
if ((b & 0x80) == 0) {
*num_bytes_read = i + 1 + msg_len;
break;
}
}
// If the total number of bytes we would read (= the bytes from the varint
// plus however many bytes that varint says we should read) is larger then the
// input buffer then error as malformed.
if (*num_bytes_read > size) {
return kUpb_DecodeStatus_Malformed;
}
if (msg_len > INT32_MAX) {
return kUpb_DecodeStatus_Malformed;
}
return upb_Decode(buf, msg_len, msg, mt, extreg, options, arena);
}
#undef OP_FIXPCK_LG2
@ -9029,14 +9064,18 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
const upb_Message* const msg,
const upb_MiniTable* const l,
char** const buf,
size_t* const size) {
char** const buf, size_t* const size,
bool prepend_len) {
// Unfortunately we must continue to perform hackery here because there are
// code paths which blindly copy the returned pointer without bothering to
// check for errors until much later (b/235839510). So we still set *buf to
// NULL on error and we still set it to non-NULL on a successful empty result.
if (UPB_SETJMP(encoder->err) == 0) {
encode_message(encoder, msg, l, size);
size_t encoded_msg_size;
encode_message(encoder, msg, l, &encoded_msg_size);
if (prepend_len) {
encode_varint(encoder, encoded_msg_size);
}
*size = encoder->limit - encoder->ptr;
if (*size == 0) {
static char ch;
@ -9055,9 +9094,10 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
return encoder->status;
}
upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
int options, upb_Arena* arena, char** buf,
size_t* size) {
static upb_EncodeStatus _upb_Encode(const upb_Message* msg,
const upb_MiniTable* l, int options,
upb_Arena* arena, char** buf, size_t* size,
bool prepend_len) {
upb_encstate e;
unsigned depth = (unsigned)options >> 16;
@ -9070,7 +9110,20 @@ upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
e.options = options;
_upb_mapsorter_init(&e.sorter);
return upb_Encoder_Encode(&e, msg, l, buf, size);
return upb_Encoder_Encode(&e, msg, l, buf, size, prepend_len);
}
upb_EncodeStatus upb_Encode(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, false);
}
upb_EncodeStatus upb_EncodeLengthDelimited(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);
}
// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64.

View File

@ -4143,10 +4143,18 @@ typedef enum {
} upb_DecodeStatus;
UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size,
upb_Message* msg, const upb_MiniTable* l,
upb_Message* msg, const upb_MiniTable* mt,
const upb_ExtensionRegistry* extreg,
int options, upb_Arena* arena);
// 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(
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);
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -4213,6 +4221,13 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg,
const upb_MiniTable* l, int options,
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);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@ -969,6 +969,7 @@ set(upb_test_files
${protobuf_SOURCE_DIR}/upb/message/test.cc
${protobuf_SOURCE_DIR}/upb/message/utf8_test.cc
${protobuf_SOURCE_DIR}/upb/test/editions_test.cc
${protobuf_SOURCE_DIR}/upb/test/length_delimited_test.cc
${protobuf_SOURCE_DIR}/upb/test/proto3_test.cc
${protobuf_SOURCE_DIR}/upb/test/test_cpp.cc
${protobuf_SOURCE_DIR}/upb/test/test_generated_code.cc