pbwire 0.1.1

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.
data/lib/pbwire.rb ADDED
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # pbwire Ruby binding: a compiled extension over the C core, no gems.
4
+ #
5
+ # A FileDescriptorSet (`protoc --descriptor_set_out`) is the schema; messages
6
+ # are built and read by field name or number and go to/from wire bytes with no
7
+ # generated code. Every pbw_status is checked and turned into Pbwire::Error.
8
+ #
9
+ # schema = Pbwire::Schema.from_file("sample.desc")
10
+ # msg = schema.message("pbwire.ruby.Sample")
11
+ # msg["name"] = "alice"
12
+ # wire = msg.encode
13
+ # schema.message("pbwire.ruby.Sample").decode(wire)["name"] # => "alice"
14
+ #
15
+ # Build it with build.sh (or `make ruby-build`); the extension is linked against
16
+ # the C core, so the schema and the wire format stay in one place.
17
+ require_relative 'pbwire_ext'
18
+
19
+ # Idiomatic Ruby resource handling, mirroring File.open: with a block the
20
+ # schema closes itself (even on exception), without one the caller owns it
21
+ # and closes it explicitly. The C extension owns the format; this wrapper
22
+ # only owns the ergonomics, so no wire behavior changes here.
23
+ module Pbwire
24
+ class Schema
25
+ class << self
26
+ alias_method :__pbwire_from_bytes__, :from_bytes
27
+ alias_method :__pbwire_from_file__, :from_file
28
+
29
+ def from_bytes(bytes)
30
+ schema = __pbwire_from_bytes__(bytes)
31
+ return schema unless block_given?
32
+
33
+ begin
34
+ yield schema
35
+ ensure
36
+ schema.close unless schema.closed?
37
+ end
38
+ end
39
+
40
+ def from_file(path)
41
+ schema = __pbwire_from_file__(path)
42
+ return schema unless block_given?
43
+
44
+ begin
45
+ yield schema
46
+ ensure
47
+ schema.close unless schema.closed?
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pbwire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - jinganix
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: A FileDescriptorSet becomes the schema at runtime; messages go to/from
13
+ wire bytes with no generated code, through a C extension over the pbwire core.
14
+ executables: []
15
+ extensions:
16
+ - ext/pbwire_ext/extconf.rb
17
+ extra_rdoc_files: []
18
+ files:
19
+ - "../../VERSION"
20
+ - "../../include/pbwire.h"
21
+ - "../../src/arena.c"
22
+ - "../../src/ctx.c"
23
+ - "../../src/decode.c"
24
+ - "../../src/descriptor_set.c"
25
+ - "../../src/encode.c"
26
+ - "../../src/json.c"
27
+ - "../../src/message.c"
28
+ - "../../src/schema.c"
29
+ - "../../src/stream.c"
30
+ - "../../src/text.c"
31
+ - "../../src/wire.c"
32
+ - README.md
33
+ - ext/pbwire_ext/extconf.rb
34
+ - ext/pbwire_ext/pbwire_ext.c
35
+ - lib/pbwire.rb
36
+ homepage: https://github.com/jinganix/pbwire
37
+ licenses:
38
+ - Apache-2.0
39
+ metadata: {}
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.6.9
55
+ specification_version: 4
56
+ summary: Dynamic protobuf over the pbwire C ABI, schema at runtime
57
+ test_files: []