forked from xai-org/x-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeserializer.rs
More file actions
26 lines (21 loc) · 1.08 KB
/
deserializer.rs
File metadata and controls
26 lines (21 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::schema::{events::Event, tweet_events::TweetEvent};
use anyhow::{Context, Result};
use prost::Message;
use thrift::protocol::{TBinaryInputProtocol, TSerializable};
use xai_thunder_proto::InNetworkEvent;
/// Deserialize a Thrift binary message into TweetEvent
pub fn deserialize_tweet_event(payload: &[u8]) -> Result<TweetEvent> {
let mut cursor = std::io::Cursor::new(payload);
let mut protocol = TBinaryInputProtocol::new(&mut cursor, true);
TweetEvent::read_from_in_protocol(&mut protocol).context("Failed to deserialize TweetEvent")
}
/// Deserialize a Thrift binary message into Event
pub fn deserialize_event(payload: &[u8]) -> Result<Event> {
let mut cursor = std::io::Cursor::new(payload);
let mut protocol = TBinaryInputProtocol::new(&mut cursor, true);
Event::read_from_in_protocol(&mut protocol).context("Failed to deserialize Event")
}
/// Deserialize a proto binary message into InNetworkEvent
pub fn deserialize_tweet_event_v2(payload: &[u8]) -> Result<InNetworkEvent> {
InNetworkEvent::decode(payload).context("Failed to deserialize InNetworkEvent")
}