DBusValue struct

Namespace Runic.Platform.Linux.DBus in Runic.Platform.Linux.DBus 0.23.0

public readonly struct DBusValue : IEquatable<DBusValue>

Inherits or implements IEquatable.

One D-Bus value with its type signature: a basic value, a variant, an array, a dictionary or a structure.

Remarks

Create values with the static factories, such as DBusValue.From or DBusValue.Array, and read them with the matching getter, such as DBusValue.GetString. A getter for another type throws InvalidOperationException. Values compare by signature and content. A h value carries a file descriptor: one received in a message is a SafeFileHandle that belongs to the receiver, which disposes it. The default value has an empty signature and holds nothing.

Properties

IsDefault

public bool IsDefault { get; }

Whether this is the default value, which holds nothing.

Remarks

An empty container, such as an as without items, is not the default value.

Signature

public DBusSignature Signature { get; }

The value's type, one complete type such as s or a{sv}; empty for the default value.

Methods

Array

public static DBusValue Array(DBusSignature elementSignature, IEnumerable<DBusValue> items)

Creates an array of elementSignature values, such as as for strings.

Exceptions

ArgumentException

The element signature is not one complete type, or an item has another signature.

ByteArray

public static DBusValue ByteArray(ReadOnlySpan<byte> items)

Creates an ay value.

Remarks

The value keeps the bytes as one block, so a large ay costs about its length in memory.

Dictionary

public static DBusValue Dictionary(DBusSignature keySignature, DBusSignature valueSignature, IEnumerable<KeyValuePair<DBusValue, DBusValue>> entries)

Creates a dictionary, such as a{sv}, from entries whose keys have a basic type.

Exceptions

ArgumentException

The key signature is not a basic type, the value signature is not one complete type, an entry has other signatures, or a key repeats.

Equals

public bool Equals(DBusValue other)

Inherits documentation from IEquatable.Equals.

Equals

public override bool Equals(object? obj)

Inherits documentation from Object.Equals.

From

public static DBusValue From(byte value)

Creates a y value.

From

public static DBusValue From(bool value)

Creates a b value.

From

public static DBusValue From(short value)

Creates an n value.

From

public static DBusValue From(ushort value)

Creates a q value.

From

public static DBusValue From(int value)

Creates an i value.

From

public static DBusValue From(uint value)

Creates a u value.

From

public static DBusValue From(long value)

Creates an x value.

From

public static DBusValue From(ulong value)

Creates a t value.

From

public static DBusValue From(double value)

Creates a d value.

From

public static DBusValue From(string value)

Creates an s value.

Exceptions

ArgumentException

value contains NUL.

From

public static DBusValue From(DBusObjectPath value)

Creates an o value.

From

public static DBusValue From(DBusSignature value)

Creates a g value, a signature carried as data.

GetBoolean

public bool GetBoolean()

Gets a b value.

GetByte

public byte GetByte()

Gets a y value.

GetByteArray

public ImmutableArray<byte> GetByteArray()

Gets the bytes of an ay value.

Remarks

The bytes are the value's own, not a copy.

GetDouble

public double GetDouble()

Gets a d value.

GetEntries

public ImmutableArray<KeyValuePair<DBusValue, DBusValue>> GetEntries()

Gets the entries of a dictionary, in message order.

Remarks

A dictionary received in a message keeps every entry, including one whose key repeats an earlier key.

GetFields

public ImmutableArray<DBusValue> GetFields()

Gets the fields of a structure.

GetHashCode

public override int GetHashCode()

Inherits documentation from Object.GetHashCode.

GetInt16

public short GetInt16()

Gets an n value.

GetInt32

public int GetInt32()

Gets an i value.

GetInt64

public long GetInt64()

Gets an x value.

GetItems

public ImmutableArray<DBusValue> GetItems()

Gets the items of an array that is not a dictionary.

Remarks

For an ay, DBusValue.GetByteArray reads the bytes without creating a value for each.

GetObjectPath

public DBusObjectPath GetObjectPath()

Gets an o value.

GetObjectPathArray

public ImmutableArray<DBusObjectPath> GetObjectPathArray()

Gets the paths of an ao value.

GetString

public string GetString()

Gets an s value.

GetStringArray

public ImmutableArray<string> GetStringArray()

Gets the strings of an as value.

GetTypeSignature

public DBusSignature GetTypeSignature()

Gets a g value.

GetUInt16

public ushort GetUInt16()

Gets a q value.

GetUInt32

public uint GetUInt32()

Gets a u value.

GetUInt64

public ulong GetUInt64()

Gets a t value.

GetUnixFd

public SafeHandle GetUnixFd()

Gets the file descriptor of an h value. A received descriptor belongs to the caller, which disposes it.

Remarks

A descriptor received in a message is a SafeFileHandle, so it can be cast and wrapped in a FileStream; a value created with DBusValue.UnixFd returns the handle it was created with.

GetVariant

public DBusValue GetVariant()

Gets the value inside a v value.

GetVariantDictionary

public ImmutableDictionary<string, DBusValue> GetVariantDictionary()

Gets an a{sv} value as a dictionary of the values inside its variants.

Remarks

D-Bus does not forbid a peer from repeating a key. When a key repeats, the last entry's value wins, as in GLib's GVariantDict and GDBusProxy and in dbus-python; DBusValue.GetEntries still lists every entry.

ObjectPathArray

public static DBusValue ObjectPathArray(IEnumerable<DBusObjectPath> items)

Creates an ao value.

StringArray

public static DBusValue StringArray(IEnumerable<string> items)

Creates an as value.

Struct

public static DBusValue Struct(params ReadOnlySpan<DBusValue> fields)

Creates a structure of one or more fields, such as (si).

Exceptions

ArgumentException

There are no fields, or a field is the default value.

ToString

public override string ToString()

Formats the value for logs, such as {'Volume': <0.5>}.

UnixFd

public static DBusValue UnixFd(SafeHandle value)

Creates an h value that sends a file descriptor. The caller keeps ownership of the handle.

Exceptions

ArgumentException

The handle is invalid or closed.

Variant

public static DBusValue Variant(DBusValue value)

Creates a v value that wraps another value.

Exceptions

ArgumentException

value is the default value.

VariantDictionary

public static DBusValue VariantDictionary(IEnumerable<KeyValuePair<string, DBusValue>> entries)

Creates an a{sv} value, wrapping each value in a variant.

Exceptions

ArgumentException

A value is the default value, or a key repeats.

Operators

operator !=

public static bool operator !=(DBusValue left, DBusValue right)

Compares two values by signature and content.

operator ==

public static bool operator ==(DBusValue left, DBusValue right)

Compares two values by signature and content.