Hikari Buffer

Ruby License: MIT

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:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for your changes
  4. Ensure all tests pass
  5. Open a Pull Request

License

Released under the MIT License. See the LICENSE file for details.