text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Author: kenton@google.com (Kenton Varda)
//  Based on original Protocol Buffers design by
//  Sanjay Ghemawat, Jeff Dean, and others.
//
// A proto file which uses optimize_for = CODE_SIZE.

syntax = "proto2";
import "google/protobuf/unittest.proto";

package protobuf_unittest;

option optimize_for = CODE_SIZE;

message TestOptimizedForSize {
  optional int32 i = 1;
  optional ForeignMessage msg = 19;

  extensions 1000 to max;

  extend TestOptimizedForSize {
    optional int32 test_extension = 1234;
    optional TestRequiredOptimizedForSize test_extension2 = 1235;
  }

  oneof foo {
    int32 integer_field = 2;
    string string_field = 3;
  }
}

message TestRequiredOptimizedForSize {
  required int32 x = 1;
}

message TestOptionalOptimizedForSize {
  optional TestRequiredOptimizedForSize o = 1;
}

mime_type: text/plain


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto3";

package google.protobuf;

option csharp_namespace = "Google.Protobuf.WellKnownTypes";
option cc_enable_arenas = true;
option go_package = "github.com/golang/protobuf/ptypes/struct;structpb";
option java_package = "com.google.protobuf";
option java_outer_classname = "StructProto";
option java_multiple_files = true;
option objc_class_prefix = "GPB";

// `Struct` represents a structured data value, consisting of fields
// which map to dynamically typed values. In some languages, `Struct`
// might be supported by a native representation. For example, in
// scripting languages like JS a struct is represented as an
// object. The details of that representation are described together
// with the proto support for the language.
//
// The JSON representation for `Struct` is JSON object.
message Struct {
  // Unordered map of dynamically typed values.
  map<string, Value> fields = 1;
}

// `Value` represents a dynamically typed value which can be either
// null, a number, a string, a boolean, a recursive struct value, or a
// list of values. A producer of value is expected to set one of that
// variants, absence of any variant indicates an error.
//
// The JSON representation for `Value` is JSON value.
message Value {
  // The kind of value.
  oneof kind {
    // Represents a null value.
    NullValue null_value = 1;
    // Represents a double value.
    double number_value = 2;
    // Represents a string value.
    string string_value = 3;
    // Represents a boolean value.
    bool bool_value = 4;
    // Represents a structured value.
    Struct struct_value = 5;
    // Represents a repeated `Value`.
    ListValue list_value = 6;
  }
}

// `NullValue` is a singleton enumeration to represent the null value for the
// `Value` type union.
//
//  The JSON representation for `NullValue` is JSON `null`.
enum NullValue {
  // Null value.
  NULL_VALUE = 0;
}

// `ListValue` is a wrapper around a repeated field of values.
//
// The JSON representation for `ListValue` is JSON array.
message ListValue {
  // Repeated field of dynamically typed values.
  repeated Value values = 1;
}


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <google/protobuf/any.h>

#include <google/protobuf/generated_message_util.h>

namespace google {
namespace protobuf {
namespace internal {

namespace {
string GetTypeUrl(const Descriptor* message,
                  const string& type_url_prefix) {
  if (!type_url_prefix.empty() &&
      type_url_prefix[type_url_prefix.size() - 1] == '/') {
    return type_url_prefix + message->full_name();
  } else {
    return type_url_prefix + "/" + message->full_name();
  }
}
}  // namespace

const char kAnyFullTypeName[] = "google.protobuf.Any";
const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/";
const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";

AnyMetadata::AnyMetadata(UrlType* type_url, ValueType* value)
    : type_url_(type_url), value_(value) {
}

void AnyMetadata::PackFrom(const Message& message) {
  PackFrom(message, kTypeGoogleApisComPrefix);
}

void AnyMetadata::PackFrom(const Message& message,
                           const string& type_url_prefix) {
  type_url_->SetNoArena(&::google::protobuf::internal::GetEmptyString(),
                        GetTypeUrl(message.GetDescriptor(), type_url_prefix));
  message.SerializeToString(value_->MutableNoArena(
      &::google::protobuf::internal::GetEmptyStringAlreadyInited()));
}

bool AnyMetadata::UnpackTo(Message* message) const {
  if (!InternalIs(message->GetDescriptor())) {
    return false;
  }
  return message->ParseFromString(value_->GetNoArena());
}

bool AnyMetadata::InternalIs(const Descriptor* descriptor) const {
  const string type_url = type_url_->GetNoArena();
  string full_name;
  if (!ParseAnyTypeUrl(type_url, &full_name)) {
    return false;
  }
  return full_name == descriptor->full_name();
}

bool ParseAnyTypeUrl(const string& type_url, string* full_type_name) {
  size_t pos = type_url.find_last_of("/");
  if (pos == string::npos || pos + 1 == type_url.size()) {
    return false;
  }
  *full_type_name = type_url.substr(pos + 1);
  return true;
}

bool GetAnyFieldDescriptors(const Message& message,
                            const FieldDescriptor** type_url_field,
                            const FieldDescriptor** value_field) {
    const Descriptor* descriptor = message.GetDescriptor();
    if (descriptor->full_name() != kAnyFullTypeName) {
      return false;
    }
    *type_url_field = descriptor->FindFieldByNumber(1);
    *value_field = descriptor->FindFieldByNumber(2);
    return (*type_url_field != NULL &&
            (*type_url_field)->type() == FieldDescriptor::TYPE_STRING &&
            *value_field != NULL &&
            (*value_field)->type() == FieldDescriptor::TYPE_BYTES);
}

}  // namespace internal
}  // namespace protobuf
}  // namespace google


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Author: kenton@google.com (Kenton Varda)
//  Based on original Protocol Buffers design by
//  Sanjay Ghemawat, Jeff Dean, and others.

#include <google/protobuf/unknown_field_set.h>

#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/stl_util.h>

