Skip to content

Commit a74440e

Browse files
committed
grpc-pb: Remove hadError() method
Signed-off-by: Johannes Zottele <[email protected]>
1 parent c41ea19 commit a74440e

File tree

6 files changed

+4
-21
lines changed

6 files changed

+4
-21
lines changed

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ProtobufDecodingException : GrpcException {
1717
ProtobufDecodingException("Message '$messageName' is missing a required field: $fieldName")
1818

1919
internal fun negativeSize() = ProtobufDecodingException(
20-
"CodedInputStream encountered an embedded string or message which claimed to have negative size."
20+
"Decoder encountered an embedded string or message which claimed to have negative size."
2121
)
2222

2323
internal fun invalidTag() = ProtobufDecodingException(

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/pb/WireDecoder.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package kotlinx.rpc.grpc.pb
66

77
import kotlinx.io.Buffer
8+
import kotlinx.rpc.grpc.ProtobufDecodingException
89
import kotlinx.rpc.grpc.internal.popLimit
910
import kotlinx.rpc.grpc.internal.pushLimit
1011
import kotlinx.rpc.internal.utils.InternalRpcApi
@@ -41,8 +42,6 @@ internal const val MAX_PACKED_BULK_SIZE: Int = 1_000_000
4142
*/
4243
@InternalRpcApi
4344
public interface WireDecoder : AutoCloseable {
44-
public fun hadError(): Boolean
45-
4645
/**
4746
* When the read tag is null, it indicates EOF and the parser may stop at this point.
4847
*/
@@ -79,11 +78,9 @@ public interface WireDecoder : AutoCloseable {
7978
public fun readPackedDouble(): List<Double>
8079
public fun readPackedEnum(): List<Int>
8180

82-
// TODO: Throw error instead of just returning
8381
public fun <T : InternalMessage> readMessage(msg: T, decoder: (T, WireDecoder) -> Unit) {
8482
val len = readInt32()
85-
if (hadError()) return
86-
if (len <= 0) return
83+
if (len < 0) throw ProtobufDecodingException.negativeSize()
8784
val limit = pushLimit(len)
8885
decoder(msg, this)
8986
popLimit(limit)

grpc/grpc-core/src/commonTest/kotlin/kotlinx/rpc/grpc/pb/WireCodecTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class WireCodecTest {
2828
val decoder = WireDecoder(buffer)
2929

3030
val tag = decoder.readTag()
31-
assertFalse(decoder.hadError())
3231
assertNotNull(tag)
3332
assertEquals(WireType.VARINT, tag.wireType)
3433
assertEquals(fieldNr, tag.fieldNr)

grpc/grpc-core/src/jvmMain/kotlin/kotlinx/rpc/grpc/pb/WireDecoder.jvm.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ internal class WireDecoderJvm(source: Buffer) : WireDecoder {
1515
// there is no way to omit coping here
1616
internal val codedInputStream: CodedInputStream = CodedInputStream.newInstance(source.asInputStream())
1717

18-
// errors in jvm are exceptions
19-
override fun hadError(): Boolean {
20-
return false
21-
}
22-
2318
override fun readTag(): KTag? = checked {
2419
val tag = codedInputStream.readTag().toUInt()
2520
if (tag == 0u) {

grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/pb/WireDecoder.native.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ internal class WireDecoderNative(private val source: Buffer) : WireDecoder {
6060
zeroCopyInput.dispose()
6161
}
6262

63-
override fun hadError(): Boolean {
64-
return false
65-
}
66-
6763
override fun readTag(): KTag? {
6864
val tag = pw_decoder_read_tag(raw)
6965
if (tag == 0u) {

protoc-gen/src/main/kotlin/kotlinx/rpc/protobuf/ModelToKotlinCommonGenerator.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class ModelToKotlinCommonGenerator(
284284
annotations = listOf("@$INTERNAL_RPC_API_ANNO"),
285285
contextReceiver = "${declaration.internalClassFullName()}.Companion"
286286
) {
287-
whileBlock("!decoder.hadError()") {
287+
whileBlock("true") {
288288
code("val tag = decoder.readTag() ?: break // EOF, we read the whole message")
289289
whenBlock {
290290
declaration.fields().forEach { (_, field) -> readMatchCase(field) }
@@ -294,10 +294,6 @@ class ModelToKotlinCommonGenerator(
294294
}
295295
}
296296
}
297-
ifBranch(
298-
condition = "decoder.hadError()",
299-
ifBlock = { code("error(\"Error during decoding of ${declaration.name.simpleName}\")") }
300-
)
301297

302298
// TODO: Make lists and maps immutable (KRPC-190)
303299
}

0 commit comments

Comments
 (0)