// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

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

edition = "2023";

package proto2_unittest;

import "google/protobuf/unittest_import_lite.proto";

option features.enum_type = CLOSED;
option features.repeated_field_encoding = EXPANDED;
option features.utf8_validation = NONE;
option cc_enable_arenas = true;
option optimize_for = LITE_RUNTIME;
option java_package = "com.google.protobuf";

// Same as TestAllTypes but with the lite runtime.
message TestAllTypesLite {
  message NestedMessage {
    int32 bb = 1;
    int64 cc = 2;
    repeated int32 dd = 3 [features.repeated_field_encoding = PACKED];
  }

  message NestedMessage2 {
    int32 dd = 1;
  }

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

  // 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;

  message OptionalGroup {
    int32 a = 17;
  }

  OptionalGroup optionalgroup = 16 [features.message_encoding = DELIMITED];

  NestedMessage optional_nested_message = 18;
  ForeignMessageLite optional_foreign_message = 19;
  proto2_unittest_import.ImportMessageLite optional_import_message = 20;
  NestedEnum optional_nested_enum = 21;
  ForeignEnumLite optional_foreign_enum = 22;
  proto2_unittest_import.ImportEnumLite optional_import_enum = 23;
  string optional_string_piece = 24 [ctype = STRING_PIECE];

  string optional_cord = 25 [ctype = CORD];
  bytes optional_bytes_cord = 86 [ctype = CORD];

  // Defined in unittest_import_public.proto
  proto2_unittest_import.PublicImportMessageLite
      optional_public_import_message = 26;
  NestedMessage optional_lazy_message = 27 [lazy = true];

  NestedMessage optional_unverified_lazy_message = 28 [unverified_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;

  message RepeatedGroup {
    int32 a = 47;
  }

  repeated RepeatedGroup repeatedgroup = 46
      [features.message_encoding = DELIMITED];

  repeated NestedMessage repeated_nested_message = 48;
  repeated ForeignMessageLite repeated_foreign_message = 49;
  repeated proto2_unittest_import.ImportMessageLite repeated_import_message =
      50;
  repeated NestedEnum repeated_nested_enum = 51;
  repeated ForeignEnumLite repeated_foreign_enum = 52;
  repeated proto2_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;

  // Singular with defaults
  int32 default_int32 = 61 [default = 41];

  int64 default_int64 = 62 [default = 42];

  uint32 default_uint32 = 63 [default = 43];

  uint64 default_uint64 = 64 [default = 44];

  sint32 default_sint32 = 65 [default = -45];

  sint64 default_sint64 = 66 [default = 46];

  fixed32 default_fixed32 = 67 [default = 47];

  fixed64 default_fixed64 = 68 [default = 48];

  sfixed32 default_sfixed32 = 69 [default = 49];

  sfixed64 default_sfixed64 = 70 [default = -50];

  float default_float = 71 [default = 51.5];

  double default_double = 72 [default = 5.2e4];

  bool default_bool = 73 [default = true];

  string default_string = 74 [default = "hello"];

  bytes default_bytes = 75 [default = "world"];

  NestedEnum default_nested_enum = 81 [default = BAR];

  ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR];

  proto2_unittest_import.ImportEnumLite default_import_enum = 83
      [default = IMPORT_LITE_BAR];

  string default_string_piece = 84 [ctype = STRING_PIECE, default = "abc"];

  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];

    NestedMessage2 oneof_nested_message2 = 117;
  }

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

message ForeignMessageLite {
  int32 c = 1;
}

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

message TestPackedTypesLite {
  repeated int32 packed_int32 = 90 [features.repeated_field_encoding = PACKED];

  repeated int64 packed_int64 = 91 [features.repeated_field_encoding = PACKED];

  repeated uint32 packed_uint32 = 92
      [features.repeated_field_encoding = PACKED];

  repeated uint64 packed_uint64 = 93
      [features.repeated_field_encoding = PACKED];

  repeated sint32 packed_sint32 = 94
      [features.repeated_field_encoding = PACKED];

  repeated sint64 packed_sint64 = 95
      [features.repeated_field_encoding = PACKED];

  repeated fixed32 packed_fixed32 = 96
      [features.repeated_field_encoding = PACKED];

  repeated fixed64 packed_fixed64 = 97
      [features.repeated_field_encoding = PACKED];

  repeated sfixed32 packed_sfixed32 = 98
      [features.repeated_field_encoding = PACKED];

  repeated sfixed64 packed_sfixed64 = 99
      [features.repeated_field_encoding = PACKED];

  repeated float packed_float = 100 [features.repeated_field_encoding = PACKED];

  repeated double packed_double = 101
      [features.repeated_field_encoding = PACKED];

  repeated bool packed_bool = 102 [features.repeated_field_encoding = PACKED];

  repeated ForeignEnumLite packed_enum = 103
      [features.repeated_field_encoding = PACKED];
}