namespace google {
namespace protobuf {

namespace {
// This global instance is returned by unknown_fields() on any message class
// when the object has no unknown fields. This is necessary because we now
// instantiate the UnknownFieldSet dynamically only when required.
UnknownFieldSet* default_unknown_field_set_instance_ = NULL;

void DeleteDefaultUnknownFieldSet() {
  delete default_unknown_field_set_instance_;
}

void InitDefaultUnknownFieldSet() {
  default_unknown_field_set_instance_ = new UnknownFieldSet();
  internal::OnShutdown(&DeleteDefaultUnknownFieldSet);
}

GOOGLE_PROTOBUF_DECLARE_ONCE(default_unknown_field_set_once_init_);
}

const UnknownFieldSet* UnknownFieldSet::default_instance() {
  ::google::protobuf::GoogleOnceInit(&default_unknown_field_set_once_init_,
                 &InitDefaultUnknownFieldSet);
  return default_unknown_field_set_instance_;
}

void UnknownFieldSet::ClearFallback() {
  GOOGLE_DCHECK(fields_ != NULL && fields_->size() > 0);
  int n = fields_->size();
  do {
    (*fields_)[--n].Delete();
  } while (n > 0);
  delete fields_;
  fields_ = NULL;
}

void UnknownFieldSet::InternalMergeFrom(const UnknownFieldSet& other) {
  int other_field_count = other.field_count();
  if (other_field_count > 0) {
    fields_ = new std::vector<UnknownField>();
    for (int i = 0; i < other_field_count; i++) {
      fields_->push_back((*other.fields_)[i]);
      fields_->back().DeepCopy((*other.fields_)[i]);
    }
  }
}

void UnknownFieldSet::MergeFrom(const UnknownFieldSet& other) {
  int other_field_count = other.field_count();
  if (other_field_count > 0) {
    if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
    for (int i = 0; i < other_field_count; i++) {
      fields_->push_back((*other.fields_)[i]);
      fields_->back().DeepCopy((*other.fields_)[i]);
    }
  }
}

// A specialized MergeFrom for performance when we are merging from an UFS that
// is temporary and can be destroyed in the process.
void UnknownFieldSet::MergeFromAndDestroy(UnknownFieldSet* other) {
  int other_field_count = other->field_count();
  if (other_field_count > 0) {
    if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
    for (int i = 0; i < other_field_count; i++) {
      fields_->push_back((*other->fields_)[i]);
      (*other->fields_)[i].Reset();
    }
  }
  delete other->fields_;
  other->fields_ = NULL;
}

void UnknownFieldSet::MergeToInternalMetdata(
    const UnknownFieldSet& other,
    internal::InternalMetadataWithArena* metadata) {
  metadata->mutable_unknown_fields()->MergeFrom(other);
}

size_t UnknownFieldSet::SpaceUsedExcludingSelfLong() const {
  if (fields_ == NULL) return 0;

  size_t total_size = sizeof(*fields_) + sizeof(UnknownField) * fields_->size();

  for (int i = 0; i < fields_->size(); i++) {
    const UnknownField& field = (*fields_)[i];
    switch (field.type()) {
      case UnknownField::TYPE_LENGTH_DELIMITED:
        total_size += sizeof(*field.data_.length_delimited_.string_value_) +
                      internal::StringSpaceUsedExcludingSelfLong(
                          *field.data_.length_delimited_.string_value_);
        break;
      case UnknownField::TYPE_GROUP:
        total_size += field.data_.group_->SpaceUsedLong();
        break;
      default:
        break;
    }
  }
  return total_size;
}

size_t UnknownFieldSet::SpaceUsedLong() const {
  return sizeof(*this) + SpaceUsedExcludingSelf();
}

void UnknownFieldSet::AddVarint(int number, uint64 value) {
  UnknownField field;
  field.number_ = number;
  field.SetType(UnknownField::TYPE_VARINT);
  field.data_.varint_ = value;
  if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
  fields_->push_back(field);
}

void UnknownFieldSet::AddFixed32(int number, uint32 value) {
  UnknownField field;
  field.number_ = number;
  field.SetType(UnknownField::TYPE_FIXED32);
  field.data_.fixed32_ = value;
  if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
  fields_->push_back(field);
}

void UnknownFieldSet::AddFixed64(int number, uint64 value) {
  UnknownField field;
  field.number_ = number;
  field.SetType(UnknownField::TYPE_FIXED64);
  field.data_.fixed64_ = value;
  if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
  fields_->push_back(field);
}

string* UnknownFieldSet::AddLengthDelimited(int number) {
  UnknownField field;
  field.number_ = number;
  field.SetType(UnknownField::TYPE_LENGTH_DELIMITED);
  field.data_.length_delimited_.string_value_ = new string;
  if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
  fields_->push_back(field);
  return field.data_.length_delimited_.string_value_;
}

UnknownFieldSet* UnknownFieldSet::AddGroup(int number) {
  UnknownField field;
  field.number_ = number;
  field.SetType(UnknownField::TYPE_GROUP);
  field.data_.group_ = new UnknownFieldSet;
  if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
  fields_->push_back(field);
  return field.data_.group_;
}

void UnknownFieldSet::AddField(const UnknownField& field) {
  if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
  fields_->push_back(field);
  fields_->back().DeepCopy(field);
}

void UnknownFieldSet::DeleteSubrange(int start, int num) {
  // Delete the specified fields.
  for (int i = 0; i < num; ++i) {
    (*fields_)[i + start].Delete();
  }
  // Slide down the remaining fields.
  for (int i = start + num; i < fields_->size(); ++i) {
    (*fields_)[i - num] = (*fields_)[i];
  }
  // Pop off the # of deleted fields.
  for (int i = 0; i < num; ++i) {
    fields_->pop_back();
  }
  if (fields_ && fields_->size() == 0) {
    // maintain invariant: never hold fields_ if empty.
    delete fields_;
    fields_ = NULL;
  }
}

void UnknownFieldSet::DeleteByNumber(int number) {
  if (fields_ == NULL) return;
  int left = 0;  // The number of fields left after deletion.
  for (int i = 0; i < fields_->size(); ++i) {
    UnknownField* field = &(*fields_)[i];
    if (field->number() == number) {
      field->Delete();
    } else {
      if (i != left) {
        (*fields_)[left] = (*fields_)[i];
      }
      ++left;
    }
  }
  fields_->resize(left);
  if (left == 0) {
    // maintain invariant: never hold fields_ if empty.
    delete fields_;
    fields_ = NULL;
  }
}

bool UnknownFieldSet::MergeFromCodedStream(io::CodedInputStream* input) {
  UnknownFieldSet other;
  if (internal::WireFormat::SkipMessage(input, &other) &&
      input->ConsumedEntireMessage()) {
    MergeFromAndDestroy(&other);
    return true;
  } else {
    return false;
  }
}

bool UnknownFieldSet::ParseFromCodedStream(io::CodedInputStream* input) {
  Clear();
  return MergeFromCodedStream(input);
}

bool UnknownFieldSet::ParseFromZeroCopyStream(io::ZeroCopyInputStream* input) {
  io::CodedInputStream coded_input(input);
  return (ParseFromCodedStream(&coded_input) &&
          coded_input.ConsumedEntireMessage());
}

bool UnknownFieldSet::ParseFromArray(const void* data, int size) {
  io::ArrayInputStream input(data, size);
  return ParseFromZeroCopyStream(&input);
}

void UnknownField::Delete() {
  switch (type()) {
    case UnknownField::TYPE_LENGTH_DELIMITED:
      delete data_.length_delimited_.string_value_;
      break;
    case UnknownField::TYPE_GROUP:
      delete data_.group_;
      break;
    default:
      break;
  }
}

// Reset all owned ptrs, a special function for performance, to avoid double
// owning the ptrs, when we merge from a temporary UnknownFieldSet objects.
void UnknownField::Reset() {
  switch (type()) {
    case UnknownField::TYPE_LENGTH_DELIMITED:
      data_.length_delimited_.string_value_ = NULL;
      break;
    case UnknownField::TYPE_GROUP: {
      data_.group_ = NULL;
      break;
    }
    default:
      break;
  }
}

void UnknownField::DeepCopy(const UnknownField& other) {
  switch (type()) {
    case UnknownField::TYPE_LENGTH_DELIMITED:
      data_.length_delimited_.string_value_ = new string(
          *data_.length_delimited_.string_value_);
      break;
    case UnknownField::TYPE_GROUP: {
      UnknownFieldSet* group = new UnknownFieldSet();
      group->InternalMergeFrom(*data_.group_);
      data_.group_ = group;
      break;
    }
    default:
      break;
  }
}

void UnknownField::SerializeLengthDelimitedNoTag(
    io::CodedOutputStream* output) const {
  GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type());
  const string& data = *data_.length_delimited_.string_value_;
  output->WriteVarint32(data.size());
  output->WriteRawMaybeAliased(data.data(), data.size());
}

uint8* UnknownField::SerializeLengthDelimitedNoTagToArray(uint8* target) const {
  GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type());
  const string& data = *data_.length_delimited_.string_value_;
  target = io::CodedOutputStream::WriteVarint32ToArray(data.size(), target);
  target = io::CodedOutputStream::WriteStringToArray(data, target);
  return target;
}

}  // namespace protobuf
}  // namespace google


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Test schema for proto3 messages.  This test schema is used by:
//
// - benchmarks
// - fuzz tests
// - conformance tests
//

syntax = "proto3";

package protobuf_test_messages.proto3;
option java_package = "com.google.protobuf_test_messages.proto3";
option objc_class_prefix = "Proto3";

// This is the default, but we specify it here explicitly.
option optimize_for = SPEED;

import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

option cc_enable_arenas = true;

