From 80b1d62bfcea65c59e2160da71dad84b1bd19cef Mon Sep 17 00:00:00 2001 From: "kenton@google.com" Date: Wed, 29 Jul 2009 01:13:20 +0000 Subject: Submit recent changes from internal branch, including "lite mode" for C++ and Java. See CHANGES.txt for more details. --- src/google/protobuf/io/coded_stream.h | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/google/protobuf/io/coded_stream.h') diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 9e450216..fa023f35 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -110,6 +110,9 @@ #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ #include +#ifndef _MSC_VER +#include +#endif // !_MSC_VER #include namespace google { @@ -137,6 +140,11 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // Create a CodedInputStream that reads from the given ZeroCopyInputStream. explicit CodedInputStream(ZeroCopyInputStream* input); + // Create a CodedInputStream that reads from the given flat array. This is + // faster than using an ArrayInputStream. PushLimit(size) is implied by + // this constructor. + explicit CodedInputStream(const uint8* buffer, int size); + // Destroy the CodedInputStream and position the underlying // ZeroCopyInputStream at the first unread byte. If an error occurred while // reading (causing a method to return false), then the exact position of @@ -360,6 +368,9 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // Advance the buffer by a given number of bytes. void Advance(int amount); + // Back up input_ to the current buffer position. + void BackUpInputToCurrentPosition(); + // Recomputes the value of buffer_size_after_limit_. Must be called after // current_limit_ or total_bytes_limit_ changes. void RecomputeBufferLimits(); @@ -664,6 +675,41 @@ inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray( } } +inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, + uint8* target) { +#if !defined(PROTOBUF_TEST_NOT_LITTLE_ENDIAN) && \ + defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN + memcpy(target, &value, sizeof(value)); +#else + target[0] = static_cast(value ); + target[1] = static_cast(value >> 8); + target[2] = static_cast(value >> 16); + target[3] = static_cast(value >> 24); +#endif + return target + sizeof(value); +} + +inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value, + uint8* target) { +#if !defined(PROTOBUF_TEST_NOT_LITTLE_ENDIAN) && \ + defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN + memcpy(target, &value, sizeof(value)); +#else + uint32 part0 = static_cast(value); + uint32 part1 = static_cast(value >> 32); + + target[0] = static_cast(part0 ); + target[1] = static_cast(part0 >> 8); + target[2] = static_cast(part0 >> 16); + target[3] = static_cast(part0 >> 24); + target[4] = static_cast(part1 ); + target[5] = static_cast(part1 >> 8); + target[6] = static_cast(part1 >> 16); + target[7] = static_cast(part1 >> 24); +#endif + return target + sizeof(value); +} + inline void CodedOutputStream::WriteTag(uint32 value) { WriteVarint32(value); } -- cgit v1.2.3