message TestAllExtensionsLite {
  extensions 1 to max;
}

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

  TestAllTypesLite.NestedMessage optional_nested_message_extension_lite = 18;
  ForeignMessageLite optional_foreign_message_extension_lite = 19;
  proto2_unittest_import.ImportMessageLite
      optional_import_message_extension_lite = 20;
  TestAllTypesLite.NestedEnum optional_nested_enum_extension_lite = 21;
  ForeignEnumLite optional_foreign_enum_extension_lite = 22;
  proto2_unittest_import.ImportEnumLite optional_import_enum_extension_lite =
      23;
  string optional_string_piece_extension_lite = 24 [ctype = STRING_PIECE];

  // TODO: ctype=CORD is not supported for extension. Add
  // ctype=CORD option back after it is supported.
  string optional_cord_extension_lite = 25;
  bytes optional_bytes_cord_extension_lite = 86;
  proto2_unittest_import.PublicImportMessageLite
      optional_public_import_message_extension_lite = 26;
  TestAllTypesLite.NestedMessage optional_lazy_message_extension_lite = 27
      [lazy = true];

  TestAllTypesLite.NestedMessage
      optional_unverified_lazy_message_extension_lite = 28
      [unverified_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 RepeatedGroup_extension_lite repeatedgroup_extension_lite = 46
      [features.message_encoding = DELIMITED];

  repeated TestAllTypesLite.NestedMessage
      repeated_nested_message_extension_lite = 48;
  repeated ForeignMessageLite repeated_foreign_message_extension_lite = 49;
  repeated proto2_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 proto2_unittest_import.ImportEnumLite
      repeated_import_enum_extension_lite = 53;
  repeated string repeated_string_piece_extension_lite = 54
      [ctype = STRING_PIECE];

  // TODO: ctype=CORD is not supported for extension. Add
  // ctype=CORD option back after it is supported.
  repeated string repeated_cord_extension_lite = 55;
  repeated TestAllTypesLite.NestedMessage repeated_lazy_message_extension_lite =
      57 [lazy = true];

  // Singular with defaults
  int32 default_int32_extension_lite = 61 [default = 41];

  int64 default_int64_extension_lite = 62 [default = 42];

  uint32 default_uint32_extension_lite = 63 [default = 43];

  uint64 default_uint64_extension_lite = 64 [default = 44];

  sint32 default_sint32_extension_lite = 65 [default = -45];

  sint64 default_sint64_extension_lite = 66 [default = 46];

  fixed32 default_fixed32_extension_lite = 67 [default = 47];

  fixed64 default_fixed64_extension_lite = 68 [default = 48];

  sfixed32 default_sfixed32_extension_lite = 69 [default = 49];

  sfixed64 default_sfixed64_extension_lite = 70 [default = -50];

  float default_float_extension_lite = 71 [default = 51.5];

  double default_double_extension_lite = 72 [default = 5.2e4];

  bool default_bool_extension_lite = 73 [default = true];

  string default_string_extension_lite = 74 [default = "hello"];

  bytes default_bytes_extension_lite = 75 [default = "world"];

  TestAllTypesLite.NestedEnum default_nested_enum_extension_lite = 81
      [default = BAR];

  ForeignEnumLite default_foreign_enum_extension_lite = 82
      [default = FOREIGN_LITE_BAR];

  proto2_unittest_import.ImportEnumLite default_import_enum_extension_lite = 83
      [default = IMPORT_LITE_BAR];

  string default_string_piece_extension_lite = 84
      [ctype = STRING_PIECE, default = "abc"];

  // TODO: ctype=CORD is not supported for extension. Add
  // ctype=CORD option back after it is supported.
  string default_cord_extension_lite = 85 [default = "123"];

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

message OptionalGroup_extension_lite {
  int32 a = 17;
}

message RepeatedGroup_extension_lite {
  int32 a = 47;
}

message TestPackedExtensionsLite {
  extensions 1 to max;
}

extend TestPackedExtensionsLite {
  repeated int32 packed_int32_extension_lite = 90
      [features.repeated_field_encoding = PACKED];

  repeated int64 packed_int64_extension_lite = 91
      [features.repeated_field_encoding = PACKED];

  repeated uint32 packed_uint32_extension_lite = 92
      [features.repeated_field_encoding = PACKED];

  repeated uint64 packed_uint64_extension_lite = 93
      [features.repeated_field_encoding = PACKED];

  repeated sint32 packed_sint32_extension_lite = 94
      [features.repeated_field_encoding = PACKED];

  repeated sint64 packed_sint64_extension_lite = 95
      [features.repeated_field_encoding = PACKED];

  repeated fixed32 packed_fixed32_extension_lite = 96
      [features.repeated_field_encoding = PACKED];

  repeated fixed64 packed_fixed64_extension_lite = 97
      [features.repeated_field_encoding = PACKED];

  repeated sfixed32 packed_sfixed32_extension_lite = 98
      [features.repeated_field_encoding = PACKED];

  repeated sfixed64 packed_sfixed64_extension_lite = 99
      [features.repeated_field_encoding = PACKED];

  repeated float packed_float_extension_lite = 100
      [features.repeated_field_encoding = PACKED];

  repeated double packed_double_extension_lite = 101
      [features.repeated_field_encoding = PACKED];

  repeated bool packed_bool_extension_lite = 102
      [features.repeated_field_encoding = PACKED];

  repeated ForeignEnumLite packed_enum_extension_lite = 103
      [features.repeated_field_encoding = PACKED];
}

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

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

  int32 deprecated_field2 = 2
      [features.field_presence = LEGACY_REQUIRED, deprecated = true];

  string deprecated_field3 = 3 [deprecated = true];

  TestDeprecatedLite deprecated_field4 = 4 [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;

    message Group1 {
      TestAllTypesLite field1 = 11;
    }

    repeated Group1 group1 = 10 [features.message_encoding = DELIMITED];

    message Group2 {
      TestAllTypesLite field1 = 21;
    }

    repeated Group2 group2 = 20 [features.message_encoding = DELIMITED];

    repeated TestAllTypesLite ext1 = 1000;
    repeated TestAllTypesLite ext2 = 1001;
  }

  TestAllTypesLite required_all_types = 1
      [features.field_presence = LEGACY_REQUIRED];

  TestAllTypesLite optional_all_types = 2;
  repeated TestAllTypesLite repeated_all_types = 3;

  message OptionalGroup {
    TestAllTypesLite optional_group_all_types = 11;
  }

  OptionalGroup optionalgroup = 10 [features.message_encoding = DELIMITED];

  message RepeatedGroup {
    TestAllTypesLite repeated_group_all_types = 21;
  }

  repeated RepeatedGroup repeatedgroup = 20
      [features.message_encoding = DELIMITED];

  extensions 1000 to max;

  extend TestParsingMergeLite {
    TestAllTypesLite optional_ext = 1000;
    repeated TestAllTypesLite repeated_ext = 1001;
  }
}