// This proto includes every type of field in both singular and repeated
// forms.
//
// Also, crucially, all messages and enums in this file are eventually
// submessages of this message.  So for example, a fuzz test of TestAllTypes
// could trigger bugs that occur in any message type in this file.  We verify
// this stays true in a unit test.
message TestAllTypesProto3 {
  message NestedMessage {
    int32 a = 1;
    TestAllTypesProto3 corecursive = 2;
  }

  enum NestedEnum {
    FOO = 0;
    BAR = 1;
    BAZ = 2;
    NEG = -1;  // Intentionally negative.
  }

  // Singular
  int32 optional_int32    =  1;
  int64 optional_int64    =  2;
  uint32 optional_uint32   =  3;
  uint64 optional_uint64   =  4;
  sint32 optional_sint32   =  5;
  sint64 optional_sint64   =  6;
  fixed32 optional_fixed32  =  7;
  fixed64 optional_fixed64  =  8;
  sfixed32 optional_sfixed32 =  9;
  sfixed64 optional_sfixed64 = 10;
  float optional_float    = 11;
  double optional_double   = 12;
  bool optional_bool     = 13;
  string optional_string   = 14;
  bytes optional_bytes    = 15;

  NestedMessage                        optional_nested_message  = 18;
  ForeignMessage                       optional_foreign_message = 19;

  NestedEnum                           optional_nested_enum     = 21;
  ForeignEnum                          optional_foreign_enum    = 22;

  string optional_string_piece = 24 [ctype=STRING_PIECE];
  string optional_cord = 25 [ctype=CORD];

  TestAllTypesProto3 recursive_message = 27;

  // Repeated
  repeated    int32 repeated_int32    = 31;
  repeated    int64 repeated_int64    = 32;
  repeated   uint32 repeated_uint32   = 33;
  repeated   uint64 repeated_uint64   = 34;
  repeated   sint32 repeated_sint32   = 35;
  repeated   sint64 repeated_sint64   = 36;
  repeated  fixed32 repeated_fixed32  = 37;
  repeated  fixed64 repeated_fixed64  = 38;
  repeated sfixed32 repeated_sfixed32 = 39;
  repeated sfixed64 repeated_sfixed64 = 40;
  repeated    float repeated_float    = 41;
  repeated   double repeated_double   = 42;
  repeated     bool repeated_bool     = 43;
  repeated   string repeated_string   = 44;
  repeated    bytes repeated_bytes    = 45;

  repeated NestedMessage                        repeated_nested_message  = 48;
  repeated ForeignMessage                       repeated_foreign_message = 49;

  repeated NestedEnum                           repeated_nested_enum     = 51;
  repeated ForeignEnum                          repeated_foreign_enum    = 52;

  repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
  repeated string repeated_cord = 55 [ctype=CORD];

  // Map
  map <   int32, int32>    map_int32_int32 = 56;
  map <   int64, int64>    map_int64_int64 = 57;
  map <  uint32, uint32>   map_uint32_uint32 = 58;
  map <  uint64, uint64>   map_uint64_uint64 = 59;
  map <  sint32, sint32>   map_sint32_sint32 = 60;
  map <  sint64, sint64>   map_sint64_sint64 = 61;
  map < fixed32, fixed32>  map_fixed32_fixed32 = 62;
  map < fixed64, fixed64>  map_fixed64_fixed64 = 63;
  map <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64;
  map <sfixed64, sfixed64> map_sfixed64_sfixed64 = 65;
  map <   int32, float>    map_int32_float = 66;
  map <   int32, double>   map_int32_double = 67;
  map <    bool, bool>     map_bool_bool = 68;
  map <  string, string>   map_string_string = 69;
  map <  string, bytes>    map_string_bytes = 70;
  map <  string, NestedMessage>  map_string_nested_message = 71;
  map <  string, ForeignMessage> map_string_foreign_message = 72;
  map <  string, NestedEnum>     map_string_nested_enum = 73;
  map <  string, ForeignEnum>    map_string_foreign_enum = 74;

  oneof oneof_field {
    uint32 oneof_uint32 = 111;
    NestedMessage oneof_nested_message = 112;
    string oneof_string = 113;
    bytes oneof_bytes = 114;
    bool oneof_bool = 115;
    uint64 oneof_uint64 = 116;
    float oneof_float = 117;
    double oneof_double = 118;
    NestedEnum oneof_enum = 119;
  }

  // Well-known types
  google.protobuf.BoolValue optional_bool_wrapper = 201;
  google.protobuf.Int32Value optional_int32_wrapper = 202;
  google.protobuf.Int64Value optional_int64_wrapper = 203;
  google.protobuf.UInt32Value optional_uint32_wrapper = 204;
  google.protobuf.UInt64Value optional_uint64_wrapper = 205;
  google.protobuf.FloatValue optional_float_wrapper = 206;
  google.protobuf.DoubleValue optional_double_wrapper = 207;
  google.protobuf.StringValue optional_string_wrapper = 208;
  google.protobuf.BytesValue optional_bytes_wrapper = 209;

  repeated google.protobuf.BoolValue repeated_bool_wrapper = 211;
  repeated google.protobuf.Int32Value repeated_int32_wrapper = 212;
  repeated google.protobuf.Int64Value repeated_int64_wrapper = 213;
  repeated google.protobuf.UInt32Value repeated_uint32_wrapper = 214;
  repeated google.protobuf.UInt64Value repeated_uint64_wrapper = 215;
  repeated google.protobuf.FloatValue repeated_float_wrapper = 216;
  repeated google.protobuf.DoubleValue repeated_double_wrapper = 217;
  repeated google.protobuf.StringValue repeated_string_wrapper = 218;
  repeated google.protobuf.BytesValue repeated_bytes_wrapper = 219;

  google.protobuf.Duration optional_duration = 301;
  google.protobuf.Timestamp optional_timestamp = 302;
  google.protobuf.FieldMask optional_field_mask = 303;
  google.protobuf.Struct optional_struct = 304;
  google.protobuf.Any optional_any = 305;
  google.protobuf.Value optional_value = 306;

  repeated google.protobuf.Duration repeated_duration = 311;
  repeated google.protobuf.Timestamp repeated_timestamp = 312;
  repeated google.protobuf.FieldMask repeated_fieldmask = 313;
  repeated google.protobuf.Struct repeated_struct = 324;
  repeated google.protobuf.Any repeated_any = 315;
  repeated google.protobuf.Value repeated_value = 316;

  // Test field-name-to-JSON-name convention.
  // (protobuf says names can be any valid C/C++ identifier.)
  int32 fieldname1 = 401;
  int32 field_name2 = 402;
  int32 _field_name3 = 403;
  int32 field__name4_ = 404;
  int32 field0name5 = 405;
  int32 field_0_name6 = 406;
  int32 fieldName7 = 407;
  int32 FieldName8 = 408;
  int32 field_Name9 = 409;
  int32 Field_Name10 = 410;
  int32 FIELD_NAME11 = 411;
  int32 FIELD_name12 = 412;
  int32 __field_name13 = 413;
  int32 __Field_name14 = 414;
  int32 field__name15 = 415;
  int32 field__Name16 = 416;
  int32 field_name17__ = 417;
  int32 Field_name18__ = 418;

  // Reserved for testing unknown fields
  reserved 501 to 510;
}

message ForeignMessage {
  int32 c = 1;
}

enum ForeignEnum {
  FOREIGN_FOO = 0;
  FOREIGN_BAR = 1;
  FOREIGN_BAZ = 2;
}


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Author: liujisi@google.com (Pherl Liu)

syntax = "proto2";

package protobuf_unittest_import;

option optimize_for = LITE_RUNTIME;

option java_package = "com.google.protobuf";

message PublicImportMessageLite {
  optional int32 e = 1;
}


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Author: kenton@google.com (Kenton Varda)
//
// This is like unittest.proto but with optimize_for = LITE_RUNTIME.

syntax = "proto2";
package protobuf_unittest;

import "google/protobuf/unittest_import_lite.proto";

option optimize_for = LITE_RUNTIME;

option java_package = "com.google.protobuf";

// Same as TestAllTypes but with the lite runtime.
message TestAllTypesLite {

  message NestedMessage {
    optional int32 bb = 1;
    optional int64 cc = 2;
  }

  enum NestedEnum {
    FOO = 1;
    BAR = 2;
    BAZ = 3;
  }

  // Singular
  optional    int32 optional_int32    =  1;
  optional    int64 optional_int64    =  2;
  optional   uint32 optional_uint32   =  3;
  optional   uint64 optional_uint64   =  4;
  optional   sint32 optional_sint32   =  5;
  optional   sint64 optional_sint64   =  6;
  optional  fixed32 optional_fixed32  =  7;
  optional  fixed64 optional_fixed64  =  8;
  optional sfixed32 optional_sfixed32 =  9;
  optional sfixed64 optional_sfixed64 = 10;
  optional    float optional_float    = 11;
  optional   double optional_double   = 12;
  optional     bool optional_bool     = 13;
  optional   string optional_string   = 14;
  optional    bytes optional_bytes    = 15;

  optional group OptionalGroup = 16 {
    optional int32 a = 17;
  }

  optional NestedMessage      optional_nested_message  = 18;
  optional ForeignMessageLite optional_foreign_message = 19;
  optional protobuf_unittest_import.ImportMessageLite
    optional_import_message = 20;

  optional NestedEnum      optional_nested_enum     = 21;
  optional ForeignEnumLite optional_foreign_enum    = 22;
  optional protobuf_unittest_import.ImportEnumLite optional_import_enum = 23;

  optional string optional_string_piece = 24 [ctype=STRING_PIECE];
  optional string optional_cord = 25 [ctype=CORD];

  // Defined in unittest_import_public.proto
  optional protobuf_unittest_import.PublicImportMessageLite
      optional_public_import_message = 26;

  optional NestedMessage optional_lazy_message = 27 [lazy=true];

  // Repeated
  repeated    int32 repeated_int32    = 31;
  repeated    int64 repeated_int64    = 32;
  repeated   uint32 repeated_uint32   = 33;
  repeated   uint64 repeated_uint64   = 34;
  repeated   sint32 repeated_sint32   = 35;
  repeated   sint64 repeated_sint64   = 36;
  repeated  fixed32 repeated_fixed32  = 37;
  repeated  fixed64 repeated_fixed64  = 38;
  repeated sfixed32 repeated_sfixed32 = 39;
  repeated sfixed64 repeated_sfixed64 = 40;
  repeated    float repeated_float    = 41;
  repeated   double repeated_double   = 42;
  repeated     bool repeated_bool     = 43;
  repeated   string repeated_string   = 44;
  repeated    bytes repeated_bytes    = 45;

  repeated group RepeatedGroup = 46 {
    optional int32 a = 47;
  }

  repeated NestedMessage      repeated_nested_message  = 48;
  repeated ForeignMessageLite repeated_foreign_message = 49;
  repeated protobuf_unittest_import.ImportMessageLite
    repeated_import_message = 50;

  repeated NestedEnum      repeated_nested_enum  = 51;
  repeated ForeignEnumLite repeated_foreign_enum = 52;
  repeated protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53;

  repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
  repeated string repeated_cord = 55 [ctype=CORD];

  repeated NestedMessage repeated_lazy_message = 57 [lazy=true];

  // Singular with defaults
  optional    int32 default_int32    = 61 [default =  41    ];
  optional    int64 default_int64    = 62 [default =  42    ];
  optional   uint32 default_uint32   = 63 [default =  43    ];
  optional   uint64 default_uint64   = 64 [default =  44    ];
  optional   sint32 default_sint32   = 65 [default = -45    ];
  optional   sint64 default_sint64   = 66 [default =  46    ];
  optional  fixed32 default_fixed32  = 67 [default =  47    ];
  optional  fixed64 default_fixed64  = 68 [default =  48    ];
  optional sfixed32 default_sfixed32 = 69 [default =  49    ];
  optional sfixed64 default_sfixed64 = 70 [default = -50    ];
  optional    float default_float    = 71 [default =  51.5  ];
  optional   double default_double   = 72 [default =  52e3  ];
  optional     bool default_bool     = 73 [default = true   ];
  optional   string default_string   = 74 [default = "hello"];
  optional    bytes default_bytes    = 75 [default = "world"];

  optional NestedEnum default_nested_enum = 81 [default = BAR];
  optional ForeignEnumLite default_foreign_enum = 82
      [default = FOREIGN_LITE_BAR];
  optional protobuf_unittest_import.ImportEnumLite
      default_import_enum = 83 [default = IMPORT_LITE_BAR];

  optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
  optional string default_cord = 85 [ctype=CORD,default="123"];

  // For oneof test
  oneof oneof_field {
    uint32 oneof_uint32 = 111;
    NestedMessage oneof_nested_message = 112;
    string oneof_string = 113;
    bytes oneof_bytes = 114;
    NestedMessage oneof_lazy_nested_message = 115 [lazy = true];
  }

  // Tests toString for non-repeated fields with a list suffix
  optional int32 deceptively_named_list = 116;
}

message ForeignMessageLite {
  optional int32 c = 1;
}

enum ForeignEnumLite {
  FOREIGN_LITE_FOO = 4;
  FOREIGN_LITE_BAR = 5;
  FOREIGN_LITE_BAZ = 6;
}

message TestPackedTypesLite {
  repeated    int32 packed_int32    =  90 [packed = true];
  repeated    int64 packed_int64    =  91 [packed = true];
  repeated   uint32 packed_uint32   =  92 [packed = true];
  repeated   uint64 packed_uint64   =  93 [packed = true];
  repeated   sint32 packed_sint32   =  94 [packed = true];
  repeated   sint64 packed_sint64   =  95 [packed = true];
  repeated  fixed32 packed_fixed32  =  96 [packed = true];
  repeated  fixed64 packed_fixed64  =  97 [packed = true];
  repeated sfixed32 packed_sfixed32 =  98 [packed = true];
  repeated sfixed64 packed_sfixed64 =  99 [packed = true];
  repeated    float packed_float    = 100 [packed = true];
  repeated   double packed_double   = 101 [packed = true];
  repeated     bool packed_bool     = 102 [packed = true];
  repeated ForeignEnumLite packed_enum  = 103 [packed = true];
}

message TestAllExtensionsLite {
  extensions 1 to max;
}

