Comments (3)
Hm, interesting question! Maybe the way to go would be to implement ReaderSegments
for message::Builder
, like this:
impl <A> ReaderSegments for Builder<A> where A: Allocator {
fn get_segment<'a>(&'a self, id: u32) -> Option<&'a [Word]> {
self.get_segments_for_output().get(id as usize).map(|x| *x)
}
}
Then you could create a message::Reader
that wraps a message::Builder
.
from capnproto-rust.
Sorry it's taken me so long to respond. That indeed works! The result is a bit strange (because you need to wrap the Builder
inside a Reader
to get at the ReaderSegments
) but here's an example:
#[test]
fn test_typed_builder() {
let mut builder = message::Builder::new_default();
{
let mut ts_root = builder.init_root::<timestamp::Builder>();
ts_root.set_seconds(14);
ts_root.set_subsecond_nanos(0);
}
let reader = message::Reader::new(builder, message::ReaderOptions::new());
let owned_message: TypedReader<message::Builder<message::HeapAllocator>, timestamp::Owned> = TypedReader::new(reader);
assert_eq!(owned_message.get().unwrap().get_seconds(), 14);
}
I'd like to encapsulate some of the above code into the Builder
- I don't see why I couldn't provide an "into_typed" (i.e. since I specifically want to consume the builder into the TypedReader
) - and I'll open a PR soon.
from capnproto-rust.
Closed by #84.
from capnproto-rust.
Related Issues (20)
- doc: tonic like framework? HOT 2
- Serializing messages with no-alloc HOT 6
- `connection_state.connection` BorrowMutError HOT 4
- generate server traits without provided implementations
- `capnp_futures::serialize_packed::try_read_message()` is blocked forever with 100% cpu usage when the input stream is closed
- Backport capnp-futures changes from master to 0.14 version HOT 2
- no_std, no alloc serialization HOT 10
- Invoking closure on the event loop to get a mutable reference to self HOT 1
- How to read unknown number of messages HOT 2
- Serializing message to &[u8] HOT 2
- Improve performance of Reader get_named HOT 4
- Primitive list panicks if the list type is `Void` HOT 1
- Null values for non active union members HOT 3
- Switch Allocator to act more like an owned arena HOT 8
- Reader fails with out of bounds pointer error when reading from compressed stream HOT 1
- Revert text setter ergonomics pessification; add raw_set methods HOT 6
- calculator example fails with java server: Cannot read capability pointer without capTable HOT 1
- c++.capnp compiles to unusable module name HOT 6
- How to send generated readers across threads HOT 3
- From bytes to TypedReader HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capnproto-rust.