// Test that the correct exception is thrown by parseFrom in a corner case
// involving merging, extensions, and required fields.
message TestMergeExceptionLite {
  TestAllExtensionsLite all_extensions = 1;
}

// 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 {
  int32 int_field = 1 [features.field_presence = LEGACY_REQUIRED];

  V1EnumLite enum_field = 2 [default = V1_FIRST];
}

message V2MessageLite {
  int32 int_field = 1 [features.field_presence = LEGACY_REQUIRED];

  V2EnumLite enum_field = 2 [default = V2_FIRST];
}

message TestHugeFieldNumbersLite {
  int32 optional_int32 = 536870000;
  int32 fixed_32 = 536870001;
  repeated int32 repeated_int32 = 536870002;
  repeated int32 packed_int32 = 536870003
      [features.repeated_field_encoding = PACKED];

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

  message OptionalGroup {
    int32 group_a = 536870009;
  }

  OptionalGroup optionalgroup = 536870008
      [features.message_encoding = DELIMITED];

  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 [declaration = {
    number: 536860000
    full_name: ".proto2_unittest.test_all_types_lite"
    type: ".proto2_unittest.TestAllTypesLite"
  }];
}

extend TestHugeFieldNumbersLite {
  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;
  }
}

message TestMessageSetLite {
  option message_set_wire_format = true;

  extensions 100 to max;
}

// The following four messages are set up to test for wire compatibility between
// packed and non-packed repeated fields. We use the field number 2048, because
// that is large enough to require a 3-byte varint for the tag.
message PackedInt32 {
  repeated int32 repeated_int32 = 2048
      [features.repeated_field_encoding = PACKED];
}

message NonPackedInt32 {
  repeated int32 repeated_int32 = 2048;
}

message PackedFixed32 {
  repeated fixed32 repeated_fixed32 = 2048
      [features.repeated_field_encoding = PACKED];
}

message NonPackedFixed32 {
  repeated fixed32 repeated_fixed32 = 2048;
}

// Test an enum that has multiple values with the same number.
message DupEnum {
  enum TestEnumWithDupValueLite {
    option allow_alias = true;

    FOO1 = 1;
    BAR1 = 2;
    BAZ = 3;
    FOO2 = 1;
    BAR2 = 2;
  }
}

message RecursiveMessage {
  RecursiveMessage recurse = 1;
  bytes payload = 2;
}

message RecursiveGroup {
  RecursiveGroup recurse = 1 [features.message_encoding = DELIMITED];
}
