diff --git a/src/Tmds.DBus.Protocol/Reader.Basic.cs b/src/Tmds.DBus.Protocol/Reader.Basic.cs index 27f35fc..119c8c1 100644 --- a/src/Tmds.DBus.Protocol/Reader.Basic.cs +++ b/src/Tmds.DBus.Protocol/Reader.Basic.cs @@ -65,6 +65,9 @@ public unsafe double ReadDouble() return value; } + public Signature ReadSignature() + => new Signature(ReadSignatureAsSpan()); + public ReadOnlySpan ReadSignatureAsSpan() { int length = ReadByte(); @@ -87,6 +90,15 @@ public void ReadSignature(string expected) } } + public void ReadSignature(ReadOnlySpan expected) + { + ReadOnlySpan signature = ReadSignatureAsSpan(); + if (!signature.SequenceEqual(expected)) + { + ThrowHelper.ThrowUnexpectedSignature(signature, Encoding.UTF8.GetString(expected)); + } + } + public ReadOnlySpan ReadObjectPathAsSpan() => ReadSpan(); public ObjectPath ReadObjectPath() => new ObjectPath(ReadString()); @@ -97,8 +109,6 @@ public void ReadSignature(string expected) public string ReadString() => Encoding.UTF8.GetString(ReadSpan()); - public Signature ReadSignatureAsSignature() => new Signature(ReadSignatureAsSpan()); - public string ReadSignatureAsString() => Encoding.UTF8.GetString(ReadSignatureAsSpan()); private ReadOnlySpan ReadSpan() diff --git a/src/Tmds.DBus.Protocol/Reader.ReadT.cs b/src/Tmds.DBus.Protocol/Reader.ReadT.cs index fe937a5..0793c4b 100644 --- a/src/Tmds.DBus.Protocol/Reader.ReadT.cs +++ b/src/Tmds.DBus.Protocol/Reader.ReadT.cs @@ -51,7 +51,7 @@ public ref partial struct Reader } else if (typeof(T) == typeof(Signature)) { - return (T)(object)ReadSignatureAsSignature(); + return (T)(object)ReadSignature(); } else if (typeof(T).IsAssignableTo(typeof(SafeHandle))) { diff --git a/src/Tmds.DBus.Protocol/Reader.Variant.cs b/src/Tmds.DBus.Protocol/Reader.Variant.cs index d8111b2..a894565 100644 --- a/src/Tmds.DBus.Protocol/Reader.Variant.cs +++ b/src/Tmds.DBus.Protocol/Reader.Variant.cs @@ -44,7 +44,7 @@ private VariantValue ReadTypeAsVariantValue(DBusType type, ReadOnlySpan in case DBusType.ObjectPath: return new VariantValue(ReadObjectPath(), nesting); case DBusType.Signature: - return new VariantValue(ReadSignatureAsSignature(), nesting); + return new VariantValue(ReadSignature(), nesting); case DBusType.UnixFd: int idx = (int)ReadUInt32(); return new VariantValue(_handles, idx, nesting); diff --git a/src/Tmds.DBus.Tool/ProtocolGenerator.cs b/src/Tmds.DBus.Tool/ProtocolGenerator.cs index f91195a..3997584 100644 --- a/src/Tmds.DBus.Tool/ProtocolGenerator.cs +++ b/src/Tmds.DBus.Tool/ProtocolGenerator.cs @@ -518,7 +518,7 @@ private void AppendInterface(string name, XElement interfaceXml) { AppendLine($"case \"{property.Name}\":"); _indentation++; - AppendLine($"reader.ReadSignature(\"{property.Signature}\");"); + AppendLine($"reader.ReadSignature(\"{property.Signature}\"u8);"); AppendLine($"props.{property.NameUpper} = {CallReadArgumentType(property.Signature)};"); AppendLine($"changedList?.Add(\"{property.NameUpper}\");"); AppendLine("break;"); @@ -757,7 +757,7 @@ private void AppendReadMessageMethod(string name, bool variant, Argument[] args) AppendLine("var reader = message.GetBodyReader();"); if (variant) { - AppendLine($"reader.ReadSignature(\"{signature}\");"); + AppendLine($"reader.ReadSignature(\"{signature}\"u8);"); } if (args.Length == 1) {