extend TestAllExtensionsLite {
  // Singular
  optional    int32 optional_int32_extension_lite    =  1;
  optional    int64 optional_int64_extension_lite    =  2;
  optional   uint32 optional_uint32_extension_lite   =  3;
  optional   uint64 optional_uint64_extension_lite   =  4;
  optional   sint32 optional_sint32_extension_lite   =  5;
  optional   sint64 optional_sint64_extension_lite   =  6;
  optional  fixed32 optional_fixed32_extension_lite  =  7;
  optional  fixed64 optional_fixed64_extension_lite  =  8;
  optional sfixed32 optional_sfixed32_extension_lite =  9;
  optional sfixed64 optional_sfixed64_extension_lite = 10;
  optional    float optional_float_extension_lite    = 11;
  optional   double optional_double_extension_lite   = 12;
  optional     bool optional_bool_extension_lite     = 13;
  optional   string optional_string_extension_lite   = 14;
  optional    bytes optional_bytes_extension_lite    = 15;

  optional group OptionalGroup_extension_lite = 16 {
    optional int32 a = 17;
  }

  optional TestAllTypesLite.NestedMessage optional_nested_message_extension_lite
      = 18;
  optional ForeignMessageLite optional_foreign_message_extension_lite = 19;
  optional protobuf_unittest_import.ImportMessageLite
    optional_import_message_extension_lite = 20;

  optional TestAllTypesLite.NestedEnum optional_nested_enum_extension_lite = 21;
  optional ForeignEnumLite optional_foreign_enum_extension_lite = 22;
  optional protobuf_unittest_import.ImportEnumLite
    optional_import_enum_extension_lite = 23;

  optional string optional_string_piece_extension_lite = 24
      [ctype=STRING_PIECE];
  optional string optional_cord_extension_lite = 25 [ctype=CORD];

  optional protobuf_unittest_import.PublicImportMessageLite
    optional_public_import_message_extension_lite = 26;

  optional TestAllTypesLite.NestedMessage
    optional_lazy_message_extension_lite = 27 [lazy=true];

  // Repeated
  repeated    int32 repeated_int32_extension_lite    = 31;
  repeated    int64 repeated_int64_extension_lite    = 32;
  repeated   uint32 repeated_uint32_extension_lite   = 33;
  repeated   uint64 repeated_uint64_extension_lite   = 34;
  repeated   sint32 repeated_sint32_extension_lite   = 35;
  repeated   sint64 repeated_sint64_extension_lite   = 36;
  repeated  fixed32 repeated_fixed32_extension_lite  = 37;
  repeated  fixed64 repeated_fixed64_extension_lite  = 38;
  repeated sfixed32 repeated_sfixed32_extension_lite = 39;
  repeated sfixed64 repeated_sfixed64_extension_lite = 40;
  repeated    float repeated_float_extension_lite    = 41;
  repeated   double repeated_double_extension_lite   = 42;
  repeated     bool repeated_bool_extension_lite     = 43;
  repeated   string repeated_string_extension_lite   = 44;
  repeated    bytes repeated_bytes_extension_lite    = 45;

  repeated group RepeatedGroup_extension_lite = 46 {
    optional int32 a = 47;
  }

  repeated TestAllTypesLite.NestedMessage repeated_nested_message_extension_lite
      = 48;
  repeated ForeignMessageLite repeated_foreign_message_extension_lite = 49;
  repeated protobuf_unittest_import.ImportMessageLite
    repeated_import_message_extension_lite = 50;

  repeated TestAllTypesLite.NestedEnum repeated_nested_enum_extension_lite = 51;
  repeated ForeignEnumLite repeated_foreign_enum_extension_lite = 52;
  repeated protobuf_unittest_import.ImportEnumLite
    repeated_import_enum_extension_lite = 53;

  repeated string repeated_string_piece_extension_lite = 54
      [ctype=STRING_PIECE];
  repeated string repeated_cord_extension_lite = 55 [ctype=CORD];

  repeated TestAllTypesLite.NestedMessage
    repeated_lazy_message_extension_lite = 57 [lazy=true];

  // Singular with defaults
  optional    int32 default_int32_extension_lite    = 61 [default =  41    ];
  optional    int64 default_int64_extension_lite    = 62 [default =  42    ];
  optional   uint32 default_uint32_extension_lite   = 63 [default =  43    ];
  optional   uint64 default_uint64_extension_lite   = 64 [default =  44    ];
  optional   sint32 default_sint32_extension_lite   = 65 [default = -45    ];
  optional   sint64 default_sint64_extension_lite   = 66 [default =  46    ];
  optional  fixed32 default_fixed32_extension_lite  = 67 [default =  47    ];
  optional  fixed64 default_fixed64_extension_lite  = 68 [default =  48    ];
  optional sfixed32 default_sfixed32_extension_lite = 69 [default =  49    ];
  optional sfixed64 default_sfixed64_extension_lite = 70 [default = -50    ];
  optional    float default_float_extension_lite    = 71 [default =  51.5  ];
  optional   double default_double_extension_lite   = 72 [default =  52e3  ];
  optional     bool default_bool_extension_lite     = 73 [default = true   ];
  optional   string default_string_extension_lite   = 74 [default = "hello"];
  optional    bytes default_bytes_extension_lite    = 75 [default = "world"];

  optional TestAllTypesLite.NestedEnum
    default_nested_enum_extension_lite = 81 [default = BAR];
  optional ForeignEnumLite
    default_foreign_enum_extension_lite = 82 [default = FOREIGN_LITE_BAR];
  optional protobuf_unittest_import.ImportEnumLite
    default_import_enum_extension_lite = 83 [default = IMPORT_LITE_BAR];

  optional string default_string_piece_extension_lite = 84 [ctype=STRING_PIECE,
                                                            default="abc"];
  optional string default_cord_extension_lite = 85 [ctype=CORD, default="123"];

  // For oneof test
  optional uint32 oneof_uint32_extension_lite = 111;
  optional TestAllTypesLite.NestedMessage oneof_nested_message_extension_lite = 112;
  optional string oneof_string_extension_lite = 113;
  optional bytes oneof_bytes_extension_lite = 114;
}

message TestPackedExtensionsLite {
  extensions 1 to max;
}

extend TestPackedExtensionsLite {
  repeated    int32 packed_int32_extension_lite    =  90 [packed = true];
  repeated    int64 packed_int64_extension_lite    =  91 [packed = true];
  repeated   uint32 packed_uint32_extension_lite   =  92 [packed = true];
  repeated   uint64 packed_uint64_extension_lite   =  93 [packed = true];
  repeated   sint32 packed_sint32_extension_lite   =  94 [packed = true];
  repeated   sint64 packed_sint64_extension_lite   =  95 [packed = true];
  repeated  fixed32 packed_fixed32_extension_lite  =  96 [packed = true];
  repeated  fixed64 packed_fixed64_extension_lite  =  97 [packed = true];
  repeated sfixed32 packed_sfixed32_extension_lite =  98 [packed = true];
  repeated sfixed64 packed_sfixed64_extension_lite =  99 [packed = true];
  repeated    float packed_float_extension_lite    = 100 [packed = true];
  repeated   double packed_double_extension_lite   = 101 [packed = true];
  repeated     bool packed_bool_extension_lite     = 102 [packed = true];
  repeated ForeignEnumLite packed_enum_extension_lite = 103 [packed = true];
}

message TestNestedExtensionLite {
  extend TestAllExtensionsLite {
    optional int32 nested_extension = 12345;
  }
}

// Test that deprecated fields work.  We only verify that they compile (at one
// point this failed).
message TestDeprecatedLite {
  optional int32 deprecated_field = 1 [deprecated = true];
}

// See the comments of the same type in unittest.proto.
message TestParsingMergeLite {
  message RepeatedFieldsGenerator {
    repeated TestAllTypesLite field1 = 1;
    repeated TestAllTypesLite field2 = 2;
    repeated TestAllTypesLite field3 = 3;
    repeated group Group1 = 10 {
      optional TestAllTypesLite field1 = 11;
    }
    repeated group Group2 = 20 {
      optional TestAllTypesLite field1 = 21;
    }
    repeated TestAllTypesLite ext1 = 1000;
    repeated TestAllTypesLite ext2 = 1001;
  }
  required TestAllTypesLite required_all_types = 1;
  optional TestAllTypesLite optional_all_types = 2;
  repeated TestAllTypesLite repeated_all_types = 3;
  optional group OptionalGroup = 10 {
    optional TestAllTypesLite optional_group_all_types = 11;
  }
  repeated group RepeatedGroup = 20 {
    optional TestAllTypesLite repeated_group_all_types = 21;
  }
  extensions 1000 to max;
  extend TestParsingMergeLite {
    optional TestAllTypesLite optional_ext = 1000;
    repeated TestAllTypesLite repeated_ext = 1001;
  }
}

// TestEmptyMessageLite is used to test unknown fields support in lite mode.
message TestEmptyMessageLite{
}

// Like above, but declare all field numbers as potential extensions.  No
// actual extensions should ever be defined for this type.
message TestEmptyMessageWithExtensionsLite {
  extensions 1 to max;
}

enum V1EnumLite {
    V1_FIRST = 1;
}

enum V2EnumLite {
    V2_FIRST = 1;
    V2_SECOND = 2;
}

message V1MessageLite {
    required int32 int_field = 1;
    optional V1EnumLite enum_field = 2 [ default = V1_FIRST ];
}

message V2MessageLite {
    required int32 int_field = 1;
    optional V2EnumLite enum_field = 2 [ default = V2_FIRST ];
}

message TestHugeFieldNumbersLite {
  optional int32 optional_int32 = 536870000;
  optional int32 fixed_32 = 536870001;
  repeated int32 repeated_int32 = 536870002 [packed = false];
  repeated int32 packed_int32 = 536870003 [packed = true];

  optional ForeignEnumLite optional_enum = 536870004;
  optional string optional_string = 536870005;
  optional bytes optional_bytes = 536870006;
  optional ForeignMessageLite optional_message = 536870007;

  optional group OptionalGroup = 536870008 {
    optional int32 group_a = 536870009;
  }

  map<string, string> string_string_map = 536870010;

  oneof oneof_field {
    uint32 oneof_uint32 = 536870011;
    TestAllTypesLite oneof_test_all_types = 536870012;
    string oneof_string = 536870013;
    bytes oneof_bytes = 536870014;
  }

  extensions  536860000 to 536869999;
}

extend TestHugeFieldNumbersLite {
  optional TestAllTypesLite test_all_types_lite = 536860000;
}

message TestOneofParsingLite {
  oneof oneof_field {
    int32 oneof_int32 = 1;
    TestAllTypesLite oneof_submessage = 2;
    string oneof_string = 3;
    bytes oneof_bytes = 4 [default = "default bytes"];
    string oneof_string_cord = 5 [ctype = CORD, default = "default Cord"];
    bytes oneof_bytes_cord = 6 [ctype = CORD];
    string oneof_string_string_piece = 7 [ctype = STRING_PIECE];
    bytes oneof_bytes_string_piece = 8
        [ctype = STRING_PIECE, default = "default StringPiece"];
    V2EnumLite oneof_enum = 9;
  }
}


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <memory>
#ifndef _SHARED_PTR_H
#include <google/protobuf/stubs/shared_ptr.h>
#endif

