Hikari Buffer
A fast, lightweight binary buffer for Ruby built as a native C extension. Hikari Buffer provides efficient serialization and deserialization of primitive data types, strings, and raw bytes through a clean, chainable API.
Features
- ๐ Native C extension for maximum performance
- ๐ฆ Binary serialization and deserialization
- ๐ข Signed integers (
i8,i16,i32,i64) - ๐ข Unsigned integers (
u8,u16,u32,u64) - ๐ Floating-point numbers (
f32,f64) - โ Boolean support
- ๐ UTF-8 string serialization
- ๐ Raw byte serialization
- ๐ฏ Cursor-based reading and writing
- ๐ Automatic buffer growth
- ๐งช Comprehensive RSpec test suite
Installation
RubyGems
gem install hikari_buffer
Bundler
gem "hikari_buffer"
Quick Start
require "hikari_buffer"
buffer = Hikari::Buffer.new
buffer
.write_u32(42)
.write_bool(true)
.write_f64(Math::PI)
.write_string("Hello, Hikari!")
buffer.rewind
puts buffer.read_u32
puts buffer.read_bool
puts buffer.read_f64
puts buffer.read_string
Supported Types
| Type | Read | Write |
|---|---|---|
| u8 | โ | โ |
| u16 | โ | โ |
| u32 | โ | โ |
| u64 | โ | โ |
| i8 | โ | โ |
| i16 | โ | โ |
| i32 | โ | โ |
| i64 | โ | โ |
| f32 | โ | โ |
| f64 | โ | โ |
| bool | โ | โ |
| bytes | โ | โ |
| string | โ | โ |
Buffer API
buffer.capacity
buffer.size
buffer.cursor
buffer.tell
buffer.remaining
buffer.seek(position)
buffer.rewind
buffer.clear
Development
Clone the repository and install dependencies:
git clone https://github.com/AntarMukhopadhyaya/hikari-buffer.git
cd hikari-buffer
bundle install
Compile the native extension:
bundle exec rake compile
Run the test suite:
bundle exec rspec
Run RuboCop:
bundle exec rubocop
Roadmap
- [x] Primitive integer serialization
- [x] Floating-point serialization
- [x] Boolean serialization
- [x] String serialization
- [x] Raw byte serialization
- [x] Automatic buffer growth
- [ ] Peek operations
- [ ] Endianness support
- [ ] Array serialization
- [ ] UUID serialization
- [ ] Benchmarks
- [ ] Precompiled native gems for Windows, Linux, and macOS
Contributing
Bug reports, feature requests, and pull requests are welcome.
If you'd like to contribute:
- Fork the repository
- Create a feature branch
- Add tests for your changes
- Ensure all tests pass
- Open a Pull Request
License
Released under the MIT License. See the LICENSE file for details.