~ubuntu-branches/ubuntu/trusty/protobuf/trusty-proposed

« back to all changes in this revision

Viewing changes to src/google/protobuf/io/coded_stream.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
111
111
 
112
112
#include <string>
113
 
#ifndef _MSC_VER
114
 
#include <sys/param.h>
115
 
#endif  // !_MSC_VER
 
113
#ifdef _MSC_VER
 
114
  #if defined(_M_IX86) && \
 
115
      !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
 
116
    #define PROTOBUF_LITTLE_ENDIAN 1
 
117
  #endif
 
118
  #if _MSC_VER >= 1300
 
119
    // If MSVC has "/RTCc" set, it will complain about truncating casts at
 
120
    // runtime.  This file contains some intentional truncating casts.
 
121
    #pragma runtime_checks("c", off)
 
122
  #endif
 
123
#else
 
124
  #include <sys/param.h>   // __BYTE_ORDER
 
125
  #if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN && \
 
126
      !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
 
127
    #define PROTOBUF_LITTLE_ENDIAN 1
 
128
  #endif
 
129
#endif
116
130
#include <google/protobuf/stubs/common.h>
117
 
#include <google/protobuf/stubs/common.h>          // for GOOGLE_PREDICT_TRUE macro
 
131
 
118
132
 
119
133
namespace google {
120
 
 
121
134
namespace protobuf {
122
135
 
123
136
class DescriptorPool;
554
567
//   char text[] = "Hello world!";
555
568
//
556
569
//   int coded_size = sizeof(magic_number) +
557
 
//                    CodedOutputStream::Varint32Size(strlen(text)) +
 
570
//                    CodedOutputStream::VarintSize32(strlen(text)) +
558
571
//                    strlen(text);
559
572
//
560
573
//   uint8* buffer =
735
748
inline const uint8* CodedInputStream::ReadLittleEndian32FromArray(
736
749
    const uint8* buffer,
737
750
    uint32* value) {
738
 
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \
739
 
    defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
 
751
#if defined(PROTOBUF_LITTLE_ENDIAN)
740
752
  memcpy(value, buffer, sizeof(*value));
741
753
  return buffer + sizeof(*value);
742
754
#else
751
763
inline const uint8* CodedInputStream::ReadLittleEndian64FromArray(
752
764
    const uint8* buffer,
753
765
    uint64* value) {
754
 
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \
755
 
    defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
 
766
#if defined(PROTOBUF_LITTLE_ENDIAN)
756
767
  memcpy(value, buffer, sizeof(*value));
757
768
  return buffer + sizeof(*value);
758
769
#else
771
782
}
772
783
 
773
784
inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {
774
 
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \
775
 
    defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
776
 
  if (GOOGLE_PREDICT_TRUE(BufferSize() >= sizeof(*value))) {
 
785
#if defined(PROTOBUF_LITTLE_ENDIAN)
 
786
  if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
777
787
    memcpy(value, buffer_, sizeof(*value));
778
788
    Advance(sizeof(*value));
779
789
    return true;
786
796
}
787
797
 
788
798
inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {
789
 
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \
790
 
    defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
791
 
  if (GOOGLE_PREDICT_TRUE(BufferSize() >= sizeof(*value))) {
 
799
#if defined(PROTOBUF_LITTLE_ENDIAN)
 
800
  if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
792
801
    memcpy(value, buffer_, sizeof(*value));
793
802
    Advance(sizeof(*value));
794
803
    return true;
915
924
 
916
925
inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value,
917
926
                                                            uint8* target) {
918
 
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \
919
 
    defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
 
927
#if defined(PROTOBUF_LITTLE_ENDIAN)
920
928
  memcpy(target, &value, sizeof(value));
921
929
#else
922
930
  target[0] = static_cast<uint8>(value);
929
937
 
930
938
inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value,
931
939
                                                            uint8* target) {
932
 
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) && \
933
 
    defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
 
940
#if defined(PROTOBUF_LITTLE_ENDIAN)
934
941
  memcpy(target, &value, sizeof(value));
935
942
#else
936
943
  uint32 part0 = static_cast<uint32>(value);
983
990
}
984
991
 
985
992
inline void CodedOutputStream::WriteString(const string& str) {
986
 
  WriteRaw(str.data(), str.size());
 
993
  WriteRaw(str.data(), static_cast<int>(str.size()));
987
994
}
988
995
 
989
996
inline uint8* CodedOutputStream::WriteStringToArray(
990
997
    const string& str, uint8* target) {
991
 
  return WriteRawToArray(str.data(), str.size(), target);
 
998
  return WriteRawToArray(str.data(), static_cast<int>(str.size()), target);
992
999
}
993
1000
 
994
1001
inline int CodedOutputStream::ByteCount() const {
1044
1051
    last_tag_(0),
1045
1052
    legitimate_message_end_(false),
1046
1053
    aliasing_enabled_(false),
1047
 
    current_limit_(INT_MAX),
 
1054
    current_limit_(kint32max),
1048
1055
    buffer_size_after_limit_(0),
1049
1056
    total_bytes_limit_(kDefaultTotalBytesLimit),
1050
1057
    total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
1086
1093
}  // namespace io
1087
1094
}  // namespace protobuf
1088
1095
 
 
1096
 
 
1097
#if defined(_MSC_VER) && _MSC_VER >= 1300
 
1098
  #pragma runtime_checks("c", restore)
 
1099
#endif  // _MSC_VER
 
1100
 
1089
1101
}  // namespace google
1090
1102
#endif  // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__