Skip to content

Commit

Permalink
fix error message; add some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump committed Jan 9, 2024
1 parent 1b1ecc8 commit cbb59c4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ internal class GoogleJavaJSONAdapter<E : Message>(
if (deterministic) {
printer = printer.sortingMapKeys()
}
// TODO: It would likely be more efficient to use printer.appendTo
// with an Appendable implementation that wraps a Buffer.
val jsonString = printer.print(message)
return Buffer().write(jsonString.encodeUtf8())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GoogleJavaJSONStrategy(

override fun <E : Any> codec(clazz: KClass<E>): Codec<E> {
if (!clazz.isSubclassOf(Message::class)) {
throw RuntimeException("class ${clazz.qualifiedName} does not extend MessageLite")
throw RuntimeException("class ${clazz.qualifiedName} does not extend Message")
}
@Suppress("UNCHECKED_CAST") // we just checked above, so it's safe
val messageClass = clazz as KClass<out Message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ internal class GoogleJavaProtoAdapter<E : MessageLite>(
}

private fun serialize(message: E, deterministic: Boolean): Buffer {
// TODO: It would likely be more efficient to wrap a Buffer with
// an OutputStream implementation so we don't have to
// first create a separate byte array that gets copied to
// buffer.
val result = ByteArray(message.serializedSize)
val output = CodedOutputStream.newInstance(result)
if (deterministic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ internal class GoogleLiteProtoAdapter<E : MessageLite>(
}

private fun serialize(message: E, deterministic: Boolean): Buffer {
// TODO: It would likely be more efficient to wrap a Buffer with
// an OutputStream implementation so we don't have to
// first create a separate byte array that gets copied to
// buffer.
val result = ByteArray(message.serializedSize)
val output = CodedOutputStream.newInstance(result)
if (deterministic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ internal fun codeFromIOException(e: IOException): Code {
) {
Code.DEADLINE_EXCEEDED
} else if (e.message?.lowercase() == "canceled") {
// TODO: Figure out what, if anything, actually throws an exception
// with this message. It seems more likely that a JVM or
// Kotlin coroutine exception would spell it with two Ls.
Code.CANCELED
} else {
Code.UNKNOWN
Expand Down

0 comments on commit cbb59c4

Please sign in to comment.