This repository contains typealiases for Kotlin types as Byte, Short, Int and Long to their respective representations in Rust as Int8, Int16, Int32, Int64 and so on.
Type aliases
typealiasUInt8= UBytetypealiasUInt16= UShorttypealiasUInt32= UInttypealiasUInt64= ULongtypealiasInt8= BytetypealiasInt16= ShorttypealiasInt32= InttypealiasInt64= Long
All types are provided with to and from ByteArray conversion for our SCALE codec purpose using Little Endian system.
// Usage exampleval int64Value: Int64=64L// don't forget L suffix for "long" types as we're still in Kotlin environmentval int64ByteArray: ByteArray= int64Value.toByteArray() // [64, 0, 0, 0, 0, 0, 0, 0]val int64FromByteArray: Int64= int64ByteArray.toInt64() // 64L, .toLong() also available
Big Integer wrapping types
Kotlin doesn't have integer with size bigger than 64 bits, thus we have added new types to this library which wrap BigInteger so that they can be used for separate serialization adapter in our SCALE codec library.
Each of them also has same to and from ByteArray set of methods, but also for convenience there are constructors to avoid extra BigInteger construction.
// Usage exampleval int256FromString = Int256("1234567890") // creates Int256 instance which wraps BigInteger with 1234567890 value inside it
val int8: Int8=8val int256FromInt8 = Int256(int8) // creates Int256 instance wrapping BigInteger which is created from Int8 / Byte value
val int16: Int16=16val int256FromInt16 = Int256(int16) // creates Int256 instance wrapping BigInteger which is created from Int16 / Short value
val int32: Int32=32val int256FromInt32 = Int256(int32) // creates Int256 instance wrapping BigInteger which is created from Int32 / Int value
val int64: Int64=64val int256FromInt64 = Int256(int64) // creates Int256 instance wrapping BigInteger which is created from Int64 / Long value
All of 128, 256, 512 unsigned and signed types allows you to instantiate object by providing any respectively unsigned or signed integers of lesser size, including BigInteger wrapping ones.