Bytes Utility Library for Kotlin
Kotlin向けバイト配列操作ライブラリ

Get Started
Gradle
依存を追加します
${latest.version} is 
dependencies {
implementation "jp.co.gahojin.bytes-kotlin:bytes-kotlin:${latest.version}"
}
Examples
val b = Bytes.wrap(someByteArray)
b.put(0, 0x01)
b.putIntLe(1, 12345)
val result = b.array()
API
Bytes
Bytes クラスは ByteArray のラッパーで、ビット操作やエンディアン変換などの便利なメソッドを提供します。
パフォーマンスと設計方針
- ゼロコピー:
Bytes.wrap(array) や Bytes.array() は内部配列を直接参照します。大規模なデータ操作においてコピーのオーバーヘッドを避け、高いパフォーマンスを実現します。
- ミュータブル:
Bytes クラスのメソッド(putInt 等)は、ラップしている内部配列を直接書き換えます。
インスタンスの生成
val b1 = Bytes.allocate(10)
val b3 = Bytes.wrap(byteArrayOf(0x01, 0x02))
val b4 = Bytes.from(0x01.toByte(), 0x02.toByte())
基本操作
val b = Bytes.allocate(4)
b.putInt(0, 12345678)
val i = b.getInt(0)
val hex = b.toHexString()
配列へのアクセス
val b = Bytes.allocate(4)
val ref = b.array()
License
Copyright 2025, GAHOJIN, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
https:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.