3
3
*/
4
4
5
5
@file:OptIn(ExperimentalRpcApi ::class , kotlinx.rpc.internal.utils.InternalRpcApi ::class )
6
-
7
6
package com.google.protobuf.kotlin
8
7
9
- import kotlinx.rpc.internal.utils.ExperimentalRpcApi
8
+ import kotlinx.rpc.internal.utils.*
10
9
import kotlinx.rpc.protobuf.input.stream.asInputStream
11
- import kotlinx.rpc.protobuf.internal.MsgFieldDelegate
12
- import kotlinx.rpc.protobuf.internal.bytes
13
- import kotlinx.rpc.protobuf.internal.int32
14
- import kotlinx.rpc.protobuf.internal.string
15
- import kotlinx.rpc.protobuf.internal.tag
16
-
17
- public class AnyInternal : com.google.protobuf.kotlin.Any ,
18
- kotlinx.rpc.protobuf.internal.InternalMessage (fieldsWithPresence = 0 ) {
10
+ import kotlinx.rpc.protobuf.internal.*
11
+
12
+ public class AnyInternal : com.google.protobuf.kotlin.Any , kotlinx.rpc.protobuf.internal.InternalMessage (fieldsWithPresence = 0 ) {
19
13
@kotlinx.rpc.internal.utils.InternalRpcApi
20
14
public override val _size : Int by lazy { computeSize() }
21
15
22
16
public override var typeUrl: String by MsgFieldDelegate { " " }
23
17
public override var value: ByteArray by MsgFieldDelegate { byteArrayOf() }
24
18
25
19
@kotlinx.rpc.internal.utils.InternalRpcApi
26
- public object CODEC : kotlinx.rpc.grpc.codec.MessageCodec<com.google.protobuf.kotlin.Any> {
27
- public override fun encode (value : com.google.protobuf.kotlin.Any ): kotlinx.rpc.protobuf.input.stream.InputStream {
20
+ public object CODEC: kotlinx.rpc.grpc.codec.MessageCodec<com.google.protobuf.kotlin.Any> {
21
+ public override fun encode (value : com.google.protobuf.kotlin.Any ): kotlinx.rpc.protobuf.input.stream.InputStream {
28
22
val buffer = kotlinx.io.Buffer ()
29
23
val encoder = kotlinx.rpc.protobuf.internal.WireEncoder (buffer)
30
- kotlinx.rpc.protobuf.internal.checkForPlatformEncodeException {
24
+ kotlinx.rpc.protobuf.internal.checkForPlatformEncodeException {
31
25
value.asInternal().encodeWith(encoder)
32
26
}
33
27
encoder.flush()
34
28
return buffer.asInputStream()
35
29
}
36
30
37
- public override fun decode (stream : kotlinx.rpc.protobuf.input.stream.InputStream ): com.google.protobuf.kotlin.Any {
38
- kotlinx.rpc.protobuf.internal.WireDecoder (stream).use {
31
+ public override fun decode (stream : kotlinx.rpc.protobuf.input.stream.InputStream ): com.google.protobuf.kotlin.Any {
32
+ kotlinx.rpc.protobuf.internal.WireDecoder (stream).use {
39
33
val msg = com.google.protobuf.kotlin.AnyInternal ()
40
- kotlinx.rpc.protobuf.internal.checkForPlatformDecodeException {
34
+ kotlinx.rpc.protobuf.internal.checkForPlatformDecodeException {
41
35
com.google.protobuf.kotlin.AnyInternal .decodeWith(msg, it)
42
36
}
43
37
msg.checkRequiredFields()
@@ -50,46 +44,43 @@ public class AnyInternal : com.google.protobuf.kotlin.Any,
50
44
public companion object
51
45
}
52
46
53
- public operator fun com.google.protobuf.kotlin.Any.Companion.invoke (body : com.google.protobuf.kotlin.AnyInternal .() -> Unit ): com.google.protobuf.kotlin.Any {
47
+ public operator fun com.google.protobuf.kotlin.Any.Companion.invoke (body : com.google.protobuf.kotlin.AnyInternal .() -> Unit ): com.google.protobuf.kotlin.Any {
54
48
val msg = com.google.protobuf.kotlin.AnyInternal ().apply (body)
55
49
msg.checkRequiredFields()
56
50
return msg
57
51
}
58
52
59
53
@kotlinx.rpc.internal.utils.InternalRpcApi
60
- public fun com.google.protobuf.kotlin.AnyInternal.checkRequiredFields () {
54
+ public fun com.google.protobuf.kotlin.AnyInternal.checkRequiredFields () {
61
55
// no required fields to check
62
56
}
63
57
64
58
@kotlinx.rpc.internal.utils.InternalRpcApi
65
- public fun com.google.protobuf.kotlin.AnyInternal.encodeWith (encoder : kotlinx.rpc.protobuf.internal.WireEncoder ) {
66
- if (typeUrl.isNotEmpty()) {
59
+ public fun com.google.protobuf.kotlin.AnyInternal.encodeWith (encoder : kotlinx.rpc.protobuf.internal.WireEncoder ) {
60
+ if (typeUrl.isNotEmpty()) {
67
61
encoder.writeString(fieldNr = 1 , value = typeUrl)
68
62
}
69
63
70
- if (value.isNotEmpty()) {
64
+ if (value.isNotEmpty()) {
71
65
encoder.writeBytes(fieldNr = 2 , value = value)
72
66
}
73
67
}
74
68
75
69
@kotlinx.rpc.internal.utils.InternalRpcApi
76
- public fun com.google.protobuf.kotlin.AnyInternal.Companion.decodeWith (
77
- msg : com.google.protobuf.kotlin.AnyInternal ,
78
- decoder : kotlinx.rpc.protobuf.internal.WireDecoder ,
79
- ) {
80
- while (true ) {
70
+ public fun com.google.protobuf.kotlin.AnyInternal.Companion.decodeWith (msg : com.google.protobuf.kotlin.AnyInternal , decoder : kotlinx.rpc.protobuf.internal.WireDecoder ) {
71
+ while (true ) {
81
72
val tag = decoder.readTag() ? : break // EOF, we read the whole message
82
- when {
83
- tag.fieldNr == 1 && tag.wireType == kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED -> {
73
+ when {
74
+ tag.fieldNr == 1 && tag.wireType == kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED -> {
84
75
msg.typeUrl = decoder.readString()
85
76
}
86
77
87
- tag.fieldNr == 2 && tag.wireType == kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED -> {
78
+ tag.fieldNr == 2 && tag.wireType == kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED -> {
88
79
msg.value = decoder.readBytes()
89
80
}
90
81
91
- else -> {
92
- if (tag.wireType == kotlinx.rpc.protobuf.internal.WireType .END_GROUP ) {
82
+ else -> {
83
+ if (tag.wireType == kotlinx.rpc.protobuf.internal.WireType .END_GROUP ) {
93
84
throw kotlinx.rpc.protobuf.internal.ProtobufDecodingException (" Unexpected END_GROUP tag." )
94
85
}
95
86
@@ -100,32 +91,21 @@ public fun com.google.protobuf.kotlin.AnyInternal.Companion.decodeWith(
100
91
}
101
92
}
102
93
103
- private fun com.google.protobuf.kotlin.AnyInternal.computeSize (): Int {
94
+ private fun com.google.protobuf.kotlin.AnyInternal.computeSize (): Int {
104
95
var __result = 0
105
- if (typeUrl.isNotEmpty()) {
106
- __result + = kotlinx.rpc.protobuf.internal.WireSize .string(typeUrl).let {
107
- kotlinx.rpc.protobuf.internal.WireSize .tag(
108
- 1 ,
109
- kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED
110
- ) + kotlinx.rpc.protobuf.internal.WireSize .int32(it) + it
111
- }
96
+ if (typeUrl.isNotEmpty()) {
97
+ __result + = kotlinx.rpc.protobuf.internal.WireSize .string(typeUrl).let { kotlinx.rpc.protobuf.internal.WireSize .tag(1 , kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED ) + kotlinx.rpc.protobuf.internal.WireSize .int32(it) + it }
112
98
}
113
99
114
- if (value.isNotEmpty()) {
115
- __result + = kotlinx.rpc.protobuf.internal.WireSize .bytes(value).let {
116
- kotlinx.rpc.protobuf.internal.WireSize .tag(
117
- 2 ,
118
- kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED
119
- ) + kotlinx.rpc.protobuf.internal.WireSize .int32(it) + it
120
- }
100
+ if (value.isNotEmpty()) {
101
+ __result + = kotlinx.rpc.protobuf.internal.WireSize .bytes(value).let { kotlinx.rpc.protobuf.internal.WireSize .tag(2 , kotlinx.rpc.protobuf.internal.WireType .LENGTH_DELIMITED ) + kotlinx.rpc.protobuf.internal.WireSize .int32(it) + it }
121
102
}
122
103
123
104
return __result
124
105
}
125
106
126
107
@kotlinx.rpc.internal.utils.InternalRpcApi
127
- public fun com.google.protobuf.kotlin.Any.asInternal (): com.google.protobuf.kotlin.AnyInternal {
128
- return this as ? com.google.protobuf.kotlin.AnyInternal
129
- ? : error(" Message ${this ::class .simpleName} is a non-internal message type." )
108
+ public fun com.google.protobuf.kotlin.Any.asInternal (): com.google.protobuf.kotlin.AnyInternal {
109
+ return this as ? com.google.protobuf.kotlin.AnyInternal ? : error(" Message ${this ::class .simpleName} is a non-internal message type." )
130
110
}
131
111
0 commit comments