0.0.5 โ€ข Published 3 years ago

@thebehera/buffer-kt v0.0.5

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Contributors Forks Stargazers Issues MIT License LinkedIn

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 ArtifactNon 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

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago