Skip to content

Commit

Permalink
fix(OpaqueValue): set StringWriter initial size to 256 chars since mo…
Browse files Browse the repository at this point in the history
…st encoded strings are longer than the default 16 characters
  • Loading branch information
lemnik committed Apr 24, 2024
1 parent 198036f commit 1fc88a6
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.bugsnag.android.ndk
import com.bugsnag.android.JsonStream
import java.io.StringWriter

private const val i = 256

/**
* Marker class for values that are `BSG_METADATA_OPAQUE_VALUE` in the C layer
*/
internal class OpaqueValue(val json: String) {
companion object {
private const val MAX_NDK_STRING_LENGTH = 64
private const val US_ASCII_MAX_CODEPOINT = 127
private const val INITIAL_BUFFER_SIZE = 256

private fun isStringNDKSupported(value: String): Boolean {
// anything over 63 characters is definitely not supported
Expand All @@ -27,7 +30,7 @@ internal class OpaqueValue(val json: String) {
}

private fun encode(value: Any): String {
val writer = StringWriter()
val writer = StringWriter(INITIAL_BUFFER_SIZE)
writer.use { JsonStream(it).value(value, false) }
return writer.toString()
}
Expand Down

0 comments on commit 1fc88a6

Please sign in to comment.