Comments (4)
I'm totally fine adding ?Sized
to the signature as a fix to get it working now (that will also fix the str
impl). Adding an impl for Vec<u8>
also doesn't bother me, although I was thinking the slice impl would cover that use case.
Long term, I don't feel like I've fully thought through the implications of the Serialize/DeserializeMessage
traits as the basis for handling this problem. Given the way the proto works, we need to have owned data in the payload, but most instance of serialization (thinking serde here) will involve copying data at some point, so for those, taking by ref seems to make the most sense. However, that makes it impossible to just pass in an owned Vec without falling back to send_raw
.
Alternatively, we could change SerializeMessage::serialize_message
to take Self
by value, change the signature of send
and send_all
to take T: SerializeMessage
by value, and then impl SerializeMessage
for borrowed types in cases where it makes sense (&Foo
instead of Foo
). My immediate instinct is that that approach feels like an improvement, but I don't feel like I've thought it through enough.
from pulsar-rs.
I fiddled around with it earlier today when I originally came across this problem and made Self
by value. It works fine, the only problem there is that you may only have a reference to your data, in which case you'll have to clone it at the call site.
I think there could be a third solution, maybe Message
holds onto a reference and has a lifetime, like:
struct Message<'a> {
payload: &'a [u8],
...
}
then,
impl<'a> SerializeMessage for &'a [u8] {
fn serialize_message(payload: Self) -> Message {
Message { payload, ..Default::default()
}
}
I haven't actually tried this though, but something to think about. It could even be something like:
struct Message<'a, B> { // I believe B: 'a is elided now since 2018
payload: &'a B,
...
}
Then bound <B: AsRef<[u8]>>
in it's impl's.
from pulsar-rs.
Unfortunately Message
has to be 'static
because it's immediately sent by channel to the async runtime to be handled.
the only problem there is that you may only have a reference to your data, in which case you'll have to clone it at the call site.
This works if you impl SerializeMessage
for a borrow of your struct, something like
#[derive(Debug, Clone, Serialize)]
pub struct Foo {
pub a: String,
pub b: u64,
}
impl SerializeMessage for &Foo {
fn serialize_message(input: &Foo) -> Result<producer::Message, Error> {
let payload = serde_json::to_vec(input).map_err(..)?;
Ok(producer::Message { payload, ..producer::Message::default() })
}
}
then you should be able to still call producer.send(..)
with your &Foo
from pulsar-rs.
Fixed in #61 (at least until we make SerializeMessage
work by value instead of by ref)
from pulsar-rs.
Related Issues (20)
- Transaction API support HOT 3
- Library always connect to 127.0.0.1? HOT 5
- Support for consumer event listener HOT 2
- Why client redirect to ssl connection? HOT 1
- Consumer stucks in reconnections HOT 9
- Consumer `try_next` stops producing messages, but consumer is still processing messages internally
- Producer and Consumer IDs
- Limit producer batch messages by size in bytes as well HOT 2
- Connection error: bytes remaining on stream
- Timeout in batching
- Negative unackedMessages in consumers
- Unable to cleanly close a consumer without unsubscribing from a topic HOT 2
- Mutex in producer::TopicProducer is unnecessary
- Concretize types for client building
- TLS BAD_PACKET_LENGTH Error
- Authentication Errors swallowed and never surfaced to places where you could handle the error HOT 1
- 在使用正则订阅的时候提示没有权限
- Please add an option to skip invalid metadata instead of shutdown the consumer
- Missing `batchingMaxPublishDelay` option
- migrate `async_rustls` to `futures-rustls`
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 pulsar-rs.