Runtime support library for Wire-generated Protocol Buffer classes in Kotlin multiplatform applications
—
Cross-platform time and duration types that map to Google Well-Known Types (google.protobuf.Duration and google.protobuf.Timestamp). These provide consistent time handling across all Kotlin multiplatform targets.
Represents a time duration with nanosecond precision, mapping to google.protobuf.Duration.
/**
* A measurement of time. Durations may be positive, zero, or negative.
* Maps to google.protobuf.Duration
*/
expect class Duration {
/** Get seconds component */
fun getSeconds(): Long
/** Get nanoseconds component (0-999,999,999) */
fun getNano(): Int
}
/** Create duration from seconds and nanoseconds */
expect fun durationOfSeconds(seconds: Long, nano: Long): DurationRepresents a timestamp with nanosecond precision, mapping to google.protobuf.Timestamp.
/**
* Represents a timestamp (google.protobuf.Timestamp)
*/
expect class Instant {
/** Seconds since Unix epoch (1970-01-01T00:00:00Z) */
fun getEpochSecond(): Long
/** Nanoseconds component (0-999,999,999) */
fun getNano(): Int
}
/** Create instant from epoch seconds and nanoseconds */
expect fun ofEpochSecond(epochSecond: Long, nano: Long): InstantUsage Examples:
import com.squareup.wire.*
// Create duration (5.5 seconds)
val duration = durationOfSeconds(5, 500_000_000)
println("Seconds: ${duration.getSeconds()}") // 5
println("Nanos: ${duration.getNano()}") // 500000000
// Create instant (Unix timestamp)
val instant = ofEpochSecond(1640995200, 123_456_789) // 2022-01-01T00:00:00.123456789Z
println("Epoch seconds: ${instant.getEpochSecond()}") // 1640995200
println("Nanos: ${instant.getNano()}") // 123456789
// Use with ProtoAdapter
val encodedDuration = ProtoAdapter.DURATION.encode(duration)
val decodedDuration = ProtoAdapter.DURATION.decode(encodedDuration)
val encodedInstant = ProtoAdapter.INSTANT.encode(instant)
val decodedInstant = ProtoAdapter.INSTANT.decode(encodedInstant)Install with Tessl CLI
npx tessl i tessl/maven-com-squareup-wire--wire-runtime