bytebuffer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/pages.yml +40 -0
- data/.github/workflows/publish.yml +88 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +70 -0
- data/LICENSE +28 -0
- data/README.md +26 -0
- data/Rakefile +90 -0
- data/bytebuffer.gemspec +23 -0
- data/ext/Cargo.lock +25 -0
- data/ext/Cargo.toml +10 -0
- data/ext/Makefile +57 -0
- data/ext/extconf.rb +1 -0
- data/ext/src/lib.rs +739 -0
- data/lib/bytebuffer/version.rb +5 -0
- data/lib/bytebuffer.rb +218 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 20a3822e4f7dd0a4162f60b834648acc30a1b33a3c7839c0434a084bf4a88ec8
|
4
|
+
data.tar.gz: c685d79e7d93d6c0df12c7ab55f55a37a98251ae4d416e6cc76b015ab8fc0a05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7f1a3cba5fcaba77cb5b975cd7a14cd690e73c5c719a9d59c3ef7d03278cb5d4880a1050240a513fe8b4e199d4c8995228a6645bd87a350ebe49bd0c5c39127
|
7
|
+
data.tar.gz: d9c2033f9009139988b7e3131afe37e393f0b48fddf7f132c24bb6aeac5fc3bb3ea74cb89c58da5e4774e5a73fe288261391be84ef5ef357afc9666485536cd4
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
name: YARD to GitHub Pages
|
3
|
+
|
4
|
+
on:
|
5
|
+
workflow_dispatch:
|
6
|
+
release:
|
7
|
+
types: [released]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
id-token: write
|
11
|
+
contents: read
|
12
|
+
pages: write
|
13
|
+
|
14
|
+
jobs:
|
15
|
+
BuildAndPublish:
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
|
20
|
+
- name: Setup Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: '3.3'
|
24
|
+
bundler-cache: true
|
25
|
+
|
26
|
+
- name: Build YARD Docs
|
27
|
+
run: bundler exec rake docs:generate
|
28
|
+
|
29
|
+
- name: Upload pages artifact
|
30
|
+
id: upload-artifact
|
31
|
+
uses: actions/upload-pages-artifact@v3
|
32
|
+
with:
|
33
|
+
name: "yard-docs"
|
34
|
+
path: ./doc/
|
35
|
+
retention-days: "7"
|
36
|
+
|
37
|
+
- name: Deploy pages artifact
|
38
|
+
uses: actions/deploy-pages@v4
|
39
|
+
with:
|
40
|
+
artifact_name: "yard-docs"
|
@@ -0,0 +1,88 @@
|
|
1
|
+
---
|
2
|
+
name: Publish Gem
|
3
|
+
|
4
|
+
on:
|
5
|
+
workflow_dispatch:
|
6
|
+
release:
|
7
|
+
types: [released]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
Build:
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
15
|
+
include:
|
16
|
+
- os: windows-latest
|
17
|
+
name: windows
|
18
|
+
path: "ext/libext.dll"
|
19
|
+
- os: ubuntu-latest
|
20
|
+
name: linux
|
21
|
+
path: "ext/libext.so"
|
22
|
+
- os: macos-latest
|
23
|
+
name: macos
|
24
|
+
path: "ext/libext.dylib"
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v4
|
27
|
+
|
28
|
+
- name: Setup Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: '3.3'
|
32
|
+
bundler-cache: true
|
33
|
+
|
34
|
+
- name: Setup Rust
|
35
|
+
uses: hecrj/setup-rust-action@v2
|
36
|
+
with:
|
37
|
+
rust-version: stable
|
38
|
+
|
39
|
+
- name: Build extension
|
40
|
+
run: bundle exec rake gem:build
|
41
|
+
|
42
|
+
- name: Upload artifact
|
43
|
+
uses: actions/upload-artifact@v4
|
44
|
+
with:
|
45
|
+
name: extension-${{ matrix.name }}
|
46
|
+
path: ${{ matrix.path }}
|
47
|
+
|
48
|
+
Publish:
|
49
|
+
runs-on: ubuntu-latest
|
50
|
+
needs: [Build]
|
51
|
+
permissions:
|
52
|
+
id-token: write
|
53
|
+
contents: write
|
54
|
+
steps:
|
55
|
+
- name: Checkout
|
56
|
+
uses: actions/checkout@v4
|
57
|
+
|
58
|
+
- name: Setup Ruby
|
59
|
+
uses: ruby/setup-ruby@v1
|
60
|
+
with:
|
61
|
+
ruby-version: '3.3'
|
62
|
+
bundler-cache: true
|
63
|
+
|
64
|
+
- name: Setup Rust
|
65
|
+
uses: hecrj/setup-rust-action@v2
|
66
|
+
with:
|
67
|
+
rust-version: stable
|
68
|
+
|
69
|
+
- name: Download build linux artifacts
|
70
|
+
uses: actions/download-artifact@v4
|
71
|
+
with:
|
72
|
+
name: extension-linux
|
73
|
+
path: ext/libext.so
|
74
|
+
|
75
|
+
- name: Download build windows artifacts
|
76
|
+
uses: actions/download-artifact@v4
|
77
|
+
with:
|
78
|
+
name: extension-windows
|
79
|
+
path: ext/libext.dll
|
80
|
+
|
81
|
+
- name: Download build macos artifacts
|
82
|
+
uses: actions/download-artifact@v4
|
83
|
+
with:
|
84
|
+
name: extension-macos
|
85
|
+
path: ext/libext.dylib
|
86
|
+
|
87
|
+
- name: Publish Gem
|
88
|
+
uses: rubygems/release-gem@v1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bytebuffer (0.1.0)
|
5
|
+
ffi (~> 1.17)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://www.rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.5.1)
|
11
|
+
docile (1.4.0)
|
12
|
+
ffi (1.17.0)
|
13
|
+
ffi (1.17.0-aarch64-linux-gnu)
|
14
|
+
ffi (1.17.0-aarch64-linux-musl)
|
15
|
+
ffi (1.17.0-arm-linux-gnu)
|
16
|
+
ffi (1.17.0-arm-linux-musl)
|
17
|
+
ffi (1.17.0-arm64-darwin)
|
18
|
+
ffi (1.17.0-x86-linux-gnu)
|
19
|
+
ffi (1.17.0-x86-linux-musl)
|
20
|
+
ffi (1.17.0-x86_64-darwin)
|
21
|
+
ffi (1.17.0-x86_64-linux-gnu)
|
22
|
+
ffi (1.17.0-x86_64-linux-musl)
|
23
|
+
gem-release (2.2.2)
|
24
|
+
rake (13.2.1)
|
25
|
+
rspec (3.13.0)
|
26
|
+
rspec-core (~> 3.13.0)
|
27
|
+
rspec-expectations (~> 3.13.0)
|
28
|
+
rspec-mocks (~> 3.13.0)
|
29
|
+
rspec-core (3.13.0)
|
30
|
+
rspec-support (~> 3.13.0)
|
31
|
+
rspec-expectations (3.13.1)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.13.0)
|
34
|
+
rspec-mocks (3.13.1)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.13.0)
|
37
|
+
rspec-support (3.13.1)
|
38
|
+
simplecov (0.22.0)
|
39
|
+
docile (~> 1.1)
|
40
|
+
simplecov-html (~> 0.11)
|
41
|
+
simplecov_json_formatter (~> 0.1)
|
42
|
+
simplecov-html (0.12.3)
|
43
|
+
simplecov_json_formatter (0.1.4)
|
44
|
+
webrick (1.8.1)
|
45
|
+
yard (0.9.36)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
aarch64-linux-gnu
|
49
|
+
aarch64-linux-musl
|
50
|
+
arm-linux-gnu
|
51
|
+
arm-linux-musl
|
52
|
+
arm64-darwin
|
53
|
+
ruby
|
54
|
+
x86-linux-gnu
|
55
|
+
x86-linux-musl
|
56
|
+
x86_64-darwin
|
57
|
+
x86_64-linux-gnu
|
58
|
+
x86_64-linux-musl
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bytebuffer!
|
62
|
+
gem-release
|
63
|
+
rake (~> 13.0)
|
64
|
+
rspec (~> 3.12)
|
65
|
+
simplecov
|
66
|
+
webrick (~> 1.7)
|
67
|
+
yard (~> 0.9)
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
2.5.3
|
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2024, Patrick Worlds
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
13
|
+
and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
16
|
+
contributors may be used to endorse or promote products derived from
|
17
|
+
this software without specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# ByteBuffer
|
2
|
+
The `ByteBuffer` Ruby gem provides a powerful and flexible interface for buffered IO data, wrapping the [bytebuffer](https://crates.io/crates/bytebuffer) crate using FFI.
|
3
|
+
|
4
|
+
## Overview
|
5
|
+
ByteBuffer offers an interface to the compiled rust library for manipulating buffered IO, e.g. reading and writing bits, bytes, integers of various sizes, and floats.
|
6
|
+
## Getting Started
|
7
|
+
#### Dependencies
|
8
|
+
The following packages are required to build and use the gem:
|
9
|
+
* `ruby` >= 3.0
|
10
|
+
* `rustc`
|
11
|
+
* `cargo`
|
12
|
+
|
13
|
+
Ensure the following toolchains are installed via rustup:
|
14
|
+
* `x86_64-unknown-linux-gnu`
|
15
|
+
*
|
16
|
+
|
17
|
+
#### Usage
|
18
|
+
A basic example of the ByteBuffer in action can be found below:
|
19
|
+
```ruby
|
20
|
+
require 'bytebuffer'
|
21
|
+
|
22
|
+
bb = ByteBuffer.new
|
23
|
+
bb.write_i32(-128)
|
24
|
+
puts bb.read_i32 # Output: -128
|
25
|
+
bb.free
|
26
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'ffi'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubygems/package_task'
|
9
|
+
|
10
|
+
namespace :gem do
|
11
|
+
desc 'Build the Gem extensions'
|
12
|
+
task :build do
|
13
|
+
raise "Install rustc along with Cargo before running this rake task." if !system('cargo --version') || !system('rustc --version')
|
14
|
+
|
15
|
+
FileUtils.chdir("ext/") do
|
16
|
+
target = case RUBY_PLATFORM
|
17
|
+
when /darwin/ then 'aarch64-apple-darwin'
|
18
|
+
when /linux/ then 'x86_64-unknown-linux-gnu'
|
19
|
+
when /mswin|mingw/ then 'x86_64-pc-windows-msvc'
|
20
|
+
else 'x86_64-unknown-linux-gnu'
|
21
|
+
end
|
22
|
+
|
23
|
+
target_path = "./build/#{target}/release/#{RUBY_PLATFORM.match?(/mswin|mingw/) ? 'ext' : 'libext'}.#{FFI::Platform::LIBSUFFIX}"
|
24
|
+
|
25
|
+
FileUtils.mkdir("build")
|
26
|
+
|
27
|
+
system("cargo build --release --target=#{target} --target-dir=#{FileUtils.pwd}/build")
|
28
|
+
|
29
|
+
FileUtils.cp(target_path, "./libext.#{FFI::Platform::LIBSUFFIX}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Clean up the Gem build environment.'
|
34
|
+
task :clean do
|
35
|
+
FileUtils.rm_rf('pkg/')
|
36
|
+
FileUtils.rm_rf('ext/build/')
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Package the Gem package'
|
40
|
+
task :package do
|
41
|
+
load('bytebuffer.gemspec')
|
42
|
+
|
43
|
+
Gem::PackageTask.new(GEM_SPEC) do |pkg|
|
44
|
+
pkg.need_tar_bz2 = true
|
45
|
+
end
|
46
|
+
|
47
|
+
Rake::Task['package'].invoke
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
namespace :docs do
|
52
|
+
require 'yard'
|
53
|
+
|
54
|
+
YARD::Rake::YardocTask.new do |t|
|
55
|
+
t.name = 'generate'
|
56
|
+
t.files = ['lib/**/*.rb']
|
57
|
+
end
|
58
|
+
|
59
|
+
task serve: %i[docs:generate] do
|
60
|
+
Kernel.system('yard server')
|
61
|
+
end
|
62
|
+
|
63
|
+
task :clean do
|
64
|
+
require 'fileutils'
|
65
|
+
|
66
|
+
FileUtils.rm_rf('doc')
|
67
|
+
FileUtils.rm_rf('.yardoc')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
namespace :test do
|
73
|
+
desc 'Runs all specs in the "spec/" folder using RSpec.'
|
74
|
+
RSpec::Core::RakeTask.new(:rspec)
|
75
|
+
|
76
|
+
task :clean do
|
77
|
+
require 'fileutils'
|
78
|
+
|
79
|
+
FileUtils.rm_rf('coverage')
|
80
|
+
end
|
81
|
+
|
82
|
+
desc 'Runs extension tests using cargo test.'
|
83
|
+
task :ext do
|
84
|
+
raise "Install rustc along with Cargo before running this rake task." if !system('cargo --version') || !system('rustc --version')
|
85
|
+
|
86
|
+
FileUtils.chdir("ext/") do
|
87
|
+
system("cargo test")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/bytebuffer.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'lib/bytebuffer/version'
|
2
|
+
|
3
|
+
GEM_SPEC = Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'bytebuffer'
|
5
|
+
spec.version = ByteBuffer::VERSION
|
6
|
+
spec.summary = 'A gem wrapping the bytebuffer crate using FFI.'
|
7
|
+
spec.description = 'A gem that provides a ByteBuffer class based on the bytebuffer rust crate.'
|
8
|
+
spec.license = 'BSD-3-Clause'
|
9
|
+
spec.author = 'Patrick W.'
|
10
|
+
spec.email = 'Sickday@pm.me'
|
11
|
+
|
12
|
+
spec.required_ruby_version = '>= 3.1.0'
|
13
|
+
|
14
|
+
spec.add_runtime_dependency 'ffi', '~> 1.17'
|
15
|
+
|
16
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
17
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
18
|
+
|
19
|
+
spec.extensions = "ext/extconf.rb"
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
data/ext/Cargo.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
2
|
+
# It is not intended for manual editing.
|
3
|
+
version = 3
|
4
|
+
|
5
|
+
[[package]]
|
6
|
+
name = "bytebuffer"
|
7
|
+
version = "2.2.0"
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
+
checksum = "fa7bfaf7cd08cacd74cdc6b521c37ac39cbc92692e5ab5c21ed5657a749b577c"
|
10
|
+
dependencies = [
|
11
|
+
"byteorder",
|
12
|
+
]
|
13
|
+
|
14
|
+
[[package]]
|
15
|
+
name = "byteorder"
|
16
|
+
version = "1.5.0"
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
19
|
+
|
20
|
+
[[package]]
|
21
|
+
name = "ext"
|
22
|
+
version = "0.1.0"
|
23
|
+
dependencies = [
|
24
|
+
"bytebuffer",
|
25
|
+
]
|
data/ext/Cargo.toml
ADDED
data/ext/Makefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
ifeq '$(findstring ;,$(PATH))' ';'
|
2
|
+
OS := Windows
|
3
|
+
else
|
4
|
+
OS := $(shell uname 2>/dev/null || echo Unknown)
|
5
|
+
OS := $(patsubst CYGWIN%,Cygwin,$(OS))
|
6
|
+
OS := $(patsubst MSYS%,MSYS,$(OS))
|
7
|
+
OS := $(patsubst MINGW%,MSYS,$(OS))
|
8
|
+
endif
|
9
|
+
|
10
|
+
|
11
|
+
ifeq ($(OS),Windows)
|
12
|
+
SUFFIX := dll
|
13
|
+
TARGET := x86_64-pc-windows-msvc
|
14
|
+
endif
|
15
|
+
ifeq ($(OS),Darwin)
|
16
|
+
SUFFIX := dylib
|
17
|
+
TARGET := aarch64-apple-darwin
|
18
|
+
endif
|
19
|
+
ifeq ($(OS),Linux)
|
20
|
+
SUFFIX := so
|
21
|
+
TARGET := x86_64-unknown-linux-gnu
|
22
|
+
endif
|
23
|
+
ifeq ($(OS),GNU)
|
24
|
+
SUFFIX := so
|
25
|
+
TARGET := x86_64-unknown-linux-gnu
|
26
|
+
endif
|
27
|
+
|
28
|
+
|
29
|
+
all:
|
30
|
+
mkdir build
|
31
|
+
echo "Outputting to $PWD /build/$(TARGET)"
|
32
|
+
cargo build --release --target=$(TARGET) --target-dir=./build
|
33
|
+
|
34
|
+
clean:
|
35
|
+
rm -rf target
|
36
|
+
|
37
|
+
install:
|
38
|
+
cp target/$(TARGET)/release/libext.$(SUFFIX) ./
|
39
|
+
|
40
|
+
test:
|
41
|
+
cargo test
|
42
|
+
|
43
|
+
build-macos-amd64:
|
44
|
+
cargo build --release --target=x86_64-apple-darwin
|
45
|
+
cp target/x86_64-apple-darwin/release/libext.dylib ./
|
46
|
+
|
47
|
+
build-macos-aarch:
|
48
|
+
cargo build --release --target=aarch64-apple-darwin
|
49
|
+
cp target/aarch64-apple-darwin/release/libext.dylib ./
|
50
|
+
|
51
|
+
build-linux:
|
52
|
+
cargo build --release --target=x86_64-unknown-linux-gnu
|
53
|
+
cp target/x86_64-unknown-linux-gnu/release/libext.so ./
|
54
|
+
|
55
|
+
build-windows:
|
56
|
+
cargo build --release --target=x86_64-pc-windows-msvc
|
57
|
+
cp target/x86_64-pc-windows-msvc/release/libext.dll ./
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
raise 'Install Rust with Cargo from https://www.rust-lang.org/ before installing this gem.' if !system('cargo --version') || !system('rustc --version')
|