File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed
commonMain/kotlin/io/rsocket/kotlin/frame/io
commonTest/kotlin/io/rsocket/kotlin/frame/io Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,8 @@ internal fun ByteReadPacket.readAuthType(): AuthType = readType(
4747
4848private fun BytePacketBuilder.writeTextWithLength (text : String ) {
4949 val typeBytes = text.encodeToByteArray()
50- writeByte(typeBytes.size.toByte()) // write length
51- writeFully(typeBytes) // write mime type
50+ writeByte(( typeBytes.size - 1 ) .toByte())
51+ writeFully(typeBytes)
5252}
5353
5454private const val KnownTypeFlag : Byte = Byte .MIN_VALUE
@@ -66,7 +66,7 @@ private inline fun <T> ByteReadPacket.readType(
6666 val identifier = byte xor KnownTypeFlag
6767 fromIdentifier(identifier)
6868 } else {
69- val stringType = readTextExactBytes(byte.toInt())
69+ val stringType = readTextExactBytes(byte.toInt() + 1 )
7070 fromText(stringType)
7171 }
7272}
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2015-2024 the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io.rsocket.kotlin.frame.io
18+
19+ import io.ktor.utils.io.core.*
20+ import io.rsocket.kotlin.core.*
21+ import kotlin.test.*
22+
23+ class CustomMimeTypeTest {
24+ val name = " message/x.foo"
25+ private val fooMimeType = CustomMimeType (name)
26+
27+ @Test
28+ fun customMimeTypeSerialization () {
29+ val packet = BytePacketBuilder ().apply {
30+ writeMimeType(fooMimeType)
31+ }.build()
32+
33+ assertEquals((name.length - 1 ).toByte(), packet.copy().readByte())
34+ assertEquals(fooMimeType, packet.copy().readMimeType())
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments