109 #ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
110 #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
114 #if defined(_M_IX86) && \
115 !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
116 #define PROTOBUF_LITTLE_ENDIAN 1
121 #pragma runtime_checks("c", off)
124 #include <sys/param.h>
125 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN && \
126 !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
127 #define PROTOBUF_LITTLE_ENDIAN 1
136 class DescriptorPool;
137 class MessageFactory;
142 class CodedInputStream;
143 class CodedOutputStream;
146 class ZeroCopyInputStream;
147 class ZeroCopyOutputStream;
175 inline bool IsFlat()
const;
179 bool Skip(
int count);
188 bool GetDirectBufferPointer(
const void** data,
int* size);
192 inline void GetDirectBufferPointerInline(
const void** data,
196 bool ReadRaw(
void* buffer,
int size);
205 bool ReadString(
string* buffer,
int size);
208 inline bool InternalReadStringInline(
string* buffer,
215 bool ReadLittleEndian64(
uint64* value);
220 static const uint8* ReadLittleEndian32FromArray(
const uint8* buffer,
223 static const uint8* ReadLittleEndian64FromArray(
const uint8* buffer,
229 bool ReadVarint32(
uint32* value);
231 bool ReadVarint64(
uint64* value);
249 inline std::pair<uint32, bool> ReadTagWithCutoff(
uint32 cutoff)
268 static const uint8* ExpectTagFromArray(
287 bool LastTagWas(
uint32 expected);
295 bool ConsumedEntireMessage();
320 Limit PushLimit(
int byte_limit);
324 void PopLimit(Limit limit);
328 int BytesUntilLimit()
const;
331 int CurrentPosition()
const;
368 void SetTotalBytesLimit(
int total_bytes_limit,
int warning_threshold);
372 int BytesUntilTotalBytesLimit()
const;
381 void SetRecursionLimit(
int limit);
386 bool IncrementRecursionDepth();
389 void DecrementRecursionDepth();
529 void Advance(
int amount);
532 void BackUpInputToCurrentPosition();
536 void RecomputeBufferLimits();
539 void PrintTotalBytesLimitError();
552 bool ReadVarint32Fallback(
uint32* value);
553 bool ReadVarint64Fallback(
uint64* value);
554 bool ReadVarint32Slow(
uint32* value);
555 bool ReadVarint64Slow(
uint64* value);
556 bool ReadLittleEndian32Fallback(
uint32* value);
557 bool ReadLittleEndian64Fallback(
uint64* value);
563 bool ReadStringFallback(
string* buffer,
int size);
566 int BufferSize()
const;
568 static const int kDefaultTotalBytesLimit = 64 << 20;
570 static const int kDefaultTotalBytesWarningThreshold = 32 << 20;
633 bool Skip(
int count);
643 bool GetDirectBufferPointer(
void** data,
int* size);
652 inline uint8* GetDirectBufferForNBytesAndAdvance(
int size);
655 void WriteRaw(
const void* buffer,
int size);
658 void WriteRawMaybeAliased(
const void* data,
int size);
664 static uint8* WriteRawToArray(
const void* buffer,
int size,
uint8* target);
667 void WriteString(
const string& str);
669 static uint8* WriteStringToArray(
const string& str,
uint8* target);
671 static uint8* WriteStringWithSizeToArray(
const string& str,
uint8* target);
683 void EnableAliasing(
bool enabled);
690 void WriteLittleEndian64(
uint64 value);
697 void WriteVarint32(
uint32 value);
701 void WriteVarint64(
uint64 value);
707 void WriteVarint32SignExtended(
int32 value);
709 static uint8* WriteVarint32SignExtendedToArray(
int32 value,
uint8* target);
716 void WriteTag(
uint32 value);
718 static uint8* WriteTagToArray(
722 static int VarintSize32(
uint32 value);
724 static int VarintSize64(
uint64 value);
727 static int VarintSize32SignExtended(
int32 value);
730 template <u
int32 Value>
732 static const int value =
735 : (
Value < (1 << 14))
737 : (
Value < (1 << 21))
739 : (
Value < (1 << 28))
745 inline int ByteCount()
const;
762 void Advance(
int amount);
770 void WriteAliasedRaw(
const void* buffer,
int size);
781 static uint8* WriteVarint32FallbackToArrayInline(
783 static uint8* WriteVarint64ToArrayInline(
786 static int VarintSize32Fallback(
uint32 value);
817 #if defined(PROTOBUF_LITTLE_ENDIAN)
818 memcpy(value, buffer,
sizeof(*value));
819 return buffer +
sizeof(*value);
821 *value = (
static_cast<uint32>(buffer[0]) ) |
822 (
static_cast<uint32>(buffer[1]) << 8) |
823 (
static_cast<uint32>(buffer[2]) << 16) |
824 (
static_cast<uint32>(buffer[3]) << 24);
825 return buffer +
sizeof(*value);
832 #if defined(PROTOBUF_LITTLE_ENDIAN)
833 memcpy(value, buffer,
sizeof(*value));
834 return buffer +
sizeof(*value);
837 (
static_cast<uint32>(buffer[1]) << 8) |
838 (
static_cast<uint32>(buffer[2]) << 16) |
839 (
static_cast<uint32>(buffer[3]) << 24);
841 (
static_cast<uint32>(buffer[5]) << 8) |
842 (
static_cast<uint32>(buffer[6]) << 16) |
843 (
static_cast<uint32>(buffer[7]) << 24);
844 *value =
static_cast<uint64>(part0) |
845 (static_cast<uint64>(part1) << 32);
846 return buffer +
sizeof(*value);
851 #if defined(PROTOBUF_LITTLE_ENDIAN)
853 memcpy(value,
buffer_,
sizeof(*value));
865 #if defined(PROTOBUF_LITTLE_ENDIAN)
867 memcpy(value,
buffer_,
sizeof(*value));
898 if (static_cast<int8>(
buffer_[0]) > 0) {
899 const uint32 kMax1ByteVarint = 0x7f;
902 return make_pair(tag, cutoff >= kMax1ByteVarint || tag <= cutoff);
907 if (cutoff >= 0x80 &&
910 const uint32 kMax2ByteVarint = (0x7f << 7) + 0x7f;
919 bool at_or_below_cutoff = cutoff >= kMax2ByteVarint || tag <= cutoff;
920 return make_pair(tag, at_or_below_cutoff);
937 if (expected < (1 << 7)) {
944 }
else if (expected < (1 << 14)) {
946 buffer_[0] == static_cast<uint8>(expected | 0x80) &&
947 buffer_[1] == static_cast<uint8>(expected >> 7)) {
961 if (expected < (1 << 7)) {
962 if (buffer[0] == expected) {
965 }
else if (expected < (1 << 14)) {
966 if (buffer[0] == static_cast<uint8>(expected | 0x80) &&
967 buffer[1] == static_cast<uint8>(expected >> 7)) {
1038 #if defined(PROTOBUF_LITTLE_ENDIAN)
1039 memcpy(target, &value,
sizeof(value));
1042 target[1] =
static_cast<uint8>(value >> 8);
1043 target[2] =
static_cast<uint8>(value >> 16);
1044 target[3] =
static_cast<uint8>(value >> 24);
1046 return target +
sizeof(
value);
1051 #if defined(PROTOBUF_LITTLE_ENDIAN)
1052 memcpy(target, &value,
sizeof(value));
1057 target[0] =
static_cast<uint8>(part0);
1058 target[1] =
static_cast<uint8>(part0 >> 8);
1059 target[2] =
static_cast<uint8>(part0 >> 16);
1060 target[3] =
static_cast<uint8>(part0 >> 24);
1061 target[4] =
static_cast<uint8>(part1);
1062 target[5] =
static_cast<uint8>(part1 >> 8);
1063 target[6] =
static_cast<uint8>(part1 >> 16);
1064 target[7] =
static_cast<uint8>(part1 >> 24);
1066 return target +
sizeof(
value);
1075 if (value < (1 << 7)) {
1078 }
else if (value < (1 << 14)) {
1079 target[0] =
static_cast<uint8>(value | 0x80);
1080 target[1] =
static_cast<uint8>(value >> 7);
1088 if (value < (1 << 7)) {
1104 WriteRaw(str.data(),
static_cast<int>(str.size()));
1108 const void* data,
int size) {
1117 const string& str,
uint8* target) {
1118 return WriteRawToArray(str.data(),
static_cast<int>(str.size()), target);
1169 total_bytes_read_(0),
1172 legitimate_message_end_(
false),
1173 aliasing_enabled_(
false),
1175 buffer_size_after_limit_(0),
1176 total_bytes_limit_(kDefaultTotalBytesLimit),
1177 total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
1178 recursion_depth_(0),
1179 recursion_limit_(default_recursion_limit_),
1180 extension_pool_(
NULL),
1181 extension_factory_(
NULL) {
1189 buffer_end_(buffer + size),
1190 total_bytes_read_(size),
1193 legitimate_message_end_(
false),
1194 aliasing_enabled_(
false),
1195 current_limit_(size),
1196 buffer_size_after_limit_(0),
1197 total_bytes_limit_(kDefaultTotalBytesLimit),
1198 total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
1199 recursion_depth_(0),
1200 recursion_limit_(default_recursion_limit_),
1201 extension_pool_(
NULL),
1202 extension_factory_(
NULL) {
1215 #if defined(_MSC_VER) && _MSC_VER >= 1300
1216 #pragma runtime_checks("c", restore)
1220 #endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
uint8 * buffer_
Definition: coded_stream.h:755
bool had_error_
Definition: coded_stream.h:758
int total_bytes_
Definition: coded_stream.h:757
void WriteRaw(const void *buffer, int size)
static int VarintSize32Fallback(uint32 value)
static uint8 * WriteRawToArray(const void *buffer, int size, uint8 *target)
void WriteVarint64(uint64 value)
int ByteCount() const
Definition: coded_stream.h:1121
static uint8 * WriteStringToArray(const string &str, uint8 *target)
Definition: coded_stream.h:1116
static uint8 * WriteVarint32ToArray(uint32 value, uint8 *target)
Definition: coded_stream.h:1009
uint8 * GetDirectBufferForNBytesAndAdvance(int size)
Definition: coded_stream.h:999
uint8_t uint8
Definition: common.h:175
Definition: coded_stream.h:731
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: message.h:720
#define false
Definition: CascPort.h:18
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: common.h:89
void WriteRawMaybeAliased(const void *data, int size)
Definition: coded_stream.h:1107
void WriteAliasedRaw(const void *buffer, int size)
void WriteTag(uint32 value)
Definition: coded_stream.h:1069
ZeroCopyOutputStream * output_
Definition: coded_stream.h:754
int32_t int32
Definition: common.h:172
Definition: descriptor.h:1167
#define GOOGLE_PREDICT_TRUE
Definition: common.h:235
Definition: coded_stream.h:621
static uint8 * WriteVarint64ToArray(uint64 value, uint8 *target)
static uint8 * WriteVarint32FallbackToArray(uint32 value, uint8 *target)
uint32_t uint32
Definition: common.h:177
static int VarintSize32SignExtended(int32 value)
Definition: coded_stream.h:1095
void WriteVarint32(uint32 value)
uint64_t uint64
Definition: common.h:178
Definition: zero_copy_stream.h:181
bool aliasing_enabled_
Definition: coded_stream.h:759
#define LIBPROTOBUF_EXPORT
Definition: common.h:105
void WriteString(const string &str)
Definition: coded_stream.h:1103
static const int32 kint32max
Definition: common.h:197
void Advance(int amount)
Definition: coded_stream.h:1129
Definition: BnetFileGenerator.h:47
static uint8 * WriteLittleEndian32ToArray(uint32 value, uint8 *target)
Definition: coded_stream.h:1036
const FieldDescriptor value
Definition: descriptor.h:1522
static uint8 * WriteLittleEndian64ToArray(uint64 value, uint8 *target)
Definition: coded_stream.h:1049
void WriteVarint32SignExtended(int32 value)
Definition: coded_stream.h:1019
static uint8 * WriteVarint32SignExtendedToArray(int32 value, uint8 *target)
Definition: coded_stream.h:1027
static uint8 * WriteTagToArray(uint32 value, uint8 *target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: coded_stream.h:1073
bool HadError() const
Definition: coded_stream.h:749
static int VarintSize32(uint32 value)
Definition: coded_stream.h:1087
int buffer_size_
Definition: coded_stream.h:756
#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: common.h:217