in agent-sdk/src/main/java/co/elastic/otel/android/internal/time/ntp/NtpPacket.kt [83:119]
fun parse(bytes: ByteArray): NtpPacket {
if (bytes.size < PACKET_SIZE_IN_BYTES) {
throw IllegalArgumentException("The min byte array size allowed is $PACKET_SIZE_IN_BYTES, the provided array size is ${bytes.size}.")
}
val longBuffer = ByteBuffer.allocate(Long.SIZE_BYTES)
val firstByte = bytes.first().toInt()
val leapIndicator = (firstByte shr 6) and 3
val versionNumber = (firstByte shr 3) and 7
val mode = firstByte and 7
val stratum = bytes[1].toInt()
val originateTimestamp = getTimestamp(
longBuffer,
bytes.sliceArray(24 until 28),
bytes.sliceArray(28 until 32)
)
val receiveTimestamp = getTimestamp(
longBuffer,
bytes.sliceArray(32 until 36),
bytes.sliceArray(36 until 40)
)
val transmitTimestamp = getTimestamp(
longBuffer,
bytes.sliceArray(40 until 44),
bytes.sliceArray(44 until 48)
)
return NtpPacket(
leapIndicator,
versionNumber,
mode,
stratum,
originateTimestamp,
receiveTimestamp,
transmitTimestamp
)
}