Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation for computing the required bytes to encode a message #2239

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions formats/protobuf/api/kotlinx-serialization-protobuf.api
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public final class kotlinx/serialization/protobuf/ProtoBufKt {
public static synthetic fun ProtoBuf$default (Lkotlinx/serialization/protobuf/ProtoBuf;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/serialization/protobuf/ProtoBuf;
}

public final class kotlinx/serialization/protobuf/ProtoBufSerializedSizeCalculatorKt {
public static final fun getOrComputeSerializedSize (Lkotlinx/serialization/protobuf/ProtoBuf;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)I
}

public final class kotlinx/serialization/protobuf/ProtoIntegerType : java/lang/Enum {
public static final field DEFAULT Lkotlinx/serialization/protobuf/ProtoIntegerType;
public static final field FIXED Lkotlinx/serialization/protobuf/ProtoIntegerType;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kotlinx.serialization.protobuf

import kotlinx.serialization.descriptors.SerialDescriptor

internal actual fun createSerializedSizeCache(): SerializedSizeCache = JsHashMap()

private class JsHashMap : SerializedSizeCache {
private val cache = mutableMapOf<SerialDescriptor, SerializedData>()

override fun get(descriptor: SerialDescriptor, key: SerializedSizeCacheKey): Int? = cache[descriptor]?.get(key)

override fun set(descriptor: SerialDescriptor, key: SerializedSizeCacheKey, serializedSize: Int) {
cache[descriptor] = mapOf(key to serializedSize)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kotlinx.serialization.protobuf

import kotlinx.serialization.descriptors.SerialDescriptor
import java.util.concurrent.ConcurrentHashMap

internal actual fun createSerializedSizeCache(): SerializedSizeCache {
return ConcurrentHashMapSerializedCache()
}

private class ConcurrentHashMapSerializedCache : SerializedSizeCache {
private val cache = ConcurrentHashMap<SerialDescriptor, SerializedData>()

override fun get(descriptor: SerialDescriptor, key: SerializedSizeCacheKey): Int? = cache[descriptor]?.get(key)

override fun set(descriptor: SerialDescriptor, key: SerializedSizeCacheKey, serializedSize: Int) {
cache[descriptor] = mapOf(key to serializedSize)
}
}
Loading