#include <google/protobuf/unittest_drop_unknown_fields.pb.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>

namespace google {
using unittest_drop_unknown_fields::Foo;
using unittest_drop_unknown_fields::FooWithExtraFields;

namespace protobuf {

TEST(DropUnknownFieldsTest, GeneratedMessageDefaultDrop) {
  ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(false);
  FooWithExtraFields foo_with_extra_fields;
  foo_with_extra_fields.set_int32_value(1);
  foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX);
  foo_with_extra_fields.set_extra_int32_value(2);

  Foo foo;
  ASSERT_TRUE(foo.ParseFromString(foo_with_extra_fields.SerializeAsString()));
  EXPECT_EQ(1, foo.int32_value());
  EXPECT_EQ(static_cast<int>(FooWithExtraFields::QUX),
            static_cast<int>(foo.enum_value()));
  EXPECT_TRUE(foo.GetReflection()->GetUnknownFields(foo).empty());

  ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo.SerializeAsString()));
  EXPECT_EQ(1, foo_with_extra_fields.int32_value());
  EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value());
  // The "extra_int32_value" field should be lost.
  EXPECT_EQ(0, foo_with_extra_fields.extra_int32_value());
}

TEST(DropUnknownFieldsTest, GeneratedMessageDefaultPreserve) {
  ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(true);
  FooWithExtraFields foo_with_extra_fields;
  foo_with_extra_fields.set_int32_value(1);
  foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX);
  foo_with_extra_fields.set_extra_int32_value(2);

  Foo foo;
  ASSERT_TRUE(foo.ParseFromString(foo_with_extra_fields.SerializeAsString()));
  EXPECT_EQ(1, foo.int32_value());
  EXPECT_EQ(static_cast<int>(FooWithExtraFields::QUX),
            static_cast<int>(foo.enum_value()));
  EXPECT_FALSE(foo.GetReflection()->GetUnknownFields(foo).empty());

  ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo.SerializeAsString()));
  EXPECT_EQ(1, foo_with_extra_fields.int32_value());
  EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value());
  // The "extra_int32_value" field should not be lost.
  EXPECT_EQ(2, foo_with_extra_fields.extra_int32_value());
}

TEST(DropUnknownFieldsTest, DynamicMessageDefaultDrop) {
  internal::SetProto3PreserveUnknownsDefault(false);
  FooWithExtraFields foo_with_extra_fields;
  foo_with_extra_fields.set_int32_value(1);
  foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX);
  foo_with_extra_fields.set_extra_int32_value(2);

  google::protobuf::DynamicMessageFactory factory;
  google::protobuf::scoped_ptr<google::protobuf::Message> foo(
      factory.GetPrototype(Foo::descriptor())->New());
  ASSERT_TRUE(foo->ParseFromString(foo_with_extra_fields.SerializeAsString()));
  EXPECT_TRUE(foo->GetReflection()->GetUnknownFields(*foo).empty());

  ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo->SerializeAsString()));
  EXPECT_EQ(1, foo_with_extra_fields.int32_value());
  EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value());
  // The "extra_int32_value" field should be lost.
  EXPECT_EQ(0, foo_with_extra_fields.extra_int32_value());
}

TEST(DropUnknownFieldsTest, DynamicMessageDefaultPreserve) {
  internal::SetProto3PreserveUnknownsDefault(true);
  FooWithExtraFields foo_with_extra_fields;
  foo_with_extra_fields.set_int32_value(1);
  foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX);
  foo_with_extra_fields.set_extra_int32_value(2);

  google::protobuf::DynamicMessageFactory factory;
  google::protobuf::scoped_ptr<google::protobuf::Message> foo(
      factory.GetPrototype(Foo::descriptor())->New());
  ASSERT_TRUE(foo->ParseFromString(foo_with_extra_fields.SerializeAsString()));
  EXPECT_FALSE(foo->GetReflection()->GetUnknownFields(*foo).empty());

  ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo->SerializeAsString()));
  EXPECT_EQ(1, foo_with_extra_fields.int32_value());
  EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value());
  // The "extra_int32_value" field should not be lost.
  EXPECT_EQ(2, foo_with_extra_fields.extra_int32_value());
}

}  // namespace protobuf
}  // namespace google


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Author: kenton@google.com (Kenton Varda)
//  Based on original Protocol Buffers design by
//  Sanjay Ghemawat, Jeff Dean, and others.
//
// This file contains messages for testing message_set_wire_format.

syntax = "proto2";
package proto2_wireformat_unittest;

option cc_enable_arenas = true;
option optimize_for = SPEED;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";

// A message with message_set_wire_format.
message TestMessageSet {
  option message_set_wire_format = true;
  extensions 4 to max;
}

message TestMessageSetWireFormatContainer {
  optional TestMessageSet message_set = 1;
}


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <google/protobuf/unittest_well_known_types.pb.h>

#include <google/protobuf/stubs/common.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/stl_util.h>

namespace google {
namespace protobuf {
namespace {

// This test only checks whether well-known types are included in protobuf
// runtime library. The test passes if it compiles.
TEST(WellKnownTypesTest, AllKnownTypesAreIncluded) {
  protobuf_unittest::TestWellKnownTypes message;
  EXPECT_EQ(0, message.any_field().ByteSize());
  EXPECT_EQ(0, message.api_field().ByteSize());
  EXPECT_EQ(0, message.duration_field().ByteSize());
  EXPECT_EQ(0, message.empty_field().ByteSize());
  EXPECT_EQ(0, message.field_mask_field().ByteSize());
  EXPECT_EQ(0, message.source_context_field().ByteSize());
  EXPECT_EQ(0, message.struct_field().ByteSize());
  EXPECT_EQ(0, message.timestamp_field().ByteSize());
  EXPECT_EQ(0, message.type_field().ByteSize());
  EXPECT_EQ(0, message.int32_field().ByteSize());
}

}  // namespace

}  // namespace protobuf
}  // namespace google


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Author: kenton@google.com (Kenton Varda)
//  Based on original Protocol Buffers design by
//  Sanjay Ghemawat, Jeff Dean, and others.
//
// This file exists solely to document the google::protobuf namespace.
// It is not compiled into anything, but it may be read by an automated
// documentation generator.

namespace google {

// Core components of the Protocol Buffers runtime library.
//
// The files in this package represent the core of the Protocol Buffer
// system.  All of them are part of the libprotobuf library.
//
// A note on thread-safety:
//
// Thread-safety in the Protocol Buffer library follows a simple rule:
// unless explicitly noted otherwise, it is always safe to use an object
// from multiple threads simultaneously as long as the object is declared
// const in all threads (or, it is only used in ways that would be allowed
// if it were declared const).  However, if an object is accessed in one
// thread in a way that would not be allowed if it were const, then it is
// not safe to access that object in any other thread simultaneously.
//
// Put simply, read-only access to an object can happen in multiple threads
// simultaneously, but write access can only happen in a single thread at
// a time.
//
// The implementation does contain some "const" methods which actually modify
// the object behind the scenes -- e.g., to cache results -- but in these cases
// mutex locking is used to make the access thread-safe.
namespace protobuf {}
}  // namespace google


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__
#define GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__

#include <google/protobuf/map_lite_unittest.pb.h>

namespace google {
namespace protobuf {

class MapLiteTestUtil {
 public:
  // Set every field in the TestMapLite message to a unique value.
  static void SetMapFields(protobuf_unittest::TestMapLite* message);

  // Set every field in the TestArenaMapLite message to a unique value.
  static void SetArenaMapFields(protobuf_unittest::TestArenaMapLite* message);

  // Set every field in the message to a default value.
  static void SetMapFieldsInitialized(protobuf_unittest::TestMapLite* message);

  // Modify all the map fields of the message (which should already have been
  // initialized with SetMapFields()).
  static void ModifyMapFields(protobuf_unittest::TestMapLite* message);

