@datkt/bytes-from
v1.0.4
Published
Convert various arguments into a ByteArray
Downloads
21
Readme
bytes-from
Convert various arguments into a ByteArray.
This package is part of the datkt.bytes
package.
Installation
$ npm install @datkt/bytes-from
Usage
import datkt.bytes.bytesFrom
fun main(args: Array<String>) {
run { val bytes = bytesFrom(0xa, 0xb, 0xc, 0xd) } // or
run { val bytes = bytesFrom(arrayOf(0xa, 0xb, 0xc, 0xd)) } // or
run { val bytes = bytesFrom("hello") } // or
run { val bytes = bytesFrom(32) }
}
API
bytesFrom(vararg bytes: Number): ByteArray
Converts a variadic array of Number
to a ByteArray
val bytes = bytesFrom(0xfe, 0xed, 0xbe, 0xef)
val bytes = bytesFrom(*arrayOf(0xfe, 0xed, 0xbe, 0xef))
bytesFrom(bytes: ByteArray): ByteArray
Converts a ByteArray
to a new ByteArray
val bytes = bytesFrom(bytesFrom(0xfe, 0xed, 0xbe, 0xef))
bytesFrom(bytes: Array<out Number>): ByteArray
Converts an Array
of Number
to a ByteArray
val bytes = bytesFrom(arrayOf(0xfe, 0xed, 0xbe, 0xef))
bytesFrom(bytes: String): ByteArray
Converts a String
to a ByteArray
val bytes = bytesFrom("feedbeef")
bytesFrom(size: Number): ByteArray
Converts a Number
to a ByteArray
val bytes = bytesFrom(16)
bytesFrom(size: Char): ByteArray
Converts a Char
to a ByteArray
val bytes = bytesFrom('a')
bytesFrom(bytes: Any? = null): ByteArray
Converts an Any?
to an empty ByteArray
val bytes = bytesFrom()
val bytes = bytesFrom(null)
val bytes = bytesFrom(fun() { })
val bytes = bytesFrom(true)
Prerequisites
- Kotlin/Native and the
konanc
command line program.
See Also
- https://github.com/datkt/bytes
- https://github.com/LinusU/buffer-from#readme
License
MIT