mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-14 13:52:11 +00:00
new enum type
This commit is contained in:
1 parent
0ae823be44
commit
7a4f6fbbbf
1 file changed
+33
@@ -10,6 +10,39 @@ use prost::Message;
|
||||
|
||||
// TODO: add some type safety w/ generics and type bounds
|
||||
|
||||
/// Sources of events
|
||||
pub enum InboundEventSource {
|
||||
Twitch(IngestionTwitchMetadata),
|
||||
}
|
||||
|
||||
/// Events
|
||||
pub enum InboundEvent {
|
||||
TwitchMessage(IngestionTwitchMessage),
|
||||
}
|
||||
|
||||
impl InboundEventSource {
|
||||
pub fn parse_from_payload(event_payload: &PubsubEventPayloadV1)
|
||||
-> AnyhowResult<Self>
|
||||
{
|
||||
match Self::parse_type_proto(event_payload) {
|
||||
Some(IngestionSourceType::IstTwitch) => {
|
||||
IngestionTwitchMetadata::decode(event_payload.ingestion_source_data())
|
||||
.map(|m| Self::Twitch(m))
|
||||
.map_err(|_| anyhow!("error decoding source proto"))
|
||||
},
|
||||
None => Err(anyhow!("invalid source type")),
|
||||
Some(_) => Err(anyhow!("type is not yet handled")),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_type_proto(event_payload: &PubsubEventPayloadV1)
|
||||
-> Option<IngestionSourceType>
|
||||
{
|
||||
event_payload.ingestion_payload_type
|
||||
.and_then(|num| IngestionSourceType::from_i32(num))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_source_type(event_payload: &PubsubEventPayloadV1)
|
||||
-> Option<IngestionSourceType>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user