BodyCapture

Turns captured bytes into the text preview the viewers show, shared by every capture adapter — the Ktor plugin and the native iOS bridge alike, so a truncated body reads the same on both.

Content types cross as String? rather than Ktor's ContentType on purpose: snoop-native gets snoop-core as implementation, so Ktor is not on its compile classpath, and the no-op mirror would have to grow a Ktor dependency it exists to avoid. Parsing happens here, where Ktor is already available.

Functions

Link copied to clipboard
fun binaryPlaceholder(contentType: String?, byteCount: Long): BodyPreview

Stand-in for a body we deliberately didn't read, so the viewer still shows it was there.

Link copied to clipboard
fun isTextLike(contentType: String?): Boolean

Whether a body of this content type is worth capturing as text (vs a binary placeholder).

Link copied to clipboard
fun textPreview(bytes: ByteArray, contentType: String?, maxLength: Long, byteCount: Long = bytes.size.toLong()): BodyPreview

Text preview of bytes, decoded with the charset the message declared — a Latin-1 response used to come out of the store full of replacement characters.