Swatch

class Swatch

Opaque message moving between peers. The wire layer does not interpret the bytes; that is the consumer's job.

sender and sequence are filled in by the transport when the frame is received; senders leave them unset (null sender, zero sequence) and the local Seam stamps them on dispatch.

Encapsulated offset-view

Internally a Swatch is backed by a (ByteArray, offset, length) triple so that header-stripping in MuxSeam and NamedMux creates a zero-copy view via dropFirst. The backing array never escapes publicly — there is no accessor that returns the live backing array. All copies are explicit and named:

equals and hashCode compare the logical slice, so a dropFirst view equals a freshly-constructed Swatch of the same bytes.

Construction

Pass a ByteArray to the primary constructor. The Swatch takes ownership of that array — callers must not mutate it after construction.

Constructors

Link copied to clipboard
constructor(payload: ByteArray, sender: PeerId? = null, sequence: Long = 0)

Primary public constructor: takes ownership of payload so the whole array is the logical payload. Normal construction path for senders and for any code that already has a correctly-sized ByteArray.

Properties

Link copied to clipboard

The number of logical payload bytes. Does not allocate.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun byteAt(index: Int): Byte

Returns the byte at logical index index without allocating.

Link copied to clipboard
fun copy(sequence: Long): Swatch

Creates a copy with a different sequence, sharing the same backing array. Equivalent to the data-class copy(sequence = …).

fun copy(sender: PeerId?): Swatch

Creates a copy with a different sender, sharing the same backing array.

Link copied to clipboard
fun <T> decode(format: BinaryFormat, deserializer: DeserializationStrategy<T>): T

Decodes the logical payload using format and deserializer.

Link copied to clipboard

Decodes the logical payload bytes as a UTF-8 string without allocating an intermediate ByteArray (uses ByteArray.decodeToString over the internal slice).

Link copied to clipboard

Returns a view of this Swatch with the first n bytes of the logical payload removed, sharing the same backing array without copying.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns a copy of the logical payload as a fresh ByteArray.

Link copied to clipboard
open override fun toString(): String