mirror of
https://github.com/xai-org/x-algorithm.git
synced 2026-02-13 03:05:06 +01:00
27 lines
1.1 KiB
Rust
27 lines
1.1 KiB
Rust
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")
|
|
}
|