-
Notifications
You must be signed in to change notification settings - Fork 218
Update schema metadata validation logic #1328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| livekit: patch | ||
| livekit-datatrack: patch | ||
| livekit-ffi: patch | ||
| livekit-uniffi: patch | ||
| --- | ||
|
|
||
| Update schema metadata validation logic - #1328 (@ladvoc) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,8 @@ pub enum DataTrackSchemaEncoding { | |
| JsonSchema, | ||
|
|
||
| /// Another well-known encoding not known to this client version. | ||
| /// | ||
| /// Only produced for received tracks; cannot be used when publishing. | ||
| Other, | ||
| /// An application-specific encoding identified by the contained string. | ||
| /// | ||
|
|
@@ -163,6 +165,8 @@ pub enum DataTrackFrameEncoding { | |
| Json, | ||
|
|
||
| /// Another well-known encoding not known to this client version. | ||
| /// | ||
| /// Only produced for received tracks; cannot be used when publishing. | ||
| Other, | ||
| /// An application-specific encoding identified by the contained string. | ||
| /// | ||
|
|
@@ -186,14 +190,24 @@ pub enum DataTrackSchemaError { | |
| /// Specified schema and frame encodings are incompatible. | ||
| #[error("Specified schema and frame encodings are incompatible")] | ||
| Incompatible, | ||
|
|
||
| /// The 'other' encoding represents an unrecognized encoding on received tracks | ||
| /// and cannot be used when publishing. | ||
| #[error("The 'other' encoding cannot be used when publishing")] | ||
| OtherEncoding, | ||
|
Comment on lines
+193
to
+197
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick(non-blocking): I wonder if there's a way to do this where you aren't exposing |
||
| } | ||
|
|
||
| /// Validates that the given frame and schema encodings are compatible. | ||
| pub(crate) fn validate_schema( | ||
| frame_encoding: Option<&DataTrackFrameEncoding>, | ||
| schema_encoding: Option<&DataTrackSchemaEncoding>, | ||
| ) -> Result<(), DataTrackSchemaError> { | ||
| use DataTrackFrameEncoding as FrameEncoding; | ||
| use DataTrackSchemaEncoding as SchemaEncoding; | ||
|
Comment on lines
+205
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Why alias these here rather than just the fully qualified names below? IMO, it adds some confusion because it's not 100% clear that |
||
| match (frame_encoding, schema_encoding) { | ||
| (Some(FrameEncoding::Other), _) | (_, Some(SchemaEncoding::Other)) => { | ||
| Err(DataTrackSchemaError::OtherEncoding) | ||
| } | ||
| (None, Some(_)) => Err(DataTrackSchemaError::MissingFrameEncoding), | ||
| (Some(frame_encoding), None) => match frame_encoding.is_self_describing() { | ||
| Some(false) => Err(DataTrackSchemaError::MissingSchemaId), | ||
|
|
@@ -230,7 +244,10 @@ impl DataTrackFrameEncoding { | |
| | (Self::Protobuf, SchemaEncoding::Protobuf) | ||
| | (Self::Flatbuffer, SchemaEncoding::Flatbuffer) | ||
| | (Self::Json, SchemaEncoding::JsonSchema) => Some(true), | ||
| (Self::Other, _) | (Self::Custom(_), _) => None, // Cannot be determined | ||
| (Self::Other, _) | ||
| | (Self::Custom(_), _) | ||
| | (_, SchemaEncoding::Other) | ||
| | (_, SchemaEncoding::Custom(_)) => None, // Cannot be determined | ||
| _ => Some(false), | ||
| } | ||
| } | ||
|
|
@@ -383,6 +400,36 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_validate_schema_custom_schema_encoding() { | ||
| assert_eq!( | ||
| validate_schema( | ||
| Some(&DataTrackFrameEncoding::Json), | ||
| Some(&DataTrackSchemaEncoding::Custom("my-schema-encoding".to_string())) | ||
| ), | ||
| Ok(()) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_validate_schema_other_schema_encoding() { | ||
| assert_eq!( | ||
| validate_schema( | ||
| Some(&DataTrackFrameEncoding::Json), | ||
| Some(&DataTrackSchemaEncoding::Other) | ||
| ), | ||
| Err(DataTrackSchemaError::OtherEncoding) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_validate_schema_other_frame_encoding() { | ||
| assert_eq!( | ||
| validate_schema(Some(&DataTrackFrameEncoding::Other), None), | ||
| Err(DataTrackSchemaError::OtherEncoding) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_validate_schema_missing_frame_encoding() { | ||
| assert_eq!( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.