From 8b8f8ed16e242341e81b0b87d58b3ed559ae058b Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Wed, 8 Jan 2025 16:13:03 -0500 Subject: [PATCH] Add internal inlined API --- benchmarks/build.gradle.kts | 1 + .../{BitOps.kt => BenchmarkParams.kt} | 0 library/endian/api/endian.api | 85 +++++ library/endian/api/endian.klib.api | 69 ++++ .../bitops/endian/-EndianInline.kt | 330 ++++++++++++++++++ .../org/kotlincrypto/bitops/endian/Endian.kt | 185 ++++------ .../bitops/endian/InternalEndianApi.kt | 44 +++ .../bitops/endian/internal/-EndianUtils.kt | 24 +- 8 files changed, 626 insertions(+), 112 deletions(-) rename benchmarks/src/commonMain/kotlin/org/kotlincrypto/bitops/benchmarks/{BitOps.kt => BenchmarkParams.kt} (100%) create mode 100644 library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/-EndianInline.kt create mode 100644 library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/InternalEndianApi.kt diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 1244838..8d0a6e2 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -54,6 +54,7 @@ kmpConfiguration { sourceSetMain { dependencies { implementation(libs.benchmark.runtime) + implementation(project(":library:bits")) implementation(project(":library:endian")) } } diff --git a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/bitops/benchmarks/BitOps.kt b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/bitops/benchmarks/BenchmarkParams.kt similarity index 100% rename from benchmarks/src/commonMain/kotlin/org/kotlincrypto/bitops/benchmarks/BitOps.kt rename to benchmarks/src/commonMain/kotlin/org/kotlincrypto/bitops/benchmarks/BenchmarkParams.kt diff --git a/library/endian/api/endian.api b/library/endian/api/endian.api index 0e96112..22dbb33 100644 --- a/library/endian/api/endian.api +++ b/library/endian/api/endian.api @@ -1,4 +1,5 @@ public abstract class org/kotlincrypto/bitops/endian/Endian { + public static final field Companion Lorg/kotlincrypto/bitops/endian/Endian$Companion; public abstract fun intFrom ([BI)I public abstract fun intOf (BBBB)I public abstract fun longFrom ([BI)J @@ -65,6 +66,9 @@ public final class org/kotlincrypto/bitops/endian/Endian$Big : org/kotlincrypto/ public fun shortOf (BB)S } +public final class org/kotlincrypto/bitops/endian/Endian$Companion { +} + public final class org/kotlincrypto/bitops/endian/Endian$Little : org/kotlincrypto/bitops/endian/Endian { public static final field INSTANCE Lorg/kotlincrypto/bitops/endian/Endian$Little; public fun equals (Ljava/lang/Object;)Z @@ -104,3 +108,84 @@ public final class org/kotlincrypto/bitops/endian/Endian$Little : org/kotlincryp public fun shortOf (BB)S } +public abstract interface annotation class org/kotlincrypto/bitops/endian/InternalEndianApi : java/lang/annotation/Annotation { +} + +public final class org/kotlincrypto/bitops/endian/_EndianInlineKt { + public static final fun beInlineIntFrom (Lorg/kotlincrypto/bitops/endian/Endian$Companion;[BI)I + public static final fun beInlineIntOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;BBBB)I + public static final fun beInlineLongFrom (Lorg/kotlincrypto/bitops/endian/Endian$Companion;[BI)J + public static final fun beInlineLongOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;BBBBBBBB)J + public static final fun beInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;I[BI)[B + public static final fun beInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;I[BIII)[B + public static final fun beInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;J[BI)[B + public static final fun beInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;J[BIII)[B + public static final fun beInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;S[BI)[B + public static final fun beInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;S[BIII)[B + public static synthetic fun beInlinePackUnsafe$default (Lorg/kotlincrypto/bitops/endian/Endian$Companion;I[BIIIILjava/lang/Object;)[B + public static synthetic fun beInlinePackUnsafe$default (Lorg/kotlincrypto/bitops/endian/Endian$Companion;J[BIIIILjava/lang/Object;)[B + public static synthetic fun beInlinePackUnsafe$default (Lorg/kotlincrypto/bitops/endian/Endian$Companion;S[BIIIILjava/lang/Object;)[B + public static final fun beInlineShortFrom (Lorg/kotlincrypto/bitops/endian/Endian$Companion;[BI)S + public static final fun beInlineShortOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;BB)S + public static final fun leInlineIntFrom (Lorg/kotlincrypto/bitops/endian/Endian$Companion;[BI)I + public static final fun leInlineIntOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;BBBB)I + public static final fun leInlineLongFrom (Lorg/kotlincrypto/bitops/endian/Endian$Companion;[BI)J + public static final fun leInlineLongOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;BBBBBBBB)J + public static final fun leInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;I[BI)[B + public static final fun leInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;I[BIII)[B + public static final fun leInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;J[BI)[B + public static final fun leInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;J[BIII)[B + public static final fun leInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;S[BI)[B + public static final fun leInlinePackUnsafe (Lorg/kotlincrypto/bitops/endian/Endian$Companion;S[BIII)[B + public static synthetic fun leInlinePackUnsafe$default (Lorg/kotlincrypto/bitops/endian/Endian$Companion;I[BIIIILjava/lang/Object;)[B + public static synthetic fun leInlinePackUnsafe$default (Lorg/kotlincrypto/bitops/endian/Endian$Companion;J[BIIIILjava/lang/Object;)[B + public static synthetic fun leInlinePackUnsafe$default (Lorg/kotlincrypto/bitops/endian/Endian$Companion;S[BIIIILjava/lang/Object;)[B + public static final fun leInlineShortFrom (Lorg/kotlincrypto/bitops/endian/Endian$Companion;[BI)S + public static final fun leInlineShortOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;BB)S + public static final fun longOf (Lorg/kotlincrypto/bitops/endian/Endian$Companion;II)J +} + +public final class org/kotlincrypto/bitops/endian/internal/B0 { + public static final synthetic fun box-impl (B)Lorg/kotlincrypto/bitops/endian/internal/B0; + public static fun constructor-impl (B)B + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (BLjava/lang/Object;)Z + public static final fun equals-impl0 (BB)Z + public fun hashCode ()I + public static fun hashCode-impl (B)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (B)Ljava/lang/String; + public final synthetic fun unbox-impl ()B +} + +public final class org/kotlincrypto/bitops/endian/internal/Lo { + public static final synthetic fun box-impl (I)Lorg/kotlincrypto/bitops/endian/internal/Lo; + public static fun constructor-impl (I)I + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (ILjava/lang/Object;)Z + public static final fun equals-impl0 (II)Z + public fun hashCode ()I + public static fun hashCode-impl (I)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (I)Ljava/lang/String; + public final synthetic fun unbox-impl ()I +} + +public final class org/kotlincrypto/bitops/endian/internal/_EndianUtilsKt { + public static final fun packAllElsePartial ([BIIIILkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)[B + public static final fun packBEInt ([BII)[B + public static final fun packBELong ([BJI)[B + public static final fun packBEShort ([BSI)[B + public static final fun packLEInt ([BII)[B + public static final fun packLELong ([BJI)[B + public static final fun packLEShort ([BSI)[B + public static final fun packPartial ([BIIILkotlin/jvm/functions/Function1;)[B + public static final fun toBEInt-_EY57KE (BBBB)I + public static final fun toBELong-23fJcIY (BBBBBBBB)J + public static final fun toBEShort-qNA_5i4 (BB)S + public static final fun toLEInt-_EY57KE (BBBB)I + public static final fun toLELong-23fJcIY (BBBBBBBB)J + public static final fun toLEShort-qNA_5i4 (BB)S + public static final fun toLong-DL1PAzY (II)J +} + diff --git a/library/endian/api/endian.klib.api b/library/endian/api/endian.klib.api index e3cc786..6f2d407 100644 --- a/library/endian/api/endian.klib.api +++ b/library/endian/api/endian.klib.api @@ -6,6 +6,32 @@ // - Show declarations: true // Library unique name: +open annotation class org.kotlincrypto.bitops.endian/InternalEndianApi : kotlin/Annotation { // org.kotlincrypto.bitops.endian/InternalEndianApi|null[0] + constructor () // org.kotlincrypto.bitops.endian/InternalEndianApi.|(){}[0] +} + +final value class org.kotlincrypto.bitops.endian.internal/B0 { // org.kotlincrypto.bitops.endian.internal/B0|null[0] + constructor (kotlin/Byte) // org.kotlincrypto.bitops.endian.internal/B0.|(kotlin.Byte){}[0] + + final val b0 // org.kotlincrypto.bitops.endian.internal/B0.b0|{}b0[0] + final fun (): kotlin/Byte // org.kotlincrypto.bitops.endian.internal/B0.b0.|(){}[0] + + final fun equals(kotlin/Any?): kotlin/Boolean // org.kotlincrypto.bitops.endian.internal/B0.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // org.kotlincrypto.bitops.endian.internal/B0.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // org.kotlincrypto.bitops.endian.internal/B0.toString|toString(){}[0] +} + +final value class org.kotlincrypto.bitops.endian.internal/Lo { // org.kotlincrypto.bitops.endian.internal/Lo|null[0] + constructor (kotlin/Int) // org.kotlincrypto.bitops.endian.internal/Lo.|(kotlin.Int){}[0] + + final val lo // org.kotlincrypto.bitops.endian.internal/Lo.lo|{}lo[0] + final fun (): kotlin/Int // org.kotlincrypto.bitops.endian.internal/Lo.lo.|(){}[0] + + final fun equals(kotlin/Any?): kotlin/Boolean // org.kotlincrypto.bitops.endian.internal/Lo.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // org.kotlincrypto.bitops.endian.internal/Lo.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // org.kotlincrypto.bitops.endian.internal/Lo.toString|toString(){}[0] +} + sealed class org.kotlincrypto.bitops.endian/Endian { // org.kotlincrypto.bitops.endian/Endian|null[0] abstract fun intFrom(kotlin/ByteArray, kotlin/Int): kotlin/Int // org.kotlincrypto.bitops.endian/Endian.intFrom|intFrom(kotlin.ByteArray;kotlin.Int){}[0] abstract fun intOf(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Int // org.kotlincrypto.bitops.endian/Endian.intOf|intOf(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] @@ -59,6 +85,8 @@ sealed class org.kotlincrypto.bitops.endian/Endian { // org.kotlincrypto.bitops. final inline fun (kotlin/ByteArray).beShortAt(kotlin/Int): kotlin/Short // org.kotlincrypto.bitops.endian/Endian.Big.beShortAt|beShortAt@kotlin.ByteArray(kotlin.Int){}[0] } + final object Companion // org.kotlincrypto.bitops.endian/Endian.Companion|null[0] + final object Little : org.kotlincrypto.bitops.endian/Endian { // org.kotlincrypto.bitops.endian/Endian.Little|null[0] final fun equals(kotlin/Any?): kotlin/Boolean // org.kotlincrypto.bitops.endian/Endian.Little.equals|equals(kotlin.Any?){}[0] final fun hashCode(): kotlin/Int // org.kotlincrypto.bitops.endian/Endian.Little.hashCode|hashCode(){}[0] @@ -91,3 +119,44 @@ sealed class org.kotlincrypto.bitops.endian/Endian { // org.kotlincrypto.bitops. final inline fun (kotlin/ByteArray).leShortAt(kotlin/Int): kotlin/Short // org.kotlincrypto.bitops.endian/Endian.Little.leShortAt|leShortAt@kotlin.ByteArray(kotlin.Int){}[0] } } + +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packAllElsePartial(kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function1, kotlin/Function1): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packAllElsePartial|packAllElsePartial@kotlin.ByteArray(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Function1;kotlin.Function1){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packBEInt(kotlin/Int, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packBEInt|packBEInt@kotlin.ByteArray(kotlin.Int;kotlin.Int){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packBELong(kotlin/Long, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packBELong|packBELong@kotlin.ByteArray(kotlin.Long;kotlin.Int){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packBEShort(kotlin/Short, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packBEShort|packBEShort@kotlin.ByteArray(kotlin.Short;kotlin.Int){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packLEInt(kotlin/Int, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packLEInt|packLEInt@kotlin.ByteArray(kotlin.Int;kotlin.Int){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packLELong(kotlin/Long, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packLELong|packLELong@kotlin.ByteArray(kotlin.Long;kotlin.Int){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packLEShort(kotlin/Short, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packLEShort|packLEShort@kotlin.ByteArray(kotlin.Short;kotlin.Int){}[0] +final inline fun (kotlin/ByteArray).org.kotlincrypto.bitops.endian.internal/packPartial(kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function1): kotlin/ByteArray // org.kotlincrypto.bitops.endian.internal/packPartial|packPartial@kotlin.ByteArray(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Function1){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/B0).org.kotlincrypto.bitops.endian.internal/toBEInt(kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Int // org.kotlincrypto.bitops.endian.internal/toBEInt|toBEInt@org.kotlincrypto.bitops.endian.internal.B0(kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/B0).org.kotlincrypto.bitops.endian.internal/toBELong(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Long // org.kotlincrypto.bitops.endian.internal/toBELong|toBELong@org.kotlincrypto.bitops.endian.internal.B0(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/B0).org.kotlincrypto.bitops.endian.internal/toBEShort(kotlin/Byte): kotlin/Short // org.kotlincrypto.bitops.endian.internal/toBEShort|toBEShort@org.kotlincrypto.bitops.endian.internal.B0(kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/B0).org.kotlincrypto.bitops.endian.internal/toLEInt(kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Int // org.kotlincrypto.bitops.endian.internal/toLEInt|toLEInt@org.kotlincrypto.bitops.endian.internal.B0(kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/B0).org.kotlincrypto.bitops.endian.internal/toLELong(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Long // org.kotlincrypto.bitops.endian.internal/toLELong|toLELong@org.kotlincrypto.bitops.endian.internal.B0(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/B0).org.kotlincrypto.bitops.endian.internal/toLEShort(kotlin/Byte): kotlin/Short // org.kotlincrypto.bitops.endian.internal/toLEShort|toLEShort@org.kotlincrypto.bitops.endian.internal.B0(kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian.internal/Lo).org.kotlincrypto.bitops.endian.internal/toLong(kotlin/Int): kotlin/Long // org.kotlincrypto.bitops.endian.internal/toLong|toLong@org.kotlincrypto.bitops.endian.internal.Lo(kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlineIntFrom(kotlin/ByteArray, kotlin/Int): kotlin/Int // org.kotlincrypto.bitops.endian/beInlineIntFrom|beInlineIntFrom@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlineIntOf(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Int // org.kotlincrypto.bitops.endian/beInlineIntOf|beInlineIntOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlineLongFrom(kotlin/ByteArray, kotlin/Int): kotlin/Long // org.kotlincrypto.bitops.endian/beInlineLongFrom|beInlineLongFrom@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlineLongOf(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Long // org.kotlincrypto.bitops.endian/beInlineLongOf|beInlineLongOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlinePackUnsafe(kotlin/Int, kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian/beInlinePackUnsafe|beInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Int;kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlinePackUnsafe(kotlin/Int, kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int =...): kotlin/ByteArray // org.kotlincrypto.bitops.endian/beInlinePackUnsafe|beInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Int;kotlin.ByteArray;kotlin.Int;kotlin.Int;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlinePackUnsafe(kotlin/Long, kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian/beInlinePackUnsafe|beInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Long;kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlinePackUnsafe(kotlin/Long, kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int =...): kotlin/ByteArray // org.kotlincrypto.bitops.endian/beInlinePackUnsafe|beInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Long;kotlin.ByteArray;kotlin.Int;kotlin.Int;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlinePackUnsafe(kotlin/Short, kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian/beInlinePackUnsafe|beInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Short;kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlinePackUnsafe(kotlin/Short, kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int =...): kotlin/ByteArray // org.kotlincrypto.bitops.endian/beInlinePackUnsafe|beInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Short;kotlin.ByteArray;kotlin.Int;kotlin.Int;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlineShortFrom(kotlin/ByteArray, kotlin/Int): kotlin/Short // org.kotlincrypto.bitops.endian/beInlineShortFrom|beInlineShortFrom@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/beInlineShortOf(kotlin/Byte, kotlin/Byte): kotlin/Short // org.kotlincrypto.bitops.endian/beInlineShortOf|beInlineShortOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlineIntFrom(kotlin/ByteArray, kotlin/Int): kotlin/Int // org.kotlincrypto.bitops.endian/leInlineIntFrom|leInlineIntFrom@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlineIntOf(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Int // org.kotlincrypto.bitops.endian/leInlineIntOf|leInlineIntOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlineLongFrom(kotlin/ByteArray, kotlin/Int): kotlin/Long // org.kotlincrypto.bitops.endian/leInlineLongFrom|leInlineLongFrom@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlineLongOf(kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte, kotlin/Byte): kotlin/Long // org.kotlincrypto.bitops.endian/leInlineLongOf|leInlineLongOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlinePackUnsafe(kotlin/Int, kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian/leInlinePackUnsafe|leInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Int;kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlinePackUnsafe(kotlin/Int, kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int =...): kotlin/ByteArray // org.kotlincrypto.bitops.endian/leInlinePackUnsafe|leInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Int;kotlin.ByteArray;kotlin.Int;kotlin.Int;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlinePackUnsafe(kotlin/Long, kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian/leInlinePackUnsafe|leInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Long;kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlinePackUnsafe(kotlin/Long, kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int =...): kotlin/ByteArray // org.kotlincrypto.bitops.endian/leInlinePackUnsafe|leInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Long;kotlin.ByteArray;kotlin.Int;kotlin.Int;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlinePackUnsafe(kotlin/Short, kotlin/ByteArray, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.bitops.endian/leInlinePackUnsafe|leInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Short;kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlinePackUnsafe(kotlin/Short, kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int =...): kotlin/ByteArray // org.kotlincrypto.bitops.endian/leInlinePackUnsafe|leInlinePackUnsafe@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Short;kotlin.ByteArray;kotlin.Int;kotlin.Int;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlineShortFrom(kotlin/ByteArray, kotlin/Int): kotlin/Short // org.kotlincrypto.bitops.endian/leInlineShortFrom|leInlineShortFrom@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.ByteArray;kotlin.Int){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/leInlineShortOf(kotlin/Byte, kotlin/Byte): kotlin/Short // org.kotlincrypto.bitops.endian/leInlineShortOf|leInlineShortOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Byte;kotlin.Byte){}[0] +final inline fun (org.kotlincrypto.bitops.endian/Endian.Companion).org.kotlincrypto.bitops.endian/longOf(kotlin/Int, kotlin/Int): kotlin/Long // org.kotlincrypto.bitops.endian/longOf|longOf@org.kotlincrypto.bitops.endian.Endian.Companion(kotlin.Int;kotlin.Int){}[0] diff --git a/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/-EndianInline.kt b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/-EndianInline.kt new file mode 100644 index 0000000..9b3abfb --- /dev/null +++ b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/-EndianInline.kt @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2025 Matthew Nelson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ +@file:Suppress("KotlinRedundantDiagnosticSuppress", "NOTHING_TO_INLINE", "DeprecatedCallableAddReplaceWith") + +package org.kotlincrypto.bitops.endian + +import org.kotlincrypto.bitops.endian.internal.* + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.longOf( + lo: Int, + hi: Int, +): Long = Lo(lo).toLong(hi = hi) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlineShortOf( + b0: Byte, + b1: Byte, +): Short = B0(b0).toBEShort(b1) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlineIntOf( + b0: Byte, + b1: Byte, + b2: Byte, + b3: Byte, +): Int = B0(b0).toBEInt(b1, b2, b3) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlineLongOf( + b0: Byte, + b1: Byte, + b2: Byte, + b3: Byte, + b4: Byte, + b5: Byte, + b6: Byte, + b7: Byte, +): Long = B0(b0).toBELong(b1, b2, b3, b4, b5, b6, b7) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlineShortOf( + b0: Byte, + b1: Byte, +): Short = B0(b0).toLEShort(b1) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlineIntOf( + b0: Byte, + b1: Byte, + b2: Byte, + b3: Byte, +): Int = B0(b0).toLEInt(b1, b2, b3) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlineLongOf( + b0: Byte, + b1: Byte, + b2: Byte, + b3: Byte, + b4: Byte, + b5: Byte, + b6: Byte, + b7: Byte, +): Long = B0(b0).toLELong(b1, b2, b3, b4, b5, b6, b7) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlineShortFrom( + source: ByteArray, + offset: Int, +): Short = B0(source[offset]).toBEShort( + source[offset + 1], +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlineIntFrom( + source: ByteArray, + offset: Int, +): Int = B0(source[offset]).toBEInt( + source[offset + 1], + source[offset + 2], + source[offset + 3], +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlineLongFrom( + source: ByteArray, + offset: Int, +): Long = B0(source[offset]).toBELong( + source[offset + 1], + source[offset + 2], + source[offset + 3], + source[offset + 4], + source[offset + 5], + source[offset + 6], + source[offset + 7], +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlineShortFrom( + source: ByteArray, + offset: Int, +): Short = B0(source[offset]).toLEShort( + source[offset + 1], +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlineIntFrom( + source: ByteArray, + offset: Int, +): Int = B0(source[offset]).toLEInt( + source[offset + 1], + source[offset + 2], + source[offset + 3], +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlineLongFrom( + source: ByteArray, + offset: Int, +): Long = B0(source[offset]).toLELong( + source[offset + 1], + source[offset + 2], + source[offset + 3], + source[offset + 4], + source[offset + 5], + source[offset + 6], + source[offset + 7], +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlinePackUnsafe( + target: Short, + dest: ByteArray, + destOffset: Int, +): ByteArray = dest.packBEShort(target, destOffset) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlinePackUnsafe( + target: Int, + dest: ByteArray, + destOffset: Int, +): ByteArray = dest.packBEInt(target, destOffset) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlinePackUnsafe( + target: Long, + dest: ByteArray, + destOffset: Int, +): ByteArray = dest.packBELong(target, destOffset) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlinePackUnsafe( + target: Short, + dest: ByteArray, + destOffset: Int, +): ByteArray = dest.packLEShort(target, destOffset) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlinePackUnsafe( + target: Int, + dest: ByteArray, + destOffset: Int, +): ByteArray = dest.packLEInt(target, destOffset) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlinePackUnsafe( + target: Long, + dest: ByteArray, + destOffset: Int, +): ByteArray = dest.packLELong(target, destOffset) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlinePackUnsafe( + target: Short, + dest: ByteArray, + destOffset: Int, + startIndex: Int, + endIndex: Int = Short.SIZE_BYTES, +): ByteArray = dest.packAllElsePartial( + offset = destOffset, + startIndex = startIndex, + endIndex = endIndex, + sizeBytes = Short.SIZE_BYTES, + packAll = { packBEShort(target, destOffset) }, + ushr = { bits -> (target.toInt() ushr (8 - bits)).toByte() }, +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlinePackUnsafe( + target: Int, + dest: ByteArray, + destOffset: Int, + startIndex: Int, + endIndex: Int = Int.SIZE_BYTES, +): ByteArray = dest.packAllElsePartial( + offset = destOffset, + startIndex = startIndex, + endIndex = endIndex, + sizeBytes = Int.SIZE_BYTES, + packAll = { packBEInt(target, destOffset) }, + ushr = { bits -> (target ushr (24 - bits)).toByte() }, +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.beInlinePackUnsafe( + target: Long, + dest: ByteArray, + destOffset: Int, + startIndex: Int, + endIndex: Int = Long.SIZE_BYTES, +): ByteArray = dest.packAllElsePartial( + offset = destOffset, + startIndex = startIndex, + endIndex = endIndex, + sizeBytes = Long.SIZE_BYTES, + packAll = { packBELong(target, destOffset) }, + ushr = { bits -> (target ushr (56 - bits)).toByte() }, +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlinePackUnsafe( + target: Short, + dest: ByteArray, + destOffset: Int, + startIndex: Int, + endIndex: Int = Short.SIZE_BYTES, +): ByteArray = dest.packAllElsePartial( + offset = destOffset, + startIndex = startIndex, + endIndex = endIndex, + sizeBytes = Short.SIZE_BYTES, + packAll = { packLEShort(target, destOffset) }, + ushr = { bits -> (target.toInt() ushr bits).toByte() }, +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlinePackUnsafe( + target: Int, + dest: ByteArray, + destOffset: Int, + startIndex: Int, + endIndex: Int = Int.SIZE_BYTES, +): ByteArray = dest.packAllElsePartial( + offset = destOffset, + startIndex = startIndex, + endIndex = endIndex, + sizeBytes = Int.SIZE_BYTES, + packAll = { packLEInt(target, destOffset) }, + ushr = { bits -> (target ushr bits).toByte() }, +) + +/** @suppress */ +@InternalEndianApi +@Deprecated("Not meant for public consumption", level = DeprecationLevel.ERROR) +public inline fun Endian.Companion.leInlinePackUnsafe( + target: Long, + dest: ByteArray, + destOffset: Int, + startIndex: Int, + endIndex: Int = Long.SIZE_BYTES, +): ByteArray = dest.packAllElsePartial( + offset = destOffset, + startIndex = startIndex, + endIndex = endIndex, + sizeBytes = Long.SIZE_BYTES, + packAll = { packLELong(target, destOffset) }, + ushr = { bits -> (target ushr bits).toByte() }, +) diff --git a/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/Endian.kt b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/Endian.kt index e337e44..bb74020 100644 --- a/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/Endian.kt +++ b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/Endian.kt @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -@file:Suppress("KotlinRedundantDiagnosticSuppress", "NOTHING_TO_INLINE") +@file:Suppress("KotlinRedundantDiagnosticSuppress", "NOTHING_TO_INLINE", "DEPRECATION_ERROR", "RemoveRedundantQualifierName") +@file:OptIn(InternalEndianApi::class) package org.kotlincrypto.bitops.endian -import org.kotlincrypto.bitops.endian.internal.* import kotlin.jvm.JvmStatic /** @@ -928,40 +928,40 @@ public sealed class Endian private constructor() { @JvmStatic public inline fun ByteArray.beShortAt( offset: Int, - ): Short = shortFrom(this, offset) + ): Short = Big.shortFrom(this, offset) /** Syntactic Sugar. See [Endian.Big.intFrom] */ @JvmStatic public inline fun ByteArray.beIntAt( offset: Int, - ): Int = intFrom(this, offset) + ): Int = Big.intFrom(this, offset) /** Syntactic Sugar. See [Endian.Big.longFrom] */ @JvmStatic public inline fun ByteArray.beLongAt( offset: Int, - ): Long = longFrom(this, offset) + ): Long = Big.longFrom(this, offset) /** Syntactic Sugar. See [Endian.Big.pack] */ @JvmStatic public inline fun ByteArray.bePack( target: Short, offset: Int, - ): ByteArray = pack(target, this, offset) + ): ByteArray = Big.pack(target, this, offset) /** Syntactic Sugar. See [Endian.Big.pack] */ @JvmStatic public inline fun ByteArray.bePack( target: Int, offset: Int, - ): ByteArray = pack(target, this, offset) + ): ByteArray = Big.pack(target, this, offset) /** Syntactic Sugar. See [Endian.Big.pack] */ @JvmStatic public inline fun ByteArray.bePack( target: Long, offset: Int, - ): ByteArray = pack(target, this, offset) + ): ByteArray = Big.pack(target, this, offset) /** Syntactic Sugar. See [Endian.Big.pack] */ @JvmStatic @@ -970,7 +970,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Short.SIZE_BYTES, - ): ByteArray = pack(target, this, offset, startIndex, endIndex) + ): ByteArray = Big.pack(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Big.pack] */ @JvmStatic @@ -979,7 +979,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Int.SIZE_BYTES, - ): ByteArray = pack(target, this, offset, startIndex, endIndex) + ): ByteArray = Big.pack(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Big.pack] */ @JvmStatic @@ -988,28 +988,28 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Long.SIZE_BYTES, - ): ByteArray = pack(target, this, offset, startIndex, endIndex) + ): ByteArray = Big.pack(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Big.packUnsafe] */ @JvmStatic public inline fun ByteArray.bePackUnsafe( target: Short, offset: Int, - ): ByteArray = packUnsafe(target, this, offset) + ): ByteArray = Big.packUnsafe(target, this, offset) /** Syntactic Sugar. See [Endian.Big.packUnsafe] */ @JvmStatic public inline fun ByteArray.bePackUnsafe( target: Int, offset: Int, - ): ByteArray = packUnsafe(target, this, offset) + ): ByteArray = Big.packUnsafe(target, this, offset) /** Syntactic Sugar. See [Endian.Big.packUnsafe] */ @JvmStatic public inline fun ByteArray.bePackUnsafe( target: Long, offset: Int, - ): ByteArray = packUnsafe(target, this, offset) + ): ByteArray = Big.packUnsafe(target, this, offset) /** Syntactic Sugar. See [Endian.Big.packUnsafe] */ @JvmStatic @@ -1018,7 +1018,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Short.SIZE_BYTES, - ): ByteArray = packUnsafe(target, this, offset, startIndex, endIndex) + ): ByteArray = Big.packUnsafe(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Big.packUnsafe] */ @JvmStatic @@ -1027,7 +1027,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Int.SIZE_BYTES, - ): ByteArray = packUnsafe(target, this, offset, startIndex, endIndex) + ): ByteArray = Big.packUnsafe(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Big.packUnsafe] */ @JvmStatic @@ -1036,19 +1036,19 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Long.SIZE_BYTES, - ): ByteArray = packUnsafe(target, this, offset, startIndex, endIndex) + ): ByteArray = Big.packUnsafe(target, this, offset, startIndex, endIndex) public override fun shortOf( b0: Byte, b1: Byte, - ): Short = B0(b0).toBEShort(b1) + ): Short = beInlineShortOf(b0, b1) public override fun intOf( b0: Byte, b1: Byte, b2: Byte, b3: Byte, - ): Int = B0(b0).toBEInt(b1, b2, b3) + ): Int = beInlineIntOf(b0, b1, b2, b3) public override fun longOf( b0: Byte, @@ -1059,54 +1059,40 @@ public sealed class Endian private constructor() { b5: Byte, b6: Byte, b7: Byte, - ): Long = B0(b0).toBELong(b1, b2, b3, b4, b5, b6, b7) + ): Long = beInlineLongOf(b0, b1, b2, b3, b4, b5, b6, b7) public override fun shortFrom( source: ByteArray, offset: Int, - ): Short = B0(source[offset]).toBEShort( - source[offset + 1], - ) + ): Short = beInlineShortFrom(source, offset) public override fun intFrom( source: ByteArray, offset: Int, - ): Int = B0(source[offset]).toBEInt( - source[offset + 1], - source[offset + 2], - source[offset + 3], - ) + ): Int = beInlineIntFrom(source, offset) public override fun longFrom( source: ByteArray, offset: Int - ): Long = B0(source[offset]).toBELong( - source[offset + 1], - source[offset + 2], - source[offset + 3], - source[offset + 4], - source[offset + 5], - source[offset + 6], - source[offset + 7], - ) + ): Long = beInlineLongFrom(source, offset) public override fun packUnsafe( target: Short, dest: ByteArray, destOffset: Int, - ): ByteArray = dest.packBEShort(target, destOffset) + ): ByteArray = beInlinePackUnsafe(target, dest, destOffset) public override fun packUnsafe( target: Int, dest: ByteArray, destOffset: Int, - ): ByteArray = dest.packBEInt(target, destOffset) + ): ByteArray = beInlinePackUnsafe(target, dest, destOffset) public override fun packUnsafe( target: Long, dest: ByteArray, destOffset: Int, - ): ByteArray = dest.packBELong(target, destOffset) + ): ByteArray = beInlinePackUnsafe(target, dest, destOffset) public override fun packUnsafe( target: Short, @@ -1114,13 +1100,12 @@ public sealed class Endian private constructor() { destOffset: Int, startIndex: Int, endIndex: Int, // = Short.SIZE_BYTES - ): ByteArray = dest.packAllElsePartial( - offset = destOffset, + ): ByteArray = beInlinePackUnsafe( + target = target, + dest = dest, + destOffset = destOffset, startIndex = startIndex, endIndex = endIndex, - sizeBytes = Short.SIZE_BYTES, - packAll = { packBEShort(target, destOffset) }, - ushr = { bits -> (target.toInt() ushr (8 - bits)).toByte() }, ) public override fun packUnsafe( @@ -1129,13 +1114,12 @@ public sealed class Endian private constructor() { destOffset: Int, startIndex: Int, endIndex: Int, // = Int.SIZE_BYTES - ): ByteArray = dest.packAllElsePartial( - offset = destOffset, + ): ByteArray = beInlinePackUnsafe( + target = target, + dest = dest, + destOffset = destOffset, startIndex = startIndex, endIndex = endIndex, - sizeBytes = Int.SIZE_BYTES, - packAll = { packBEInt(target, destOffset) }, - ushr = { bits -> (target ushr (24 - bits)).toByte() }, ) public override fun packUnsafe( @@ -1144,13 +1128,12 @@ public sealed class Endian private constructor() { destOffset: Int, startIndex: Int, endIndex: Int, // = Long.SIZE_BYTES - ): ByteArray = dest.packAllElsePartial( - offset = destOffset, + ): ByteArray = beInlinePackUnsafe( + target = target, + dest = dest, + destOffset = destOffset, startIndex = startIndex, endIndex = endIndex, - sizeBytes = Long.SIZE_BYTES, - packAll = { packBELong(target, destOffset) }, - ushr = { bits -> (target ushr (56 - bits)).toByte() }, ) } @@ -1166,40 +1149,40 @@ public sealed class Endian private constructor() { @JvmStatic public inline fun ByteArray.leShortAt( offset: Int, - ): Short = shortFrom(this, offset) + ): Short = Little.shortFrom(this, offset) /** Syntactic Sugar. See [Endian.Little.intFrom] */ @JvmStatic public inline fun ByteArray.leIntAt( offset: Int, - ): Int = intFrom(this, offset) + ): Int = Little.intFrom(this, offset) /** Syntactic Sugar. See [Endian.Little.longFrom] */ @JvmStatic public inline fun ByteArray.leLongAt( offset: Int, - ): Long = longFrom(this, offset) + ): Long = Little.longFrom(this, offset) /** Syntactic Sugar. See [Endian.Little.pack] */ @JvmStatic public inline fun ByteArray.lePack( target: Short, offset: Int, - ): ByteArray = pack(target, this, offset) + ): ByteArray = Little.pack(target, this, offset) /** Syntactic Sugar. See [Endian.Little.pack] */ @JvmStatic public inline fun ByteArray.lePack( target: Int, offset: Int, - ): ByteArray = pack(target, this, offset) + ): ByteArray = Little.pack(target, this, offset) /** Syntactic Sugar. See [Endian.Little.pack] */ @JvmStatic public inline fun ByteArray.lePack( target: Long, offset: Int, - ): ByteArray = pack(target, this, offset) + ): ByteArray = Little.pack(target, this, offset) /** Syntactic Sugar. See [Endian.Little.pack] */ @JvmStatic @@ -1208,7 +1191,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Short.SIZE_BYTES, - ): ByteArray = pack(target, this, offset, startIndex, endIndex) + ): ByteArray = Little.pack(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Little.pack] */ @JvmStatic @@ -1217,7 +1200,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Int.SIZE_BYTES, - ): ByteArray = pack(target, this, offset, startIndex, endIndex) + ): ByteArray = Little.pack(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Little.pack] */ @JvmStatic @@ -1226,28 +1209,28 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Long.SIZE_BYTES, - ): ByteArray = pack(target, this, offset, startIndex, endIndex) + ): ByteArray = Little.pack(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Little.packUnsafe] */ @JvmStatic public inline fun ByteArray.lePackUnsafe( target: Short, offset: Int, - ): ByteArray = packUnsafe(target, this, offset) + ): ByteArray = Little.packUnsafe(target, this, offset) /** Syntactic Sugar. See [Endian.Little.packUnsafe] */ @JvmStatic public inline fun ByteArray.lePackUnsafe( target: Int, offset: Int, - ): ByteArray = packUnsafe(target, this, offset) + ): ByteArray = Little.packUnsafe(target, this, offset) /** Syntactic Sugar. See [Endian.Little.packUnsafe] */ @JvmStatic public inline fun ByteArray.lePackUnsafe( target: Long, offset: Int, - ): ByteArray = packUnsafe(target, this, offset) + ): ByteArray = Little.packUnsafe(target, this, offset) /** Syntactic Sugar. See [Endian.Little.packUnsafe] */ @JvmStatic @@ -1256,7 +1239,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Short.SIZE_BYTES, - ): ByteArray = packUnsafe(target, this, offset, startIndex, endIndex) + ): ByteArray = Little.packUnsafe(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Little.packUnsafe] */ @JvmStatic @@ -1265,7 +1248,7 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Int.SIZE_BYTES, - ): ByteArray = packUnsafe(target, this, offset, startIndex, endIndex) + ): ByteArray = Little.packUnsafe(target, this, offset, startIndex, endIndex) /** Syntactic Sugar. See [Endian.Little.packUnsafe] */ @JvmStatic @@ -1274,19 +1257,19 @@ public sealed class Endian private constructor() { offset: Int, startIndex: Int, endIndex: Int = Long.SIZE_BYTES, - ): ByteArray = packUnsafe(target, this, offset, startIndex, endIndex) + ): ByteArray = Little.packUnsafe(target, this, offset, startIndex, endIndex) public override fun shortOf( b0: Byte, b1: Byte, - ): Short = B0(b0).toLEShort(b1) + ): Short = leInlineShortOf(b0, b1) public override fun intOf( b0: Byte, b1: Byte, b2: Byte, b3: Byte, - ): Int = B0(b0).toLEInt(b1, b2, b3) + ): Int = leInlineIntOf(b0, b1, b2, b3) public override fun longOf( b0: Byte, @@ -1297,54 +1280,40 @@ public sealed class Endian private constructor() { b5: Byte, b6: Byte, b7: Byte, - ): Long = B0(b0).toLELong(b1, b2, b3, b4, b5, b6, b7) + ): Long = leInlineLongOf(b0, b1, b2, b3, b4, b5, b6, b7) public override fun shortFrom( source: ByteArray, offset: Int, - ): Short = B0(source[offset]).toLEShort( - source[offset + 1], - ) + ): Short = leInlineShortFrom(source, offset) public override fun intFrom( source: ByteArray, offset: Int, - ): Int = B0(source[offset]).toLEInt( - source[offset + 1], - source[offset + 2], - source[offset + 3], - ) + ): Int = leInlineIntFrom(source, offset) public override fun longFrom( source: ByteArray, offset: Int - ): Long = B0(source[offset]).toLELong( - source[offset + 1], - source[offset + 2], - source[offset + 3], - source[offset + 4], - source[offset + 5], - source[offset + 6], - source[offset + 7], - ) + ): Long = leInlineLongFrom(source, offset) public override fun packUnsafe( target: Short, dest: ByteArray, destOffset: Int, - ): ByteArray = dest.packLEShort(target, destOffset) + ): ByteArray = leInlinePackUnsafe(target, dest, destOffset) public override fun packUnsafe( target: Int, dest: ByteArray, destOffset: Int, - ): ByteArray = dest.packLEInt(target, destOffset) + ): ByteArray = leInlinePackUnsafe(target, dest, destOffset) public override fun packUnsafe( target: Long, dest: ByteArray, destOffset: Int, - ): ByteArray = dest.packLELong(target, destOffset) + ): ByteArray = leInlinePackUnsafe(target, dest, destOffset) public override fun packUnsafe( target: Short, @@ -1352,13 +1321,12 @@ public sealed class Endian private constructor() { destOffset: Int, startIndex: Int, endIndex: Int, // = Short.SIZE_BYTES - ): ByteArray = dest.packAllElsePartial( - offset = destOffset, + ): ByteArray = leInlinePackUnsafe( + target = target, + dest = dest, + destOffset = destOffset, startIndex = startIndex, endIndex = endIndex, - sizeBytes = Short.SIZE_BYTES, - packAll = { packLEShort(target, destOffset) }, - ushr = { bits -> (target.toInt() ushr bits).toByte() }, ) public override fun packUnsafe( @@ -1367,13 +1335,12 @@ public sealed class Endian private constructor() { destOffset: Int, startIndex: Int, endIndex: Int, // = Int.SIZE_BYTES - ): ByteArray = dest.packAllElsePartial( - offset = destOffset, + ): ByteArray = leInlinePackUnsafe( + target = target, + dest = dest, + destOffset = destOffset, startIndex = startIndex, endIndex = endIndex, - sizeBytes = Int.SIZE_BYTES, - packAll = { packLEInt(target, destOffset) }, - ushr = { bits -> (target ushr bits).toByte() }, ) public override fun packUnsafe( @@ -1382,13 +1349,12 @@ public sealed class Endian private constructor() { destOffset: Int, startIndex: Int, endIndex: Int, // = Long.SIZE_BYTES - ): ByteArray = dest.packAllElsePartial( - offset = destOffset, + ): ByteArray = leInlinePackUnsafe( + target = target, + dest = dest, + destOffset = destOffset, startIndex = startIndex, endIndex = endIndex, - sizeBytes = Long.SIZE_BYTES, - packAll = { packLELong(target, destOffset) }, - ushr = { bits -> (target ushr bits).toByte() }, ) } @@ -1398,7 +1364,8 @@ public sealed class Endian private constructor() { is Little -> "Endian.Little" } - private companion object { + /** @suppress */ + public companion object { @JvmStatic private fun checkPackParameters( diff --git a/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/InternalEndianApi.kt b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/InternalEndianApi.kt new file mode 100644 index 0000000..41f4fc2 --- /dev/null +++ b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/InternalEndianApi.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Matthew Nelson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ +package org.kotlincrypto.bitops.endian + +/** + * Denotes an api as internal, and subject to change at any time. + * + * Any usage of a declaration annotated with [InternalEndianApi] + * must be accepted by annotating that usage with the [OptIn] + * annotation, e.g. @OptIn(InternalEndianApi::class), or by using + * the following compiler argument: + * + * -Xopt-in=org.kotlincrypto.bitops.endian.InternalEndianApi + * */ +@RequiresOptIn +@MustBeDocumented +@Target( + AnnotationTarget.CLASS, + AnnotationTarget.ANNOTATION_CLASS, + AnnotationTarget.PROPERTY, + AnnotationTarget.FIELD, + AnnotationTarget.LOCAL_VARIABLE, + AnnotationTarget.VALUE_PARAMETER, + AnnotationTarget.CONSTRUCTOR, + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.TYPEALIAS +) +@Retention(AnnotationRetention.BINARY) +public annotation class InternalEndianApi diff --git a/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/internal/-EndianUtils.kt b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/internal/-EndianUtils.kt index 179336c..637c35b 100644 --- a/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/internal/-EndianUtils.kt +++ b/library/endian/src/commonMain/kotlin/org/kotlincrypto/bitops/endian/internal/-EndianUtils.kt @@ -20,16 +20,20 @@ package org.kotlincrypto.bitops.endian.internal import kotlin.jvm.JvmInline @JvmInline -internal value class B0 internal constructor(internal val b0: Byte) +@PublishedApi +internal value class B0 @PublishedApi internal constructor(@PublishedApi internal val b0: Byte) @JvmInline -internal value class Lo internal constructor(internal val lo: Int) +@PublishedApi +internal value class Lo @PublishedApi internal constructor(@PublishedApi internal val lo: Int) +@PublishedApi internal inline fun Lo.toLong(hi: Int): Long { return ((hi.toLong() and 0xffffffff) shl 32) or ((lo.toLong() and 0xffffffff) ) } +@PublishedApi internal inline fun B0.toBEShort(b1: Byte): Short { return ( ((b0.toInt() and 0xff) shl 8) or @@ -37,6 +41,7 @@ internal inline fun B0.toBEShort(b1: Byte): Short { ).toShort() } +@PublishedApi internal inline fun B0.toLEShort(b1: Byte): Short { return ( ((b0.toInt() and 0xff) ) or @@ -44,6 +49,7 @@ internal inline fun B0.toLEShort(b1: Byte): Short { ).toShort() } +@PublishedApi internal inline fun B0.toBEInt(b1: Byte, b2: Byte, b3: Byte): Int { return ((b0.toInt() ) shl 24) or ((b1.toInt() and 0xff) shl 16) or @@ -51,6 +57,7 @@ internal inline fun B0.toBEInt(b1: Byte, b2: Byte, b3: Byte): Int { ((b3.toInt() and 0xff) ) } +@PublishedApi internal inline fun B0.toLEInt(b1: Byte, b2: Byte, b3: Byte): Int { return ((b0.toInt() and 0xff) ) or ((b1.toInt() and 0xff) shl 8) or @@ -58,26 +65,31 @@ internal inline fun B0.toLEInt(b1: Byte, b2: Byte, b3: Byte): Int { ((b3.toInt() ) shl 24) } +@PublishedApi internal inline fun B0.toBELong(b1: Byte, b2: Byte, b3: Byte, b4: Byte, b5: Byte, b6: Byte, b7: Byte): Long { return Lo(B0(b4).toBEInt(b5, b6, b7)).toLong(hi = this.toBEInt(b1, b2, b3)) } +@PublishedApi internal inline fun B0.toLELong(b1: Byte, b2: Byte, b3: Byte, b4: Byte, b5: Byte, b6: Byte, b7: Byte): Long { return Lo(this.toLEInt(b1, b2, b3)).toLong(hi = B0(b4).toLEInt(b5, b6, b7)) } +@PublishedApi internal inline fun ByteArray.packBEShort(target: Short, offset: Int): ByteArray { this[offset ] = (target.toInt() ushr 8).toByte() this[offset + 1] = (target ).toByte() return this } +@PublishedApi internal inline fun ByteArray.packLEShort(target: Short, offset: Int): ByteArray { this[offset ] = (target ).toByte() this[offset + 1] = (target.toInt() ushr 8).toByte() return this } +@PublishedApi internal inline fun ByteArray.packBEInt(target: Int, offset: Int): ByteArray { this[offset ] = (target ushr 24).toByte() this[offset + 1] = (target ushr 16).toByte() @@ -86,6 +98,7 @@ internal inline fun ByteArray.packBEInt(target: Int, offset: Int): ByteArray { return this } +@PublishedApi internal inline fun ByteArray.packLEInt(target: Int, offset: Int): ByteArray { this[offset ] = (target ).toByte() this[offset + 1] = (target ushr 8).toByte() @@ -94,6 +107,7 @@ internal inline fun ByteArray.packLEInt(target: Int, offset: Int): ByteArray { return this } +@PublishedApi internal inline fun ByteArray.packBELong(target: Long, offset: Int): ByteArray { this[offset ] = (target ushr 56).toByte() this[offset + 1] = (target ushr 48).toByte() @@ -106,6 +120,7 @@ internal inline fun ByteArray.packBELong(target: Long, offset: Int): ByteArray { return this } +@PublishedApi internal inline fun ByteArray.packLELong(target: Long, offset: Int): ByteArray { this[offset ] = (target ).toByte() this[offset + 1] = (target ushr 8).toByte() @@ -118,6 +133,7 @@ internal inline fun ByteArray.packLELong(target: Long, offset: Int): ByteArray { return this } +@PublishedApi internal inline fun ByteArray.packAllElsePartial( offset: Int, startIndex: Int, @@ -126,10 +142,12 @@ internal inline fun ByteArray.packAllElsePartial( packAll: ByteArray.() -> ByteArray, ushr: (bits: Int) -> Byte, ): ByteArray { - return if (startIndex == 0 && endIndex == sizeBytes) packAll() + // Check endIndex first + return if (endIndex == sizeBytes && startIndex == 0) packAll() else packPartial(offset, startIndex, endIndex, ushr) } +@PublishedApi internal inline fun ByteArray.packPartial( offset: Int, startIndex: Int,