Skip to content

Commit

Permalink
ProtocolConstants: remove signatures.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Nov 20, 2024
1 parent f95869b commit e95b0ab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 35 deletions.
30 changes: 15 additions & 15 deletions src/Tmds.DBus.Protocol/MessageWriter.Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,91 +56,91 @@ public void WriteSignature(string s)

public void WriteVariantBool(bool value)
{
WriteSignature(ProtocolConstants.BooleanSignature);
WriteSignature(Signature.Boolean);
WriteBool(value);
}

public void WriteVariantByte(byte value)
{
WriteSignature(ProtocolConstants.ByteSignature);
WriteSignature(Signature.Byte);
WriteByte(value);
}

public void WriteVariantInt16(short value)
{
WriteSignature(ProtocolConstants.Int16Signature);
WriteSignature(Signature.Int16);
WriteInt16(value);
}

public void WriteVariantUInt16(ushort value)
{
WriteSignature(ProtocolConstants.UInt16Signature);
WriteSignature(Signature.UInt16);
WriteUInt16(value);
}

public void WriteVariantInt32(int value)
{
WriteSignature(ProtocolConstants.Int32Signature);
WriteSignature(Signature.Int32);
WriteInt32(value);
}

public void WriteVariantUInt32(uint value)
{
WriteSignature(ProtocolConstants.UInt32Signature);
WriteSignature(Signature.UInt32);
WriteUInt32(value);
}

public void WriteVariantInt64(long value)
{
WriteSignature(ProtocolConstants.Int64Signature);
WriteSignature(Signature.Int64);
WriteInt64(value);
}

public void WriteVariantUInt64(ulong value)
{
WriteSignature(ProtocolConstants.UInt64Signature);
WriteSignature(Signature.UInt64);
WriteUInt64(value);
}

public void WriteVariantDouble(double value)
{
WriteSignature(ProtocolConstants.DoubleSignature);
WriteSignature(Signature.Double);
WriteDouble(value);
}

public void WriteVariantString(scoped ReadOnlySpan<byte> value)
{
WriteSignature(ProtocolConstants.StringSignature);
WriteSignature(Signature.String);
WriteString(value);
}

public void WriteVariantSignature(scoped ReadOnlySpan<byte> value)
{
WriteSignature(ProtocolConstants.SignatureSignature);
WriteSignature(Signature.Sig);
WriteSignature(value);
}

public void WriteVariantObjectPath(scoped ReadOnlySpan<byte> value)
{
WriteSignature(ProtocolConstants.ObjectPathSignature);
WriteSignature(Signature.ObjectPath);
WriteObjectPath(value);
}

public void WriteVariantString(string value)
{
WriteSignature(ProtocolConstants.StringSignature);
WriteSignature(Signature.String);
WriteString(value);
}

public void WriteVariantSignature(string value)
{
WriteSignature(ProtocolConstants.SignatureSignature);
WriteSignature(Signature.Sig);
WriteSignature(value);
}

public void WriteVariantObjectPath(string value)
{
WriteSignature(ProtocolConstants.ObjectPathSignature);
WriteSignature(Signature.ObjectPath);
WriteObjectPath(value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.DBus.Protocol/MessageWriter.Handle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void WriteHandle(SafeHandle value)

public void WriteVariantHandle(SafeHandle value)
{
WriteSignature(ProtocolConstants.UnixFdSignature);
WriteSignature(Signature.UnixFd);
WriteHandle(value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.DBus.Protocol/MessageWriter.Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void WriteError(
{
WriteStructureStart();
WriteByte((byte)MessageHeader.Signature);
WriteVariantSignature(ProtocolConstants.StringSignature);
WriteVariantSignature(Signature.String);
}

WriteHeaderEnd(start);
Expand Down
17 changes: 0 additions & 17 deletions src/Tmds.DBus.Protocol/ProtocolConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ namespace Tmds.DBus.Protocol;
static class ProtocolConstants
{
public const int MaxSignatureLength = 256;

// note: C# compiler treats these as static data.
public static ReadOnlySpan<byte> ByteSignature => new byte[] { (byte)'y' };
public static ReadOnlySpan<byte> BooleanSignature => new byte[] { (byte)'b' };
public static ReadOnlySpan<byte> Int16Signature => new byte[] { (byte)'n' };
public static ReadOnlySpan<byte> UInt16Signature => new byte[] { (byte)'q' };
public static ReadOnlySpan<byte> Int32Signature => new byte[] { (byte)'i' };
public static ReadOnlySpan<byte> UInt32Signature => new byte[] { (byte)'u' };
public static ReadOnlySpan<byte> Int64Signature => new byte[] { (byte)'x' };
public static ReadOnlySpan<byte> UInt64Signature => new byte[] { (byte)'t' };
public static ReadOnlySpan<byte> DoubleSignature => new byte[] { (byte)'d' };
public static ReadOnlySpan<byte> UnixFdSignature => new byte[] { (byte)'h' };
public static ReadOnlySpan<byte> StringSignature => new byte[] { (byte)'s' };
public static ReadOnlySpan<byte> ObjectPathSignature => new byte[] { (byte)'o' };
public static ReadOnlySpan<byte> SignatureSignature => new byte[] { (byte)'g' };
public static ReadOnlySpan<byte> VariantSignature => new byte[] { (byte)'v' };

public const int StructAlignment = 8;
public const int UInt32Alignment = 4;

Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.DBus.Protocol/VariantValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ private void WriteValueTo(ref MessageWriter writer, int nestingOffset)
nesting += nestingOffset;
while (nesting > 1)
{
writer.WriteSignature(ProtocolConstants.VariantSignature);
writer.WriteSignature(Protocol.Signature.Variant);
nesting--;
}
if (nesting == 1)
Expand Down

0 comments on commit e95b0ab

Please sign in to comment.