-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented skipping of filed with proto Id=0 if it missed in the des…
…criptor Also optimized skipping of size delimited fields - removed the creation of an byte array in case of skipping Fixes #2649
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/SkipFieldsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization.protobuf | ||
|
||
|
||
import kotlinx.serialization.* | ||
import kotlin.test.* | ||
|
||
class SkipFieldsTest { | ||
|
||
@Serializable | ||
data class Holder(val value: Int) | ||
|
||
@Test | ||
fun testSkipZeroId() { | ||
// first value with id = 0 | ||
val hexString = "000f082a" | ||
val holder = ProtoBuf.decodeFromHexString<Holder>(hexString) | ||
assertEquals(42, holder.value) | ||
} | ||
|
||
@Test | ||
fun testSkipBigId() { | ||
// first value with id = 2047 and takes 2 bytes | ||
val hexString = "f87f20082a" | ||
val holder = ProtoBuf.decodeFromHexString<Holder>(hexString) | ||
assertEquals(42, holder.value) | ||
} | ||
|
||
@Test | ||
fun testSkipString() { | ||
// first value is size delimited (string) with id = 42 | ||
val hexString = "d2020c48656c6c6f20576f726c6421082a" | ||
val holder = ProtoBuf.decodeFromHexString<Holder>(hexString) | ||
assertEquals(42, holder.value) | ||
} | ||
} |