  // Check that all fields have the values that they should have after
  // SetMapFields() is called.
  static void ExpectMapFieldsSet(const protobuf_unittest::TestMapLite& message);

  // Check that all fields have the values that they should have after
  // SetMapFields() is called for TestArenaMapLite.
  static void ExpectArenaMapFieldsSet(
      const protobuf_unittest::TestArenaMapLite& message);

  // Check that all fields have the values that they should have after
  // SetMapFieldsInitialized() is called.
  static void ExpectMapFieldsSetInitialized(
      const protobuf_unittest::TestMapLite& message);

  // Expect that the message is modified as would be expected from
  // ModifyMapFields().
  static void ExpectMapFieldsModified(
      const protobuf_unittest::TestMapLite& message);

  // Check that all fields are empty.
  static void ExpectClear(const protobuf_unittest::TestMapLite& message);
};

}  // namespace protobuf

}  // namespace google
#endif  // GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__
#define GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__

#include <google/protobuf/map_field.h>
#include <google/protobuf/reflection.h>
#include <google/protobuf/repeated_field.h>

namespace google {
namespace protobuf {
namespace internal {
// A base class for RepeatedFieldAccessor implementations that can support
// random-access efficiently. All iterator methods delegates the work to
// corresponding random-access methods.
class RandomAccessRepeatedFieldAccessor : public RepeatedFieldAccessor {
 public:
  virtual ~RandomAccessRepeatedFieldAccessor() {}

  virtual Iterator* BeginIterator(const Field* data) const {
    return PositionToIterator(0);
  }
  virtual Iterator* EndIterator(const Field* data) const {
    return PositionToIterator(this->Size(data));
  }
  virtual Iterator* CopyIterator(const Field* data,
                                 const Iterator* iterator) const {
    return const_cast<Iterator*>(iterator);
  }
  virtual Iterator* AdvanceIterator(const Field* data,
                                    Iterator* iterator) const {
    return PositionToIterator(IteratorToPosition(iterator) + 1);
  }
  virtual bool EqualsIterator(const Field* data,
                              const Iterator* a,
                              const Iterator* b) const {
    return a == b;
  }
  virtual void DeleteIterator(const Field* data, Iterator* iterator) const {
  }
  virtual const Value* GetIteratorValue(const Field* data,
                                        const Iterator* iterator,
                                        Value* scratch_space) const {
    return Get(data, static_cast<int>(IteratorToPosition(iterator)),
               scratch_space);
  }

 private:
  static intptr_t IteratorToPosition(const Iterator* iterator) {
    return reinterpret_cast<intptr_t>(iterator);
  }
  static Iterator* PositionToIterator(intptr_t position) {
    return reinterpret_cast<Iterator*>(position);
  }
};

// Base class for RepeatedFieldAccessor implementations that manipulates
// RepeatedField<T>.
template<typename T>
class RepeatedFieldWrapper : public RandomAccessRepeatedFieldAccessor {
 public:
  RepeatedFieldWrapper() {}
  virtual ~RepeatedFieldWrapper() {}
  virtual bool IsEmpty(const Field* data) const {
    return GetRepeatedField(data)->empty();
  }
  virtual int Size(const Field* data) const {
    return GetRepeatedField(data)->size();
  }
  virtual const Value* Get(const Field* data, int index,
                          Value* scratch_space) const {
    return ConvertFromT(GetRepeatedField(data)->Get(index), scratch_space);
  }
  virtual void Clear(Field* data) const {
    MutableRepeatedField(data)->Clear();
  }
  virtual void Set(Field* data, int index, const Value* value) const {
    MutableRepeatedField(data)->Set(index, ConvertToT(value));
  }
  virtual void Add(Field* data, const Value* value) const {
    MutableRepeatedField(data)->Add(ConvertToT(value));
  }
  virtual void RemoveLast(Field* data) const {
    MutableRepeatedField(data)->RemoveLast();
  }
  virtual void SwapElements(Field* data, int index1, int index2) const {
    MutableRepeatedField(data)->SwapElements(index1, index2);
  }

 protected:
  typedef RepeatedField<T> RepeatedFieldType;
  static const RepeatedFieldType* GetRepeatedField(const Field* data) {
    return reinterpret_cast<const RepeatedFieldType*>(data);
  }
  static RepeatedFieldType* MutableRepeatedField(Field* data) {
    return reinterpret_cast<RepeatedFieldType*>(data);
  }

  // Convert an object recevied by this accessor to an object to be stored in
  // the underlying RepeatedField.
  virtual T ConvertToT(const Value* value) const = 0;

  // Convert an object stored in RepeatedPtrField to an object that will be
  // returned by this accessor. If the two objects have the same type (true
  // for string fields with ctype=STRING), a pointer to the source object can
  // be returned directly. Otherwise, data should be copied from value to
  // scratch_space and scratch_space should be returned.
  virtual const Value* ConvertFromT(const T& value,
                                    Value* scratch_space) const = 0;
};

// Base class for RepeatedFieldAccessor implementations that manipulates
// RepeatedPtrField<T>.
template<typename T>
class RepeatedPtrFieldWrapper : public RandomAccessRepeatedFieldAccessor {
 public:
  RepeatedPtrFieldWrapper() {}
  virtual ~RepeatedPtrFieldWrapper() {}
  virtual bool IsEmpty(const Field* data) const {
    return GetRepeatedField(data)->empty();
  }
  virtual int Size(const Field* data) const {
    return GetRepeatedField(data)->size();
  }
  virtual const Value* Get(const Field* data, int index,
                           Value* scratch_space) const {
    return ConvertFromT(GetRepeatedField(data)->Get(index), scratch_space);
  }
  virtual void Clear(Field* data) const {
    MutableRepeatedField(data)->Clear();
  }
  virtual void Set(Field* data, int index, const Value* value) const {
    ConvertToT(value, MutableRepeatedField(data)->Mutable(index));
  }
  virtual void Add(Field* data, const Value* value) const {
    T* allocated = New(value);
    ConvertToT(value, allocated);
    MutableRepeatedField(data)->AddAllocated(allocated);
  }
  virtual void RemoveLast(Field* data) const {
    MutableRepeatedField(data)->RemoveLast();
  }
  virtual void SwapElements(Field* data, int index1, int index2) const {
    MutableRepeatedField(data)->SwapElements(index1, index2);
  }

 protected:
  typedef RepeatedPtrField<T> RepeatedFieldType;
  static const RepeatedFieldType* GetRepeatedField(const Field* data) {
    return reinterpret_cast<const RepeatedFieldType*>(data);
  }
  static RepeatedFieldType* MutableRepeatedField(Field* data) {
    return reinterpret_cast<RepeatedFieldType*>(data);
  }

  // Create a new T instance. For repeated message fields, T can be specified
  // as google::protobuf::Message so we can't use "new T()" directly. In that case, value
  // should be a message of the same type (it's ensured by the caller) and a
  // new message object will be created using it.
  virtual T* New(const Value* value) const = 0;

  // Convert an object received by this accessor to an object that will be
  // stored in the underlying RepeatedPtrField.
  virtual void ConvertToT(const Value* value, T* result) const = 0;

  // Convert an object stored in RepeatedPtrField to an object that will be
  // returned by this accessor. If the two objects have the same type (true
  // for string fields with ctype=STRING), a pointer to the source object can
  // be returned directly. Otherwise, data should be copied from value to
  // scratch_space and scratch_space should be returned.
  virtual const Value* ConvertFromT(const T& value,
                                    Value* scratch_space) const = 0;
};

// An implementation of RandomAccessRepeatedFieldAccessor that manipulates
// MapFieldBase.
class MapFieldAccessor : public RandomAccessRepeatedFieldAccessor {
 public:
  MapFieldAccessor() {}
  virtual ~MapFieldAccessor() {}
  virtual bool IsEmpty(const Field* data) const {
    return GetRepeatedField(data)->empty();
  }
  virtual int Size(const Field* data) const {
    return GetRepeatedField(data)->size();
  }
  virtual const Value* Get(const Field* data, int index,
                           Value* scratch_space) const {
    return ConvertFromEntry(GetRepeatedField(data)->Get(index), scratch_space);
  }
  virtual void Clear(Field* data) const {
    MutableRepeatedField(data)->Clear();
  }
  virtual void Set(Field* data, int index, const Value* value) const {
    ConvertToEntry(value, MutableRepeatedField(data)->Mutable(index));
  }
  virtual void Add(Field* data, const Value* value) const {
    Message* allocated = New(value);
    ConvertToEntry(value, allocated);
    MutableRepeatedField(data)->AddAllocated(allocated);
  }
  virtual void RemoveLast(Field* data) const {
    MutableRepeatedField(data)->RemoveLast();
  }
  virtual void SwapElements(Field* data, int index1, int index2) const {
    MutableRepeatedField(data)->SwapElements(index1, index2);
  }
  virtual void Swap(
      Field* data,
      const internal::RepeatedFieldAccessor* other_mutator,
      Field* other_data) const {
    GOOGLE_CHECK(this == other_mutator);
    MutableRepeatedField(data)->Swap(MutableRepeatedField(other_data));
  }

 protected:
  typedef RepeatedPtrField<Message> RepeatedFieldType;
  static const RepeatedFieldType* GetRepeatedField(const Field* data) {
    return reinterpret_cast<const RepeatedFieldType*>(
        (&reinterpret_cast<const MapFieldBase*>(data)->GetRepeatedField()));
  }
  static RepeatedFieldType* MutableRepeatedField(Field* data) {
    return reinterpret_cast<RepeatedFieldType*>(
        reinterpret_cast<MapFieldBase*>(data)->MutableRepeatedField());
  }
  virtual Message* New(const Value* value) const {
    return static_cast<const Message*>(value)->New();
  }
  // Convert an object received by this accessor to an MapEntry message to be
  // stored in the underlying MapFieldBase.
  virtual void ConvertToEntry(const Value* value, Message* result) const {
    result->CopyFrom(*static_cast<const Message*>(value));
  }
  // Convert a MapEntry message stored in the underlying MapFieldBase to an
  // object that will be returned by this accessor.
  virtual const Value* ConvertFromEntry(const Message& value,
                                        Value* scratch_space) const {
    return static_cast<const Value*>(&value);
  }
};

// Default implementations of RepeatedFieldAccessor for primitive types.
template<typename T>
class RepeatedFieldPrimitiveAccessor : public RepeatedFieldWrapper<T> {
  typedef void Field;
  typedef void Value;
  using RepeatedFieldWrapper<T>::MutableRepeatedField;

 public:
  RepeatedFieldPrimitiveAccessor() {}
  virtual ~RepeatedFieldPrimitiveAccessor() {}
  virtual void Swap(
      Field* data,
      const internal::RepeatedFieldAccessor* other_mutator,
      Field* other_data) const {
    // Currently RepeatedFieldPrimitiveAccessor is the only implementation of
    // RepeatedFieldAccessor for primitive types. As we are using singletons
    // for these accessors, here "other_mutator" must be "this".
    GOOGLE_CHECK(this == other_mutator);
    MutableRepeatedField(data)->Swap(MutableRepeatedField(other_data));
  }

 protected:
  virtual T ConvertToT(const Value* value) const {
    return *static_cast<const T*>(value);
  }
  virtual const Value* ConvertFromT(const T& value,
                                    Value* scratch_space) const {
    return static_cast<const Value*>(&value);
  }
};

// Default implementation of RepeatedFieldAccessor for string fields with
// ctype=STRING.
class RepeatedPtrFieldStringAccessor : public RepeatedPtrFieldWrapper<string> {
  typedef void Field;
  typedef void Value;
  using RepeatedFieldAccessor::Add;

 public:
  RepeatedPtrFieldStringAccessor() {}
  virtual ~RepeatedPtrFieldStringAccessor() {}
  virtual void Swap(
      Field* data,
      const internal::RepeatedFieldAccessor* other_mutator,
      Field* other_data) const {
    if (this == other_mutator) {
      MutableRepeatedField(data)->Swap(MutableRepeatedField(other_data));
    } else {
      RepeatedPtrField<string> tmp;
      tmp.Swap(MutableRepeatedField(data));
      int other_size = other_mutator->Size(other_data);
      for (int i = 0; i < other_size; ++i) {
        Add<string>(data, other_mutator->Get<string>(other_data, i));
      }
      int size = Size(data);
      other_mutator->Clear(other_data);
      for (int i = 0; i < size; ++i) {
        other_mutator->Add<string>(other_data, tmp.Get(i));
      }
    }
  }

 protected:
  virtual string* New(const Value*) const {
    return new string();
  }
  virtual void ConvertToT(const Value* value, string* result) const {
    *result = *static_cast<const string*>(value);
  }
  virtual const Value* ConvertFromT(const string& value,
                                    Value* scratch_space) const {
    return static_cast<const Value*>(&value);
  }
};

class RepeatedPtrFieldMessageAccessor
    : public RepeatedPtrFieldWrapper<Message> {
  typedef void Field;
  typedef void Value;

 public:
  RepeatedPtrFieldMessageAccessor() {}
  virtual ~RepeatedPtrFieldMessageAccessor() {}
  virtual void Swap(
      Field* data,
      const internal::RepeatedFieldAccessor* other_mutator,
      Field* other_data) const {
    GOOGLE_CHECK(this == other_mutator);
    MutableRepeatedField(data)->Swap(MutableRepeatedField(other_data));
  }

 protected:
  virtual Message* New(const Value* value) const {
    return static_cast<const Message*>(value)->New();
  }
  virtual void ConvertToT(const Value* value, Message* result) const {
    result->CopyFrom(*static_cast<const Message*>(value));
  }
  virtual const Value* ConvertFromT(const Message& value,
                                    Value* scratch_space) const {
    return static_cast<const Value*>(&value);
  }
};
}  // namespace internal
}  // namespace protobuf

}  // namespace google
#endif  // GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__


text:
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <google/protobuf/generated_message_table_driven_lite.h>

#include <google/protobuf/stubs/type_traits.h>

#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/wire_format_lite_inl.h>

namespace google {
namespace protobuf {
namespace internal {

namespace {

string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) {
  return Raw<InternalMetadataWithArenaLite>(msg, arena_offset)
      ->mutable_unknown_fields();
}

struct UnknownFieldHandlerLite {
  static bool Skip(MessageLite* msg, const ParseTable& table,
                   io::CodedInputStream* input,
                   int tag) {
    GOOGLE_DCHECK(!table.unknown_field_set);
    ::google::protobuf::io::StringOutputStream unknown_fields_string(
        MutableUnknownFields(msg, table.arena_offset));
    ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
        &unknown_fields_string, false);

    return ::google::protobuf::internal::WireFormatLite::SkipField(
        input, tag, &unknown_fields_stream);
  }

  static void Varint(MessageLite* msg, const ParseTable& table,
                     int tag, int value) {
    GOOGLE_DCHECK(!table.unknown_field_set);

    ::google::protobuf::io::StringOutputStream unknown_fields_string(
        MutableUnknownFields(msg, table.arena_offset));
    ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
        &unknown_fields_string, false);
    unknown_fields_stream.WriteVarint32(tag);
    unknown_fields_stream.WriteVarint32(value);
  }

  static bool ParseExtension(
      MessageLite* msg, const ParseTable& table,
      io::CodedInputStream* input, int tag) {
    ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
    if (extensions == NULL) {
      return false;
    }

    const MessageLite* prototype = table.default_instance();

    GOOGLE_DCHECK(!table.unknown_field_set);
    ::google::protobuf::io::StringOutputStream unknown_fields_string(
        MutableUnknownFields(msg, table.arena_offset));
    ::google::protobuf::io::CodedOutputStream unknown_fields_stream(
        &unknown_fields_string, false);
    return extensions->ParseField(
        tag, input, prototype, &unknown_fields_stream);
  }
};

}  // namespace

bool MergePartialFromCodedStreamLite(
    MessageLite* msg, const ParseTable& table, io::CodedInputStream* input) {
  return MergePartialFromCodedStreamImpl<UnknownFieldHandlerLite,
                                         InternalMetadataWithArenaLite>(
      msg, table, input);
}

}  // namespace internal
}  // namespace protobuf
}  // namespace google