diff --git a/generated-code-tests/src/main/kotlin/testgen/enums/enums.proto.kt b/generated-code-tests/src/main/kotlin/testgen/enums/enums.proto.kt new file mode 100644 index 0000000..1aa7653 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/enums/enums.proto.kt @@ -0,0 +1,57 @@ +package testgen.enums + +import kotlin.Int +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class MessageWithEnum( + @ProtoNumber(number = 1) + public val id: Int = 0, + @ProtoNumber(number = 2) + public val testEnum: TestEnum = testgen.enums.TestEnum.FOO, + @ProtoNumber(number = 3) + public val aliasedEnum: AliasedEnum = testgen.enums.AliasedEnum.ALIAS_FOO, + @ProtoNumber(number = 4) + public val nestedEnum: NestedEnum = testgen.enums.MessageWithEnum.NestedEnum.NESTED_FOO, +) { + @Serializable + public enum class NestedEnum { + @ProtoNumber(number = 0) + NESTED_FOO, + @ProtoNumber(number = 1) + NESTED_BAR, + @ProtoNumber(number = 2) + NESTED_BAZ, + } +} + +@Serializable +public enum class TestEnum { + @ProtoNumber(number = 0) + FOO, + @ProtoNumber(number = 1) + BAR, + @ProtoNumber(number = 2) + BAZ, + @ProtoNumber(number = 100) + TOP, + @ProtoNumber(number = -1) + NEG, +} + +@Serializable +public enum class AliasedEnum { + @ProtoNumber(number = 0) + ALIAS_FOO, + @ProtoNumber(number = 1) + ALIAS_BAR, + @ProtoNumber(number = 2) + ALIAS_BAZ, + @ProtoNumber(number = 2) + QUX, + @ProtoNumber(number = 2) + qux, + @ProtoNumber(number = 2) + bAz, +} diff --git a/generated-code-tests/src/main/kotlin/testgen/google/protobuf/any.proto.kt b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/any.proto.kt new file mode 100644 index 0000000..66b9822 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/any.proto.kt @@ -0,0 +1,14 @@ +package testgen.google.protobuf + +import kotlin.ByteArray +import kotlin.String +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class Any( + @ProtoNumber(number = 1) + public val typeUrl: String = "", + @ProtoNumber(number = 2) + public val `value`: ByteArray = byteArrayOf(), +) diff --git a/generated-code-tests/src/main/kotlin/testgen/google/protobuf/duration.proto.kt b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/duration.proto.kt new file mode 100644 index 0000000..f930bb8 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/duration.proto.kt @@ -0,0 +1,2 @@ +package testgen.google.protobuf + diff --git a/generated-code-tests/src/main/kotlin/testgen/google/protobuf/field_mask.proto.kt b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/field_mask.proto.kt new file mode 100644 index 0000000..afab865 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/field_mask.proto.kt @@ -0,0 +1,12 @@ +package testgen.google.protobuf + +import kotlin.String +import kotlin.collections.List +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class FieldMask( + @ProtoNumber(number = 1) + public val paths: List = emptyList(), +) diff --git a/generated-code-tests/src/main/kotlin/testgen/google/protobuf/struct.proto.kt b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/struct.proto.kt new file mode 100644 index 0000000..adb8186 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/struct.proto.kt @@ -0,0 +1,56 @@ +package testgen.google.protobuf + +import kotlin.Boolean +import kotlin.Double +import kotlin.String +import kotlin.collections.List +import kotlin.collections.Map +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class Struct( + @ProtoNumber(number = 1) + public val fields: Map = emptyMap(), +) + +@Serializable +public data class Value( + @ProtoNumber(number = 1) + public val nullValue: NullValue? = null, + @ProtoNumber(number = 2) + public val numberValue: Double? = null, + @ProtoNumber(number = 3) + public val stringValue: String? = null, + @ProtoNumber(number = 4) + public val boolValue: Boolean? = null, + @ProtoNumber(number = 5) + public val structValue: Struct? = null, + @ProtoNumber(number = 6) + public val listValue: ListValue? = null, +) { + init { + require( + listOfNotNull( + nullValue, + numberValue, + stringValue, + boolValue, + structValue, + listValue, + ).size <= 1 + ) { "Should only contain one of kind." } + } +} + +@Serializable +public data class ListValue( + @ProtoNumber(number = 1) + public val values: List = emptyList(), +) + +@Serializable +public enum class NullValue { + @ProtoNumber(number = 0) + NULL_VALUE, +} diff --git a/generated-code-tests/src/main/kotlin/testgen/google/protobuf/timestamp.proto.kt b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/timestamp.proto.kt new file mode 100644 index 0000000..f930bb8 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/timestamp.proto.kt @@ -0,0 +1,2 @@ +package testgen.google.protobuf + diff --git a/generated-code-tests/src/main/kotlin/testgen/google/protobuf/wrappers.proto.kt b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/wrappers.proto.kt new file mode 100644 index 0000000..f930bb8 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/google/protobuf/wrappers.proto.kt @@ -0,0 +1,2 @@ +package testgen.google.protobuf + diff --git a/generated-code-tests/src/main/kotlin/testgen/maps/maps.proto.kt b/generated-code-tests/src/main/kotlin/testgen/maps/maps.proto.kt new file mode 100644 index 0000000..29609bf --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/maps/maps.proto.kt @@ -0,0 +1,92 @@ +package testgen.maps + +import kotlin.Boolean +import kotlin.ByteArray +import kotlin.Double +import kotlin.Float +import kotlin.Int +import kotlin.Long +import kotlin.String +import kotlin.UInt +import kotlin.ULong +import kotlin.collections.Map +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class MapsMessage( + @ProtoNumber(number = 1) + public val mapInt32Int32: Map = emptyMap(), + @ProtoNumber(number = 2) + public val mapInt64Int64: Map = emptyMap(), + @ProtoNumber(number = 3) + public val mapUint32Uint32: Map = emptyMap(), + @ProtoNumber(number = 4) + public val mapUint64Uint64: Map = emptyMap(), + @ProtoNumber(number = 5) + public val mapSint32Sint32: Map = emptyMap(), + @ProtoNumber(number = 6) + public val mapSint64Sint64: Map = emptyMap(), + @ProtoNumber(number = 7) + public val mapFixed32Fixed32: Map = emptyMap(), + @ProtoNumber(number = 8) + public val mapFixed64Fixed64: Map = emptyMap(), + @ProtoNumber(number = 9) + public val mapSfixed32Sfixed32: Map = emptyMap(), + @ProtoNumber(number = 10) + public val mapSfixed64Sfixed64: Map = emptyMap(), + @ProtoNumber(number = 11) + public val mapInt32Float: Map = emptyMap(), + @ProtoNumber(number = 12) + public val mapInt32Double: Map = emptyMap(), + @ProtoNumber(number = 13) + public val mapBoolBool: Map = emptyMap(), + @ProtoNumber(number = 14) + public val mapStringString: Map = emptyMap(), + @ProtoNumber(number = 15) + public val mapStringBytes: Map = emptyMap(), + @ProtoNumber(number = 16) + public val mapStringNestedMessage: Map = emptyMap(), + @ProtoNumber(number = 17) + public val mapStringForeignMessage: Map = emptyMap(), + @ProtoNumber(number = 18) + public val mapStringNestedEnum: Map = emptyMap(), + @ProtoNumber(number = 19) + public val mapStringForeignEnum: Map = emptyMap(), +) { + @Serializable + public data class NestedMessage( + @ProtoNumber(number = 1) + public val a: Int = 0, + @ProtoNumber(number = 2) + public val corecursive: MapsMessage? = null, + ) + + @Serializable + public enum class NestedEnum { + @ProtoNumber(number = 0) + FOO, + @ProtoNumber(number = 1) + BAR, + @ProtoNumber(number = 2) + BAZ, + @ProtoNumber(number = -1) + NEG, + } +} + +@Serializable +public data class ForeignMessage( + @ProtoNumber(number = 1) + public val c: Int = 0, +) + +@Serializable +public enum class ForeignEnum { + @ProtoNumber(number = 0) + FOREIGN_FOO, + @ProtoNumber(number = 1) + FOREIGN_BAR, + @ProtoNumber(number = 2) + FOREIGN_BAZ, +} diff --git a/generated-code-tests/src/main/kotlin/testgen/messages/message_no_fields.proto.kt b/generated-code-tests/src/main/kotlin/testgen/messages/message_no_fields.proto.kt new file mode 100644 index 0000000..87ac438 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/messages/message_no_fields.proto.kt @@ -0,0 +1,51 @@ +package testgen.messages + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.String +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public class MessageNoFields() { + override fun toString(): String = "MessageNoFields" + + override fun hashCode(): Int = 70_682_849 + + override fun equals(other: Any?): Boolean = other is MessageNoFields + + @Serializable + public data class SubMessageNoFields( + @ProtoNumber(number = 1) + public val subHello: SubMessageNoFields? = null, + ) { + @Serializable + public data class SubMessageNoFieldsExtend( + @ProtoNumber(number = 1) + public val type: Type = testgen.messages.MessageNoFields.Type.UNKNOWN, + ) + } + + @Serializable + public data class SubMessageOneofFields( + @ProtoNumber(number = 1) + public val someValue: Int? = null, + ) { + init { + require( + listOfNotNull( + someValue, + ).size <= 1 + ) { "Should only contain one of some_oneof." } + } + } + + @Serializable + public enum class Type { + @ProtoNumber(number = 0) + UNKNOWN, + @ProtoNumber(number = 1) + KNOWN, + } +} diff --git a/generated-code-tests/src/main/kotlin/testgen/messages/messages.proto.kt b/generated-code-tests/src/main/kotlin/testgen/messages/messages.proto.kt new file mode 100644 index 0000000..136b366 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/messages/messages.proto.kt @@ -0,0 +1,30 @@ +package testgen.messages + +import kotlin.Int +import kotlin.String +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class MessagesMessage( + @ProtoNumber(number = 1) + public val id: String = "", + @ProtoNumber(number = 2) + public val optionalNestedMessage: NestedMessage? = null, + @ProtoNumber(number = 3) + public val optionalForeignMessage: ForeignMessage? = null, +) { + @Serializable + public data class NestedMessage( + @ProtoNumber(number = 1) + public val a: Int = 0, + @ProtoNumber(number = 2) + public val corecursive: MessagesMessage? = null, + ) +} + +@Serializable +public data class ForeignMessage( + @ProtoNumber(number = 1) + public val c: Int = 0, +) diff --git a/generated-code-tests/src/main/kotlin/testgen/oneof/oneof.proto.kt b/generated-code-tests/src/main/kotlin/testgen/oneof/oneof.proto.kt new file mode 100644 index 0000000..edb23bb --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/oneof/oneof.proto.kt @@ -0,0 +1,75 @@ +package testgen.oneof + +import kotlin.Boolean +import kotlin.Double +import kotlin.Float +import kotlin.Int +import kotlin.String +import kotlin.UInt +import kotlin.ULong +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class OneofMessage( + @ProtoNumber(number = 1) + public val oneofUint32: UInt? = null, + @ProtoNumber(number = 2) + public val oneofNestedMessage: NestedMessage? = null, + @ProtoNumber(number = 3) + public val oneofString: String? = null, + @ProtoNumber(number = 5) + public val oneofBool: Boolean? = null, + @ProtoNumber(number = 6) + public val oneofUint64: ULong? = null, + @ProtoNumber(number = 7) + public val oneofFloat: Float? = null, + @ProtoNumber(number = 8) + public val oneofDouble: Double? = null, + @ProtoNumber(number = 9) + public val oneofEnum: NestedEnum? = null, + @ProtoNumber(number = 10) + public val left: String? = null, + @ProtoNumber(number = 11) + public val right: String? = null, +) { + init { + require( + listOfNotNull( + oneofUint32, + oneofNestedMessage, + oneofString, + oneofBool, + oneofUint64, + oneofFloat, + oneofDouble, + oneofEnum, + ).size <= 1 + ) { "Should only contain one of oneof_field." } + require( + listOfNotNull( + left, + right, + ).size <= 1 + ) { "Should only contain one of second_oneof_field." } + } + @Serializable + public data class NestedMessage( + @ProtoNumber(number = 1) + public val a: Int = 0, + @ProtoNumber(number = 2) + public val corecursive: OneofMessage? = null, + ) + + @Serializable + public enum class NestedEnum { + @ProtoNumber(number = 0) + FOO, + @ProtoNumber(number = 1) + BAR, + @ProtoNumber(number = 2) + BAZ, + @ProtoNumber(number = -1) + NEG, + } +} diff --git a/generated-code-tests/src/main/kotlin/testgen/primitives/primitives.proto.kt b/generated-code-tests/src/main/kotlin/testgen/primitives/primitives.proto.kt new file mode 100644 index 0000000..c6e4a88 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/primitives/primitives.proto.kt @@ -0,0 +1,56 @@ +package testgen.primitives + +import kotlin.Boolean +import kotlin.ByteArray +import kotlin.Double +import kotlin.Float +import kotlin.Int +import kotlin.Long +import kotlin.String +import kotlin.UInt +import kotlin.ULong +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoIntegerType.FIXED +import kotlinx.serialization.protobuf.ProtoIntegerType.SIGNED +import kotlinx.serialization.protobuf.ProtoNumber +import kotlinx.serialization.protobuf.ProtoType + +@Serializable +public data class PrimitivesMessage( + @ProtoNumber(number = 1) + public val optionalInt32: Int = 0, + @ProtoNumber(number = 2) + public val optionalInt64: Long = 0L, + @ProtoNumber(number = 3) + public val optionalUint32: UInt = 0U, + @ProtoNumber(number = 4) + public val optionalUint64: ULong = 0UL, + @ProtoNumber(number = 5) + @ProtoType(type = SIGNED) + public val optionalSint32: Int = 0, + @ProtoNumber(number = 6) + @ProtoType(type = SIGNED) + public val optionalSint64: Long = 0L, + @ProtoNumber(number = 7) + @ProtoType(type = FIXED) + public val optionalFixed32: Int = 0, + @ProtoNumber(number = 8) + @ProtoType(type = FIXED) + public val optionalFixed64: Long = 0L, + @ProtoNumber(number = 9) + @ProtoType(type = FIXED) + public val optionalSfixed32: Int = 0, + @ProtoNumber(number = 10) + @ProtoType(type = FIXED) + public val optionalSfixed64: Long = 0L, + @ProtoNumber(number = 11) + public val optionalFloat: Float = 0.0f, + @ProtoNumber(number = 12) + public val optionalDouble: Double = 0.0, + @ProtoNumber(number = 13) + public val optionalBool: Boolean = false, + @ProtoNumber(number = 14) + public val optionalString: String = "", + @ProtoNumber(number = 15) + public val optionalBytes: ByteArray = byteArrayOf(), +) diff --git a/generated-code-tests/src/main/kotlin/testgen/protobuf_test_messages/proto3/test_messages_proto3.proto.kt b/generated-code-tests/src/main/kotlin/testgen/protobuf_test_messages/proto3/test_messages_proto3.proto.kt new file mode 100644 index 0000000..a1f5293 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/protobuf_test_messages/proto3/test_messages_proto3.proto.kt @@ -0,0 +1,442 @@ +package testgen.protobuf_test_messages.proto3 + +import dogacel.kotlinx.protobuf.gen.wkt.BoolValueP +import dogacel.kotlinx.protobuf.gen.wkt.BytesValueP +import dogacel.kotlinx.protobuf.gen.wkt.DoubleValueP +import dogacel.kotlinx.protobuf.gen.wkt.DurationP +import dogacel.kotlinx.protobuf.gen.wkt.FloatValueP +import dogacel.kotlinx.protobuf.gen.wkt.Int32ValueP +import dogacel.kotlinx.protobuf.gen.wkt.Int64ValueP +import dogacel.kotlinx.protobuf.gen.wkt.StringValueP +import dogacel.kotlinx.protobuf.gen.wkt.TimestampP +import dogacel.kotlinx.protobuf.gen.wkt.UInt32ValueP +import dogacel.kotlinx.protobuf.gen.wkt.UInt64ValueP +import kotlin.Boolean +import kotlin.ByteArray +import kotlin.Double +import kotlin.Float +import kotlin.Int +import kotlin.Long +import kotlin.String +import kotlin.UInt +import kotlin.ULong +import kotlin.collections.List +import kotlin.collections.Map +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoIntegerType.FIXED +import kotlinx.serialization.protobuf.ProtoIntegerType.SIGNED +import kotlinx.serialization.protobuf.ProtoNumber +import kotlinx.serialization.protobuf.ProtoPacked +import kotlinx.serialization.protobuf.ProtoType +import testgen.google.protobuf.Any +import testgen.google.protobuf.FieldMask +import testgen.google.protobuf.ListValue +import testgen.google.protobuf.Struct +import testgen.google.protobuf.Value + +@Serializable +public data class TestAllTypesProto3( + @ProtoNumber(number = 1) + public val optionalInt32: Int = 0, + @ProtoNumber(number = 2) + public val optionalInt64: Long = 0L, + @ProtoNumber(number = 3) + public val optionalUint32: UInt = 0U, + @ProtoNumber(number = 4) + public val optionalUint64: ULong = 0UL, + @ProtoNumber(number = 5) + @ProtoType(type = SIGNED) + public val optionalSint32: Int = 0, + @ProtoNumber(number = 6) + @ProtoType(type = SIGNED) + public val optionalSint64: Long = 0L, + @ProtoNumber(number = 7) + @ProtoType(type = FIXED) + public val optionalFixed32: Int = 0, + @ProtoNumber(number = 8) + @ProtoType(type = FIXED) + public val optionalFixed64: Long = 0L, + @ProtoNumber(number = 9) + @ProtoType(type = FIXED) + public val optionalSfixed32: Int = 0, + @ProtoNumber(number = 10) + @ProtoType(type = FIXED) + public val optionalSfixed64: Long = 0L, + @ProtoNumber(number = 11) + public val optionalFloat: Float = 0.0f, + @ProtoNumber(number = 12) + public val optionalDouble: Double = 0.0, + @ProtoNumber(number = 13) + public val optionalBool: Boolean = false, + @ProtoNumber(number = 14) + public val optionalString: String = "", + @ProtoNumber(number = 15) + public val optionalBytes: ByteArray = byteArrayOf(), + @ProtoNumber(number = 18) + public val optionalNestedMessage: NestedMessage? = null, + @ProtoNumber(number = 19) + public val optionalForeignMessage: ForeignMessage? = null, + @ProtoNumber(number = 21) + public val optionalNestedEnum: NestedEnum = + testgen.protobuf_test_messages.proto3.TestAllTypesProto3.NestedEnum.FOO, + @ProtoNumber(number = 22) + public val optionalForeignEnum: ForeignEnum = + testgen.protobuf_test_messages.proto3.ForeignEnum.FOREIGN_FOO, + @ProtoNumber(number = 23) + public val optionalAliasedEnum: AliasedEnum = + testgen.protobuf_test_messages.proto3.TestAllTypesProto3.AliasedEnum.ALIAS_FOO, + @ProtoNumber(number = 24) + public val optionalStringPiece: String = "", + @ProtoNumber(number = 25) + public val optionalCord: String = "", + @ProtoNumber(number = 27) + public val recursiveMessage: TestAllTypesProto3? = null, + @ProtoNumber(number = 31) + @ProtoPacked + public val repeatedInt32: List = emptyList(), + @ProtoNumber(number = 32) + @ProtoPacked + public val repeatedInt64: List = emptyList(), + @ProtoNumber(number = 33) + @ProtoPacked + public val repeatedUint32: List = emptyList(), + @ProtoNumber(number = 34) + @ProtoPacked + public val repeatedUint64: List = emptyList(), + @ProtoNumber(number = 35) + @ProtoPacked + public val repeatedSint32: List = emptyList(), + @ProtoNumber(number = 36) + @ProtoPacked + public val repeatedSint64: List = emptyList(), + @ProtoNumber(number = 37) + @ProtoPacked + public val repeatedFixed32: List = emptyList(), + @ProtoNumber(number = 38) + @ProtoPacked + public val repeatedFixed64: List = emptyList(), + @ProtoNumber(number = 39) + @ProtoPacked + public val repeatedSfixed32: List = emptyList(), + @ProtoNumber(number = 40) + @ProtoPacked + public val repeatedSfixed64: List = emptyList(), + @ProtoNumber(number = 41) + @ProtoPacked + public val repeatedFloat: List = emptyList(), + @ProtoNumber(number = 42) + @ProtoPacked + public val repeatedDouble: List = emptyList(), + @ProtoNumber(number = 43) + @ProtoPacked + public val repeatedBool: List = emptyList(), + @ProtoNumber(number = 44) + public val repeatedString: List = emptyList(), + @ProtoNumber(number = 45) + public val repeatedBytes: List = emptyList(), + @ProtoNumber(number = 48) + public val repeatedNestedMessage: List = emptyList(), + @ProtoNumber(number = 49) + public val repeatedForeignMessage: List = emptyList(), + @ProtoNumber(number = 51) + @ProtoPacked + public val repeatedNestedEnum: List = emptyList(), + @ProtoNumber(number = 52) + @ProtoPacked + public val repeatedForeignEnum: List = emptyList(), + @ProtoNumber(number = 54) + public val repeatedStringPiece: List = emptyList(), + @ProtoNumber(number = 55) + public val repeatedCord: List = emptyList(), + @ProtoNumber(number = 75) + @ProtoPacked + public val packedInt32: List = emptyList(), + @ProtoNumber(number = 76) + @ProtoPacked + public val packedInt64: List = emptyList(), + @ProtoNumber(number = 77) + @ProtoPacked + public val packedUint32: List = emptyList(), + @ProtoNumber(number = 78) + @ProtoPacked + public val packedUint64: List = emptyList(), + @ProtoNumber(number = 79) + @ProtoPacked + public val packedSint32: List = emptyList(), + @ProtoNumber(number = 80) + @ProtoPacked + public val packedSint64: List = emptyList(), + @ProtoNumber(number = 81) + @ProtoPacked + public val packedFixed32: List = emptyList(), + @ProtoNumber(number = 82) + @ProtoPacked + public val packedFixed64: List = emptyList(), + @ProtoNumber(number = 83) + @ProtoPacked + public val packedSfixed32: List = emptyList(), + @ProtoNumber(number = 84) + @ProtoPacked + public val packedSfixed64: List = emptyList(), + @ProtoNumber(number = 85) + @ProtoPacked + public val packedFloat: List = emptyList(), + @ProtoNumber(number = 86) + @ProtoPacked + public val packedDouble: List = emptyList(), + @ProtoNumber(number = 87) + @ProtoPacked + public val packedBool: List = emptyList(), + @ProtoNumber(number = 88) + @ProtoPacked + public val packedNestedEnum: List = emptyList(), + @ProtoNumber(number = 89) + public val unpackedInt32: List = emptyList(), + @ProtoNumber(number = 90) + public val unpackedInt64: List = emptyList(), + @ProtoNumber(number = 91) + public val unpackedUint32: List = emptyList(), + @ProtoNumber(number = 92) + public val unpackedUint64: List = emptyList(), + @ProtoNumber(number = 93) + public val unpackedSint32: List = emptyList(), + @ProtoNumber(number = 94) + public val unpackedSint64: List = emptyList(), + @ProtoNumber(number = 95) + public val unpackedFixed32: List = emptyList(), + @ProtoNumber(number = 96) + public val unpackedFixed64: List = emptyList(), + @ProtoNumber(number = 97) + public val unpackedSfixed32: List = emptyList(), + @ProtoNumber(number = 98) + public val unpackedSfixed64: List = emptyList(), + @ProtoNumber(number = 99) + public val unpackedFloat: List = emptyList(), + @ProtoNumber(number = 100) + public val unpackedDouble: List = emptyList(), + @ProtoNumber(number = 101) + public val unpackedBool: List = emptyList(), + @ProtoNumber(number = 102) + public val unpackedNestedEnum: List = emptyList(), + @ProtoNumber(number = 56) + public val mapInt32Int32: Map = emptyMap(), + @ProtoNumber(number = 57) + public val mapInt64Int64: Map = emptyMap(), + @ProtoNumber(number = 58) + public val mapUint32Uint32: Map = emptyMap(), + @ProtoNumber(number = 59) + public val mapUint64Uint64: Map = emptyMap(), + @ProtoNumber(number = 60) + public val mapSint32Sint32: Map = emptyMap(), + @ProtoNumber(number = 61) + public val mapSint64Sint64: Map = emptyMap(), + @ProtoNumber(number = 62) + public val mapFixed32Fixed32: Map = emptyMap(), + @ProtoNumber(number = 63) + public val mapFixed64Fixed64: Map = emptyMap(), + @ProtoNumber(number = 64) + public val mapSfixed32Sfixed32: Map = emptyMap(), + @ProtoNumber(number = 65) + public val mapSfixed64Sfixed64: Map = emptyMap(), + @ProtoNumber(number = 66) + public val mapInt32Float: Map = emptyMap(), + @ProtoNumber(number = 67) + public val mapInt32Double: Map = emptyMap(), + @ProtoNumber(number = 68) + public val mapBoolBool: Map = emptyMap(), + @ProtoNumber(number = 69) + public val mapStringString: Map = emptyMap(), + @ProtoNumber(number = 70) + public val mapStringBytes: Map = emptyMap(), + @ProtoNumber(number = 71) + public val mapStringNestedMessage: Map = emptyMap(), + @ProtoNumber(number = 72) + public val mapStringForeignMessage: Map = emptyMap(), + @ProtoNumber(number = 73) + public val mapStringNestedEnum: Map = emptyMap(), + @ProtoNumber(number = 74) + public val mapStringForeignEnum: Map = emptyMap(), + @ProtoNumber(number = 111) + public val oneofUint32: UInt? = null, + @ProtoNumber(number = 112) + public val oneofNestedMessage: NestedMessage? = null, + @ProtoNumber(number = 113) + public val oneofString: String? = null, + @ProtoNumber(number = 114) + public val oneofBytes: ByteArray? = null, + @ProtoNumber(number = 115) + public val oneofBool: Boolean? = null, + @ProtoNumber(number = 116) + public val oneofUint64: ULong? = null, + @ProtoNumber(number = 117) + public val oneofFloat: Float? = null, + @ProtoNumber(number = 118) + public val oneofDouble: Double? = null, + @ProtoNumber(number = 119) + public val oneofEnum: NestedEnum? = null, + @ProtoNumber(number = 201) + public val optionalBoolWrapper: BoolValueP? = null, + @ProtoNumber(number = 202) + public val optionalInt32Wrapper: Int32ValueP? = null, + @ProtoNumber(number = 203) + public val optionalInt64Wrapper: Int64ValueP? = null, + @ProtoNumber(number = 204) + public val optionalUint32Wrapper: UInt32ValueP? = null, + @ProtoNumber(number = 205) + public val optionalUint64Wrapper: UInt64ValueP? = null, + @ProtoNumber(number = 206) + public val optionalFloatWrapper: FloatValueP? = null, + @ProtoNumber(number = 207) + public val optionalDoubleWrapper: DoubleValueP? = null, + @ProtoNumber(number = 208) + public val optionalStringWrapper: StringValueP? = null, + @ProtoNumber(number = 209) + public val optionalBytesWrapper: BytesValueP? = null, + @ProtoNumber(number = 211) + public val repeatedBoolWrapper: List = emptyList(), + @ProtoNumber(number = 212) + public val repeatedInt32Wrapper: List = emptyList(), + @ProtoNumber(number = 213) + public val repeatedInt64Wrapper: List = emptyList(), + @ProtoNumber(number = 214) + public val repeatedUint32Wrapper: List = emptyList(), + @ProtoNumber(number = 215) + public val repeatedUint64Wrapper: List = emptyList(), + @ProtoNumber(number = 216) + public val repeatedFloatWrapper: List = emptyList(), + @ProtoNumber(number = 217) + public val repeatedDoubleWrapper: List = emptyList(), + @ProtoNumber(number = 218) + public val repeatedStringWrapper: List = emptyList(), + @ProtoNumber(number = 219) + public val repeatedBytesWrapper: List = emptyList(), + @ProtoNumber(number = 301) + public val optionalDuration: DurationP? = null, + @ProtoNumber(number = 302) + public val optionalTimestamp: TimestampP? = null, + @ProtoNumber(number = 303) + public val optionalFieldMask: FieldMask? = null, + @ProtoNumber(number = 304) + public val optionalStruct: Struct? = null, + @ProtoNumber(number = 305) + public val optionalAny: Any? = null, + @ProtoNumber(number = 306) + public val optionalValue: Value? = null, + @ProtoNumber(number = 311) + public val repeatedDuration: List = emptyList(), + @ProtoNumber(number = 312) + public val repeatedTimestamp: List = emptyList(), + @ProtoNumber(number = 313) + public val repeatedFieldmask: List = emptyList(), + @ProtoNumber(number = 324) + public val repeatedStruct: List = emptyList(), + @ProtoNumber(number = 315) + public val repeatedAny: List = emptyList(), + @ProtoNumber(number = 316) + public val repeatedValue: List = emptyList(), + @ProtoNumber(number = 317) + public val repeatedListValue: List = emptyList(), + @ProtoNumber(number = 401) + public val fieldname1: Int = 0, + @ProtoNumber(number = 402) + public val fieldName2: Int = 0, + @ProtoNumber(number = 403) + public val FieldName3: Int = 0, + @ProtoNumber(number = 404) + public val field_Name4_: Int = 0, + @ProtoNumber(number = 405) + public val field0name5: Int = 0, + @ProtoNumber(number = 406) + public val field_0Name6: Int = 0, + @ProtoNumber(number = 407) + public val fieldName7: Int = 0, + @ProtoNumber(number = 408) + public val FieldName8: Int = 0, + @ProtoNumber(number = 409) + public val fieldName9: Int = 0, + @ProtoNumber(number = 410) + public val FieldName10: Int = 0, + @ProtoNumber(number = 411) + public val FIELDNAME11: Int = 0, + @ProtoNumber(number = 412) + public val FIELDName12: Int = 0, + @ProtoNumber(number = 413) + public val _FieldName13: Int = 0, + @ProtoNumber(number = 414) + public val _FieldName14: Int = 0, + @ProtoNumber(number = 415) + public val field_Name15: Int = 0, + @ProtoNumber(number = 416) + public val field_Name16: Int = 0, + @ProtoNumber(number = 417) + public val fieldName17__: Int = 0, + @ProtoNumber(number = 418) + public val FieldName18__: Int = 0, +) { + init { + require( + listOfNotNull( + oneofUint32, + oneofNestedMessage, + oneofString, + oneofBytes, + oneofBool, + oneofUint64, + oneofFloat, + oneofDouble, + oneofEnum, + ).size <= 1 + ) { "Should only contain one of oneof_field." } + } + @Serializable + public data class NestedMessage( + @ProtoNumber(number = 1) + public val a: Int = 0, + @ProtoNumber(number = 2) + public val corecursive: TestAllTypesProto3? = null, + ) + + @Serializable + public enum class NestedEnum { + @ProtoNumber(number = 0) + FOO, + @ProtoNumber(number = 1) + BAR, + @ProtoNumber(number = 2) + BAZ, + @ProtoNumber(number = -1) + NEG, + } + + @Serializable + public enum class AliasedEnum { + @ProtoNumber(number = 0) + ALIAS_FOO, + @ProtoNumber(number = 1) + ALIAS_BAR, + @ProtoNumber(number = 2) + ALIAS_BAZ, + @ProtoNumber(number = 2) + QUX, + @ProtoNumber(number = 2) + qux, + @ProtoNumber(number = 2) + bAz, + } +} + +@Serializable +public data class ForeignMessage( + @ProtoNumber(number = 1) + public val c: Int = 0, +) + +@Serializable +public enum class ForeignEnum { + @ProtoNumber(number = 0) + FOREIGN_FOO, + @ProtoNumber(number = 1) + FOREIGN_BAR, + @ProtoNumber(number = 2) + FOREIGN_BAZ, +} diff --git a/generated-code-tests/src/main/kotlin/testgen/repeateds/repeateds.proto.kt b/generated-code-tests/src/main/kotlin/testgen/repeateds/repeateds.proto.kt new file mode 100644 index 0000000..f93cb47 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/repeateds/repeateds.proto.kt @@ -0,0 +1,108 @@ +package testgen.repeateds + +import kotlin.Boolean +import kotlin.ByteArray +import kotlin.Double +import kotlin.Float +import kotlin.Int +import kotlin.Long +import kotlin.String +import kotlin.UInt +import kotlin.ULong +import kotlin.collections.List +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber +import kotlinx.serialization.protobuf.ProtoPacked + +@Serializable +public data class RepeatedsMessage( + @ProtoNumber(number = 1) + @ProtoPacked + public val repeatedInt32: List = emptyList(), + @ProtoNumber(number = 2) + @ProtoPacked + public val repeatedInt64: List = emptyList(), + @ProtoNumber(number = 3) + @ProtoPacked + public val repeatedUint32: List = emptyList(), + @ProtoNumber(number = 4) + @ProtoPacked + public val repeatedUint64: List = emptyList(), + @ProtoNumber(number = 5) + @ProtoPacked + public val repeatedSint32: List = emptyList(), + @ProtoNumber(number = 6) + @ProtoPacked + public val repeatedSint64: List = emptyList(), + @ProtoNumber(number = 7) + @ProtoPacked + public val repeatedFixed32: List = emptyList(), + @ProtoNumber(number = 8) + @ProtoPacked + public val repeatedFixed64: List = emptyList(), + @ProtoNumber(number = 9) + @ProtoPacked + public val repeatedSfixed32: List = emptyList(), + @ProtoNumber(number = 10) + @ProtoPacked + public val repeatedSfixed64: List = emptyList(), + @ProtoNumber(number = 11) + @ProtoPacked + public val repeatedFloat: List = emptyList(), + @ProtoNumber(number = 12) + @ProtoPacked + public val repeatedDouble: List = emptyList(), + @ProtoNumber(number = 13) + @ProtoPacked + public val repeatedBool: List = emptyList(), + @ProtoNumber(number = 14) + public val repeatedString: List = emptyList(), + @ProtoNumber(number = 15) + public val repeatedBytes: List = emptyList(), + @ProtoNumber(number = 16) + public val repeatedNestedMessage: List = emptyList(), + @ProtoNumber(number = 17) + public val repeatedForeignMessage: List = emptyList(), + @ProtoNumber(number = 18) + @ProtoPacked + public val repeatedNestedEnum: List = emptyList(), + @ProtoNumber(number = 19) + @ProtoPacked + public val repeatedForeignEnum: List = emptyList(), +) { + @Serializable + public data class NestedMessage( + @ProtoNumber(number = 1) + public val a: Int = 0, + @ProtoNumber(number = 2) + public val corecursive: RepeatedsMessage? = null, + ) + + @Serializable + public enum class NestedEnum { + @ProtoNumber(number = 0) + FOO, + @ProtoNumber(number = 1) + BAR, + @ProtoNumber(number = 2) + BAZ, + @ProtoNumber(number = -1) + NEG, + } +} + +@Serializable +public data class ForeignMessage( + @ProtoNumber(number = 1) + public val c: Int = 0, +) + +@Serializable +public enum class ForeignEnum { + @ProtoNumber(number = 0) + FOREIGN_FOO, + @ProtoNumber(number = 1) + FOREIGN_BAR, + @ProtoNumber(number = 2) + FOREIGN_BAZ, +} diff --git a/generated-code-tests/src/main/kotlin/testgen/test/grpc/test_grpc.proto.kt b/generated-code-tests/src/main/kotlin/testgen/test/grpc/test_grpc.proto.kt new file mode 100644 index 0000000..2c287a1 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/test/grpc/test_grpc.proto.kt @@ -0,0 +1,31 @@ +package testgen.test.grpc + +import kotlin.String +import kotlinx.coroutines.flow.Flow +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class TestUnaryRequest( + @ProtoNumber(number = 1) + public val name: String = "", +) + +@Serializable +public data class TestUnaryResponse( + @ProtoNumber(number = 1) + public val message: String = "", +) + +public abstract class TestService { + public open suspend fun testUnary(testUnaryRequest: TestUnaryRequest): TestUnaryResponse = TODO() + + public open suspend fun testClientStream(testUnaryRequest: Flow): + TestUnaryResponse = TODO() + + public open suspend fun testServerStream(testUnaryRequest: TestUnaryRequest): + Flow = TODO() + + public open suspend fun testBidiStream(testUnaryRequest: Flow): + Flow = TODO() +} diff --git a/generated-code-tests/src/main/kotlin/testgen/test/messages_under_test.proto.kt b/generated-code-tests/src/main/kotlin/testgen/test/messages_under_test.proto.kt new file mode 100644 index 0000000..9d2bd40 --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/test/messages_under_test.proto.kt @@ -0,0 +1,11 @@ +package testgen.test + +import kotlin.ByteArray +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber + +@Serializable +public data class BytesUnderTest( + @ProtoNumber(number = 1) + public val bytes: ByteArray = byteArrayOf(), +) diff --git a/generated-code-tests/src/main/kotlin/testgen/wkt/well_known_type.proto.kt b/generated-code-tests/src/main/kotlin/testgen/wkt/well_known_type.proto.kt new file mode 100644 index 0000000..4f1d00c --- /dev/null +++ b/generated-code-tests/src/main/kotlin/testgen/wkt/well_known_type.proto.kt @@ -0,0 +1,56 @@ +package testgen.wkt + +import dogacel.kotlinx.protobuf.gen.wkt.BoolValueP +import dogacel.kotlinx.protobuf.gen.wkt.BytesValueP +import dogacel.kotlinx.protobuf.gen.wkt.DoubleValueP +import dogacel.kotlinx.protobuf.gen.wkt.DurationP +import dogacel.kotlinx.protobuf.gen.wkt.FloatValueP +import dogacel.kotlinx.protobuf.gen.wkt.Int32ValueP +import dogacel.kotlinx.protobuf.gen.wkt.Int64ValueP +import dogacel.kotlinx.protobuf.gen.wkt.StringValueP +import dogacel.kotlinx.protobuf.gen.wkt.TimestampP +import dogacel.kotlinx.protobuf.gen.wkt.UInt32ValueP +import dogacel.kotlinx.protobuf.gen.wkt.UInt64ValueP +import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoNumber +import testgen.google.protobuf.Any +import testgen.google.protobuf.FieldMask +import testgen.google.protobuf.ListValue +import testgen.google.protobuf.Struct +import testgen.google.protobuf.Value + +@Serializable +public data class MessageWithWellKnownTypes( + @ProtoNumber(number = 1) + public val optionalBoolWrapper: BoolValueP? = null, + @ProtoNumber(number = 2) + public val optionalInt32Wrapper: Int32ValueP? = null, + @ProtoNumber(number = 3) + public val optionalInt64Wrapper: Int64ValueP? = null, + @ProtoNumber(number = 4) + public val optionalUint32Wrapper: UInt32ValueP? = null, + @ProtoNumber(number = 5) + public val optionalUint64Wrapper: UInt64ValueP? = null, + @ProtoNumber(number = 6) + public val optionalFloatWrapper: FloatValueP? = null, + @ProtoNumber(number = 7) + public val optionalDoubleWrapper: DoubleValueP? = null, + @ProtoNumber(number = 8) + public val optionalStringWrapper: StringValueP? = null, + @ProtoNumber(number = 9) + public val optionalBytesWrapper: BytesValueP? = null, + @ProtoNumber(number = 10) + public val optionalDuration: DurationP? = null, + @ProtoNumber(number = 11) + public val optionalTimestamp: TimestampP? = null, + @ProtoNumber(number = 12) + public val optionalFieldMask: FieldMask? = null, + @ProtoNumber(number = 13) + public val optionalStruct: Struct? = null, + @ProtoNumber(number = 14) + public val optionalAny: Any? = null, + @ProtoNumber(number = 15) + public val optionalValue: Value? = null, + @ProtoNumber(number = 16) + public val repeatedListValue: ListValue? = null, +)