0.0.5 โข Published 3 years ago
@thebehera/buffer-kt v0.0.5
About The Project
Allocating and managing a chunk of memory can be slightly different based on each platform. This project aims to make it easier to manage buffers in a cross platform way using kotlin multiplatform. This was originally created as a side project for a kotlin multiplatform mqtt data sync solution.
Implementation notes:
JVM
+Android
delegate to direct ByteBuffers to avoid memory copies when possible.Native
platforms use standard byte arrays to manage memory.JS
targets use Uint8Array.
Runtime Dependencies
- None
Supported Platforms
Platform | ๐ Builds๐ + ๐ฌTests๐ฌ | Deployed Artifact | Non Kotlin Sample |
---|---|---|---|
JVM 1.8 | ๐ | maven central ๐ฎ | ๐ฎ |
Node.js | ๐ | npm ๐ฎ | ๐ฎ |
Browser (Chrome) | ๐ | npm ๐ฎ | ๐ฎ |
Android | ๐ | maven central ๐ฎ | ๐ฎ |
iOS | ๐ | cocoapods ๐ฎ | ๐ฎ |
WatchOS | ๐ | cocoapods ๐ฎ | ๐ฎ |
TvOS | ๐ | cocoapods ๐ฎ | ๐ฎ |
MacOS | ๐ | cocoapods ๐ฎ | ๐ฎ |
Linux X64 | ๐ | apt/yum ๐ฎ | ๐ฎ |
Windows X64 | ๐ | chocolatey ๐ฎ | ๐ฎ |
Installation
- TODO: Add explanation after artifacts are deployed
Usage
Allocate a new platform agnostic buffer
val buffer = allocateNewBuffer(byteSize)
Write big endian data into platform agnostic buffer
val buffer :WriteBuffer
// write signed byte
buffer.write(5.toByte())
// write unsigned byte
buffer.write(5.toUByte())
// write unsigned short
buffer.write(5.toUShort())
// write unsigned int
buffer.write(5.toUInt())
// write long
buffer.write(5L)
// write float
buffer.write(123.456f)
// write double
buffer.write(123.456)
// write text
buffer.write("5")
// copy buffer into this one
buffer.write(otherBuffer)
// write byte array
buffer.write(byteArrayOf(1,2,3,4))
// write partial byte array
buffer.write(byteArrayOf(1,2,3,4,5), offset, length)
Read big endian data into platform agnostic buffer
val buffer :ReadBuffer
// read signed byte
buffer.readByte()
// read unsigned byte
buffer.readUnsignedByte()
// read unsigned short
buffer.readUnsignedShort()
// read unsigned int
buffer.readUnsignedInt()
// read long
buffer.readLong()
// read float
buffer.readFloat()
// read double
buffer.readDouble()
// read text
buffer.readUtf8(numOfBytesToRead)
// read byte array
buffer.readByteArray(numOfBytesToRead)
Building Locally
git clone git@github.com:DitchOoM/buffer.git
- Open cloned directory with Intellij IDEA.
- Be sure to open with gradle
Roadmap
See the open issues for a list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the Apache 2.0 License. See LICENSE
for more information.