picopack 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dd7f2d8174a485b27b4db6798fae2fbd3162055b9d7af513fee9ea610705a729
4
+ data.tar.gz: d0af47d504728b4eb82bb2eaa7f24405c3a499c6289a8d05d3bb750e545b8b92
5
+ SHA512:
6
+ metadata.gz: d9503692254ea53c0045d990d67e9b8c4d77cb8c8401151aef219c382cb32543a7216178bfa3718a32834091d663b212b05c3ea8e23d75bdcb2da94aab98e422
7
+ data.tar.gz: d6f0fa8a091a99a434db967ca3ddd36651469a0bbabdd2061470138d78027090f48d41fc4de0b00bb661d7ab2aeff5a7225e3711a3d16575ff73ad6059a962ef
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-12-04
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Hartley McGuire
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Picopack
2
+
3
+ Pure Ruby MessagePack
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add picopack
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by
14
+ executing:
15
+
16
+ ```bash
17
+ gem install picopack
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
27
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
28
+ prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To
31
+ release a new version, update the version number in `version.rb`, and then run
32
+ `bundle exec rake release`, which will create a git tag for the version, push
33
+ git commits and the created tag, and push the `.gem` file to
34
+ [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at
39
+ https://github.com/skipkayhil/picopack.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT
44
+ License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "megatest/test_task"
5
+
6
+ Megatest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
data/bench/ar.rb ADDED
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "picopack"
6
+ require "active_record"
7
+ require "paquito"
8
+ require "benchmark/ips"
9
+ require "vernier"
10
+
11
+ # Set up an in-memory SQLite database with a table that mirrors a typical
12
+ # Active Record model — 39 columns with a mix of types and many nils.
13
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
14
+
15
+ ActiveRecord::Schema.define do
16
+ create_table :records do |t|
17
+ t.string(:string1)
18
+ t.string(:string2)
19
+ t.text(:text1)
20
+ t.string(:string3)
21
+ t.string(:string4)
22
+ t.string(:string5)
23
+ t.string(:string6)
24
+ t.string(:string7)
25
+ t.string(:string8)
26
+ t.boolean(:boolean1)
27
+ t.integer(:integer1)
28
+ t.string(:string9)
29
+ t.string(:string10)
30
+ t.string(:string11)
31
+ t.float(:float1)
32
+ t.float(:float2)
33
+ t.string(:string12)
34
+ t.integer(:integer2)
35
+ t.string(:string13)
36
+
37
+ t.string(:string14)
38
+ t.integer(:integer3)
39
+ t.boolean(:boolean2)
40
+ t.boolean(:boolean3)
41
+ t.string(:string15)
42
+ t.string(:string16)
43
+ # t.datetime(:datetime1)
44
+ t.string(:string17)
45
+ t.string(:string18)
46
+ t.string(:string19)
47
+ t.boolean(:boolean4)
48
+ t.string(:string20)
49
+ # t.datetime(:created_at)
50
+ # t.datetime(:updated_at)
51
+ t.string(:string21)
52
+ t.string(:string22)
53
+ t.integer(:integer4)
54
+ t.string(:string23)
55
+ t.integer(:integer5)
56
+ end
57
+ end
58
+
59
+ class Record < ActiveRecord::Base
60
+ end
61
+
62
+ TEXT_BLOB = <<~TEXT
63
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
64
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
65
+ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
66
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
67
+ eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
68
+ in culpa qui officia deserunt mollit anim id est laborum.
69
+ TEXT
70
+
71
+ # now = Time.utc(2026, 3, 4, 18, 49, 17)
72
+
73
+ record = Record.create!(
74
+ string1: "short1",
75
+ string2: "medium_string@test",
76
+ text1: TEXT_BLOB,
77
+ string3: "medium.string.value",
78
+ string4: "medium12",
79
+ string5: "AB",
80
+ string6: "a medium string!",
81
+ string7: "ABC 123",
82
+ string8: "medstr01",
83
+ boolean1: nil,
84
+ integer1: 360283,
85
+ string9: nil,
86
+ string10: "5551234567",
87
+ string11: nil,
88
+ float1: nil,
89
+ float2: nil,
90
+ string12: "medium.string.value",
91
+ integer2: 1000001,
92
+ string13: "a_medium_string_val",
93
+ string14: "another_val",
94
+ integer3: 1,
95
+ boolean2: false,
96
+ boolean3: false,
97
+ string15: "en",
98
+ string16: "a" * 64,
99
+ # datetime1: nil,
100
+ string17: "a_slightly_longer_string",
101
+ string18: nil,
102
+ string19: nil,
103
+ boolean4: false,
104
+ string20: nil,
105
+ # created_at: now,
106
+ # updated_at: now,
107
+ string21: nil,
108
+ string22: nil,
109
+ integer4: 1,
110
+ string23: nil,
111
+ integer5: 1
112
+ )
113
+
114
+ codec = Paquito::Types::ActiveRecordPacker
115
+ bytes = codec.dump(record).freeze
116
+ factory = codec::FACTORY
117
+
118
+ # Sanity check
119
+ factory.load(bytes).tap do |restored|
120
+ pico = Picopack.load(bytes)
121
+
122
+ unless restored == pico
123
+ # binding.irb
124
+ raise "Round-trip failed!"
125
+ end
126
+ end
127
+
128
+ stage = ENV.fetch("STAGE", "after")
129
+
130
+ puts "=== dump ==="
131
+ Benchmark.ips do |x|
132
+ x.save!("/tmp/paquito-bench-active-record-dump.json")
133
+ x.report("dump (#{stage})") { codec.dump(record) }
134
+ x.compare!(order: :baseline)
135
+ end
136
+
137
+ puts
138
+ puts "=== load ==="
139
+ Benchmark.ips do |x|
140
+ x.save!("/tmp/paquito-bench-active-record-load.json")
141
+ x.report("msgpack load (#{stage})") { factory.load(bytes) }
142
+ x.report("picopack load (#{stage})") { Picopack.load(bytes) }
143
+ x.compare!(order: :baseline)
144
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Picopack
4
+ VERSION = "0.1.0"
5
+ end
data/lib/picopack.rb ADDED
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "picopack/version"
4
+
5
+ module Picopack
6
+ class Parser
7
+ def initialize(buffer)
8
+ @buffer = buffer
9
+ @cursor = 0
10
+ end
11
+
12
+ def read
13
+ byte = read_byte
14
+
15
+ case byte
16
+ when 0xc0 then nil
17
+ when 0xc2 then false
18
+ when 0xc3 then true
19
+ # fixstr
20
+ when 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
21
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf
22
+
23
+ len = byte & 31
24
+
25
+ str = @buffer.byteslice(@cursor, len)
26
+ @cursor += len
27
+ str
28
+ # fixmap
29
+ when 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f
30
+ len = byte & 15
31
+ i = 0
32
+ map = Hash.new(capacity: len)
33
+
34
+ while i < len
35
+ map[read] = read
36
+
37
+ i += 1
38
+ end
39
+
40
+ map
41
+ # fixarray
42
+ when 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
43
+ len = byte & 15
44
+ i = 0
45
+ array = Array.new(len)
46
+
47
+ while i < len
48
+ array[i] = read
49
+
50
+ i += 1
51
+ end
52
+
53
+ array
54
+ # uint 16
55
+ when 0xcd
56
+ (read_byte << 8) + read_byte
57
+ # uint 32
58
+ when 0xce
59
+ (((((read_byte << 8) + read_byte) << 8) + read_byte) << 8) + read_byte
60
+ # str 8
61
+ when 0xd9
62
+ len = read_byte
63
+
64
+ str = @buffer.byteslice(@cursor, len)
65
+ @cursor += len
66
+ str
67
+ # str 16
68
+ when 0xda
69
+ len = (read_byte << 8) + read_byte
70
+
71
+ str = @buffer.byteslice(@cursor, len)
72
+ @cursor += len
73
+ str
74
+ # map 16
75
+ when 0xde
76
+ len = (read_byte << 8) + read_byte
77
+ i = 0
78
+ map = Hash.new(capacity: len)
79
+
80
+ while i < len
81
+ map[read] = read
82
+
83
+ i += 1
84
+ end
85
+
86
+ map
87
+ else
88
+ # only literals above for opt_case_dispatch
89
+
90
+ # positive fixint
91
+ if byte <= 0x7f
92
+ byte & 127
93
+ else
94
+ # TODO: once all the other bytes are covered, this else will only be
95
+ # negative fixint
96
+ raise "Unimplemented type: 0x#{byte.to_s(16)}"
97
+ end
98
+ end
99
+ end
100
+
101
+ def read_byte
102
+ b = @buffer.getbyte(@cursor)
103
+ @cursor += 1
104
+ b
105
+ end
106
+ end
107
+
108
+ module_function
109
+
110
+ def load(buffer)
111
+ Parser.new(buffer).read
112
+ end
113
+ end
data/sig/picopack.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Picopack
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picopack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hartley McGuire
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - skipkayhil@gmail.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - CHANGELOG.md
19
+ - LICENSE.txt
20
+ - README.md
21
+ - Rakefile
22
+ - bench/ar.rb
23
+ - lib/picopack.rb
24
+ - lib/picopack/version.rb
25
+ - sig/picopack.rbs
26
+ homepage: https://github.com/skipkayhil/picopack
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ homepage_uri: https://github.com/skipkayhil/picopack
31
+ source_code_uri: https://github.com/skipkayhil/picopack
32
+ changelog_uri: https://github.com/skipkayhil/picopack/blob/main/CHANGELOG.md
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 4.0.20
48
+ specification_version: 4
49
+ summary: Pure Ruby MessagePack
50
+ test_files: []