提交 93c9367e authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Minor refactoring

上级 6b0acc44
......@@ -3,7 +3,7 @@ use crate::worker::common::{EventHandlers, SubscriptionTarget, WeakEventHandlers
use crate::worker::{RequestError, SubscriptionHandler};
use async_executor::Executor;
use async_fs::File;
use bytes::{BufMut, Bytes, BytesMut};
use bytes::Bytes;
use futures_lite::io::BufReader;
use futures_lite::{future, AsyncReadExt, AsyncWriteExt};
use log::{debug, trace, warn};
......@@ -372,19 +372,14 @@ impl Channel {
debug!("request() [method:{}, id:{}]: {}", method, id, message);
let bytes = {
let mut bytes = BytesMut::new().writer();
serde_json::to_writer(
&mut bytes,
&RequestMessagePrivate {
id,
method,
message,
},
)
.unwrap();
bytes.into_inner()
};
let bytes = Bytes::from(
serde_json::to_vec(&RequestMessagePrivate {
id,
method,
message,
})
.unwrap(),
);
if bytes.len() > NS_PAYLOAD_MAX_LEN {
self.inner
......@@ -399,7 +394,7 @@ impl Channel {
self.inner
.sender
.send(bytes.freeze())
.send(bytes)
.await
.map_err(|_| RequestError::ChannelClosed {})?;
......
......@@ -3,7 +3,7 @@ use crate::worker::common::{EventHandlers, SubscriptionTarget, WeakEventHandlers
use crate::worker::{RequestError, SubscriptionHandler};
use async_executor::Executor;
use async_fs::File;
use bytes::{BufMut, Bytes, BytesMut};
use bytes::Bytes;
use futures_lite::io::BufReader;
use futures_lite::{future, AsyncReadExt, AsyncWriteExt};
use log::{debug, error, trace, warn};
......@@ -366,19 +366,14 @@ impl PayloadChannel {
debug!("request() [method:{}, id:{}]: {}", method, id, message);
let bytes = {
let mut bytes = BytesMut::new().writer();
serde_json::to_writer(
&mut bytes,
&RequestMessagePrivate {
id,
method,
message,
},
)
.unwrap();
bytes.into_inner()
};
let bytes = Bytes::from(
serde_json::to_vec(&RequestMessagePrivate {
id,
method,
message,
})
.unwrap(),
);
if bytes.len() > NS_PAYLOAD_MAX_LEN {
self.inner
......@@ -405,7 +400,7 @@ impl PayloadChannel {
self.inner
.sender
.send(MessageWithPayload {
message: bytes.freeze(),
message: bytes,
payload,
})
.await
......@@ -465,18 +460,13 @@ impl PayloadChannel {
return Err(NotificationError::PayloadTooLong);
}
let bytes = {
let mut bytes = BytesMut::new().writer();
serde_json::to_writer(
&mut bytes,
&NotificationMessagePrivate {
event,
notification,
},
)
.unwrap();
bytes.into_inner()
};
let bytes = Bytes::from(
serde_json::to_vec(&NotificationMessagePrivate {
event,
notification,
})
.unwrap(),
);
if bytes.len() > NS_PAYLOAD_MAX_LEN {
return Err(NotificationError::MessageTooLong);
......@@ -485,7 +475,7 @@ impl PayloadChannel {
self.inner
.sender
.send(MessageWithPayload {
message: bytes.freeze(),
message: bytes,
payload,
})
.await
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论