
Byte-array manipulation utility offering wrapping, indexed put/get, little-endian integer read/write, buffer-style operations, and simple extraction of the underlying byte array.
Kotlin向けバイト配列操作ライブラリ
依存を追加します
dependencies {
implementation "jp.co.gahojin.bytes-kotlin:bytes-kotlin:${latest.version}"
}val b = Bytes.wrap(someByteArray)
b.put(0, 0x01)
b.putIntLe(1, 12345)
val result = b.array()Bytes クラスは ByteArray のラッパーで、ビット操作やエンディアン変換などの便利なメソッドを提供します。
Bytes.wrap(array) や Bytes.array() は内部配列を直接参照します。大規模なデータ操作においてコピーのオーバーヘッドを避け、高いパフォーマンスを実現します。Bytes クラスのメソッド(putInt 等)は、ラップしている内部配列を直接書き換えます。Byte の符号拡張を適切に処理しており、負の値を含むバイト配列でも正しく数値の読み書きが可能です。// アロケート
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() // 内部配列への参照を返す(変更はbに反映される)Copyright 2025, GAHOJIN, Inc.
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.
Kotlin向けバイト配列操作ライブラリ
依存を追加します
dependencies {
implementation "jp.co.gahojin.bytes-kotlin:bytes-kotlin:${latest.version}"
}val b = Bytes.wrap(someByteArray)
b.put(0, 0x01)
b.putIntLe(1, 12345)
val result = b.array()Bytes クラスは ByteArray のラッパーで、ビット操作やエンディアン変換などの便利なメソッドを提供します。
Bytes.wrap(array) や Bytes.array() は内部配列を直接参照します。大規模なデータ操作においてコピーのオーバーヘッドを避け、高いパフォーマンスを実現します。Bytes クラスのメソッド(putInt 等)は、ラップしている内部配列を直接書き換えます。Byte の符号拡張を適切に処理しており、負の値を含むバイト配列でも正しく数値の読み書きが可能です。// アロケート
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() // 内部配列への参照を返す(変更はbに反映される)Copyright 2025, GAHOJIN, Inc.
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.