pbwire 0.1.15 → 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 +24 -0
- data/ext/pbwire_ext/pbwire_ext.c +1159 -67
- 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
|
@@ -159,6 +159,30 @@ String do not change the message. A borrowed sub-message returned by `get` is
|
|
|
159
159
|
owned by its parent: it keeps the parent alive and refuses to be used after the
|
|
160
160
|
parent is closed.
|
|
161
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
|
+
|
|
162
186
|
## Repeated fields, maps, groups
|
|
163
187
|
|
|
164
188
|
Repeated scalars (packed or unpacked on the wire), repeated strings/bytes and
|