Skip to content

Commit fc8a522

Browse files
Internal change.
PiperOrigin-RevId: 759710630
1 parent e34bb0d commit fc8a522

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/google/protobuf/io/coded_stream.h

+26-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
#include <type_traits>
9999
#include <utility>
100100

101+
#include "absl/base/optimization.h"
102+
101103
#if defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
102104
// If MSVC has "/RTCc" set, it will complain about truncating casts at
103105
// runtime. This file contains some intentional truncating casts.
@@ -821,6 +823,29 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {
821823
int64_t ByteCount(uint8_t* ptr) const;
822824

823825

826+
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
827+
template <typename ValT, typename CallbackT>
828+
uint8_t* WriteNumericArray(uint8_t* ptr, uint32_t count,
829+
CallbackT&& callback) {
830+
static_assert(sizeof(ValT) > 1, "Use WriteRaw");
831+
static_assert(sizeof(ValT) < kSlopBytes, "");
832+
833+
int64_t size = count * sizeof(ValT);
834+
while (size > 0) {
835+
ptr = EnsureSpace(ptr);
836+
int64_t chunk_size = std::min<int64_t>(GetSize(ptr), size);
837+
int64_t round_down_size = (chunk_size / sizeof(ValT)) * sizeof(ValT);
838+
ABSL_DCHECK_GT(round_down_size, 0u);
839+
840+
callback(ptr, round_down_size);
841+
842+
size -= round_down_size;
843+
ptr += round_down_size;
844+
}
845+
return ptr;
846+
}
847+
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
848+
824849
private:
825850
uint8_t* end_;
826851
uint8_t* buffer_end_ = buffer_;
@@ -829,7 +854,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {
829854
bool had_error_ = false;
830855
bool aliasing_enabled_ = false; // See EnableAliasing().
831856
bool is_serialization_deterministic_;
832-
bool skip_check_consistency = false;
857+
bool skip_check_consistency_ = false;
833858

834859
uint8_t* EnsureSpaceFallback(uint8_t* ptr);
835860
inline uint8_t* Next();

0 commit comments

Comments
 (0)