-
Notifications
You must be signed in to change notification settings - Fork 14
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
runtime polish #198
runtime polish #198
Conversation
private val _sizeOf: KFunction1<Int, Int> = SizeCodecs::sizeOf | ||
|
||
val sizeOf = SizeCodecs::class.asTypeName().member(_sizeOf.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get compile-safe references to these functions.
object Message : Nonscalar(ktRepresentation = KtMessage::class) | ||
object String : Nonscalar(kotlin.String::class) | ||
object Bytes : Nonscalar(protokt.v1.Bytes::class) | ||
data object Enum : Nonscalar(ktRepresentation = KtEnum::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE recommended, shrug
// strips Explicit API mode declarations | ||
// https://kotlinlang.org/docs/whatsnew14.html#explicit-api-mode-for-library-authors | ||
private fun stripApiMode(code: String) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meh
KtLintRuleEngine( | ||
ruleProviders(), | ||
editorConfigOverride = EditorConfigOverride.from( | ||
INDENT_SIZE_PROPERTY to 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave KotlinPoet settings alone.
} | ||
|
||
public final class protokt/v1/Bytes { | ||
public static final field Companion Lprotokt/v1/Bytes$Companion; | ||
public fun <init> ([B)V | ||
public static final fun empty ()Lprotokt/v1/Bytes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve Java interop.
class Bytes internal constructor( | ||
internal val value: ByteArray | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make defensive copies.
} else { | ||
unmodifiableMap(map) | ||
} | ||
expect object Collections { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap these functions for polish and ability to use JvmStatic.
t + sizeOf(k, v).let { s -> | ||
s + sizeOf(s) | ||
@JvmStatic | ||
fun <K, V> sizeOf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just call it sizeOf like the others
@@ -38,12 +44,14 @@ class Bytes(internal val value: ByteArray) { | |||
companion object { | |||
private val EMPTY = Bytes(ByteArray(0)) | |||
|
|||
@JvmStatic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could have sworn I tried to put JvmStatic in common code before and the compiler threw up - now that it's working, I'm going to consider adding it to the generated code in the right spots before going 1.0, if there are any right spots. Maybe the constructor functions if I put them in companion objects.
protokt-runtime/src/commonMain/kotlin/com/toasttab/protokt/rt/KtMessage.kt
Outdated
Show resolved
Hide resolved
|
||
@JvmStatic | ||
fun from(message: KtMessage) = | ||
Bytes(message.serialize()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No-copy Bytes construction from a KtMessage.
Changes:
Bytes.from(ktmessage)
.Collections
andSizeCodecs
Foo.FooDsl
becomesFoo.Builder
JvmInline
classes now that that API is stable (open to undoing this)