-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c306959
commit c87f599
Showing
15 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
[package] | ||
name = "xmtp_content_types" | ||
edition = "2021" | ||
license.workspace = true | ||
name = "xmtp_content_types" | ||
version.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
thiserror = { workspace = true } | ||
prost = { workspace = true, features = ["prost-derive"] } | ||
rand = { workspace = true } | ||
tonic = { version = "0.12", features = ["transport"] } | ||
|
||
# XMTP/Local | ||
xmtp_proto = { workspace = true, features = ["convert"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
// TODO: move content types here | ||
pub mod group_updated; | ||
pub mod membership_change; | ||
#[cfg(test)] | ||
mod test_utils; | ||
pub mod text; | ||
|
||
use thiserror::Error; | ||
use xmtp_proto::xmtp::mls::message_contents::{ContentTypeId, EncodedContent}; | ||
|
||
pub enum ContentType { | ||
GroupMembershipChange, | ||
GroupUpdated, | ||
Text, | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum CodecError { | ||
#[error("encode error {0}")] | ||
Encode(String), | ||
#[error("decode error {0}")] | ||
Decode(String), | ||
} | ||
|
||
pub trait ContentCodec<T> { | ||
fn content_type() -> ContentTypeId; | ||
fn encode(content: T) -> Result<EncodedContent, CodecError>; | ||
fn decode(content: EncodedContent) -> Result<T, CodecError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#[cfg(test)] | ||
use rand::{ | ||
distributions::{Alphanumeric, DistString}, | ||
Rng, | ||
}; | ||
|
||
#[cfg(test)] | ||
pub(crate) fn rand_string() -> String { | ||
Alphanumeric.sample_string(&mut rand::thread_rng(), 24) | ||
} | ||
|
||
#[cfg(test)] | ||
pub(crate) fn rand_vec() -> Vec<u8> { | ||
rand::thread_rng().gen::<[u8; 24]>().to_vec() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters