pbwire 0.1.14 → 0.1.16
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 +4 -4
- data/README.md +31 -2
- data/ext/pbwire_ext/pbwire_ext.c +1233 -87
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7dd94f55ce589d8950dccaa9be49b72ccaeaf41f2e8e8d0cb618e277b9f390a9
|
|
4
|
+
data.tar.gz: e2ec6aad9f8f6388052549fa6a36dc800d20a92a374ae11c6c88c47fb0ef84af
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8271cb299cd323b746b9030f2589eb2e9458d8ced67e760d956b25db915e488dd83ced3b332635206b8f0d3ac4766415c6ca05a512dace2cba657a4c9a649bb
|
|
7
|
+
data.tar.gz: f8777686778ccd31fa9f5cbff856f7770fb9f67d44935171f8b4c329c5fdceb94975ce2f8e9b373f77f52e938123292c7915afcd367c47ee8a7ae7ebec9cca93
|
data/README.md
CHANGED
|
@@ -51,6 +51,11 @@ back["inner"]["s"] # => "nested"
|
|
|
51
51
|
back.encode == wire # => true: byte-exact re-encode
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
`Pbwire::Type` is not part of the Ruby API: it is the C-side holder for one
|
|
55
|
+
message's field table (memoized per schema and kept alive by the messages that
|
|
56
|
+
reference it). Reach a type through the schema — `schema.message("pkg.Msg")`
|
|
57
|
+
returns a builder of that type, and `Message#type` returns its full name.
|
|
58
|
+
|
|
54
59
|
## Build and run
|
|
55
60
|
|
|
56
61
|
The extension is compiled once per interpreter with `sh build.sh` (or
|
|
@@ -154,6 +159,30 @@ String do not change the message. A borrowed sub-message returned by `get` is
|
|
|
154
159
|
owned by its parent: it keeps the parent alive and refuses to be used after the
|
|
155
160
|
parent is closed.
|
|
156
161
|
|
|
162
|
+
### Contexts and pools
|
|
163
|
+
|
|
164
|
+
`Pbwire::Context` is the C `pbw_ctx` workspace (an arena plus a reusable encode
|
|
165
|
+
buffer), and `Pbwire::Pool` is a bounded freelist of them, for a server that
|
|
166
|
+
decodes in a tight loop:
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
ctx = Pbwire::Context.new
|
|
170
|
+
ctx.decode(schema, "pkg.Msg", wire) # read-only view, dies with the next reset
|
|
171
|
+
ctx.encode(msg) # into the context's buffer
|
|
172
|
+
ctx.used # bytes held now
|
|
173
|
+
ctx.retain_cap = 64 * 1024 # resident ceiling (1 MiB default)
|
|
174
|
+
ctx.reset # frees everything since the last reset
|
|
175
|
+
|
|
176
|
+
pool = Pbwire::Pool.new(max_idle: 8, retain_cap: 64 * 1024)
|
|
177
|
+
ctx = pool.acquire
|
|
178
|
+
# ... use ctx ...
|
|
179
|
+
pool.release(ctx) # already reset for the next acquire
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
A message decoded through a context borrows it: after `reset` (or a pool
|
|
183
|
+
`release`) it raises `"context was reset"` instead of reading freed arena
|
|
184
|
+
memory.
|
|
185
|
+
|
|
157
186
|
## Repeated fields, maps, groups
|
|
158
187
|
|
|
159
188
|
Repeated scalars (packed or unpacked on the wire), repeated strings/bytes and
|
|
@@ -214,9 +243,9 @@ official `conformance_test_runner` through this binding
|
|
|
214
243
|
`make conformance-setup`):
|
|
215
244
|
|
|
216
245
|
```
|
|
217
|
-
CONFORMANCE SUITE PASSED:
|
|
246
|
+
CONFORMANCE SUITE PASSED: 2747 successes, 0 skipped, 0 expected failures,
|
|
218
247
|
0 unexpected failures.
|
|
219
|
-
CONFORMANCE SUITE PASSED:
|
|
248
|
+
CONFORMANCE SUITE PASSED: 443 successes, 0 skipped, 0 expected failures,
|
|
220
249
|
0 unexpected failures.
|
|
221
250
|
```
|
|
222
251
|
|