public static class BridgeWire Static, allocation-conscious JSON primitives used by generated bridge codecs. Values whose JavaScript number representation can lose precision are represented as invariant strings on the wire.
Methods
Canonicalize
public static byte[] Canonicalize(ReadOnlySpan<byte> json) Returns a canonical UTF-8 encoding for a complete JSON document.
Canonicalize
public static byte[] Canonicalize(JsonElement value) Returns a canonical UTF-8 encoding for one JSON value.
EncodeCanonical
public static string EncodeCanonical(Action<Utf8JsonWriter> write) Writes a complete canonical JSON value.
Exceptions
FormatExceptionThe value has a duplicate member name, a number beyond the range of a double or a string that is not valid Unicode.
Remarks
The canonical form is RFC 8785 (JCS): object members are sorted by the UTF-16 code units of their names, duplicate names are rejected, numbers are read as IEEE 754 doubles and written as ECMAScript writes them (1.0 and 1e0 are both 1, and -0 is 0), and strings escape only ", \ and control characters. A number beyond the range of a double and a string that is not valid Unicode are rejected.
Invalid
public static FormatException Invalid(string message) Creates a consistent invalid-wire exception for generated readers.
ReadBigInteger
public static BigInteger ReadBigInteger(JsonElement value) Reads an exact arbitrary-precision integer represented as a decimal string.
ReadDateOnly
public static DateOnly ReadDateOnly(JsonElement value) Reads an RFC 3339 full-date (yyyy-MM-dd).
ReadDateTime
public static DateTime ReadDateTime(JsonElement value) Reads an RFC 3339 date-time with an optional offset: none is DateTimeKind.Unspecified, Z is DateTimeKind.Utc, and an offset is DateTimeKind.Local, converted to local time.
ReadDateTimeOffset
public static DateTimeOffset ReadDateTimeOffset(JsonElement value) Reads an RFC 3339 date-time whose offset (Z or ±hh:mm) is required, keeping the offset.
ReadDecimal
public static decimal ReadDecimal(JsonElement value) Reads an exact decimal string, -?(0|[1-9][0-9]*)(\.[0-9]+)? with at most 28 digits after the point and digits below 2^96. The scale is the number of digits after the point.
ReadDouble
public static double ReadDouble(JsonElement value) Reads a finite JSON number as a double-precision value.
ReadEnum
public static TEnum ReadEnum<TEnum>(JsonElement value) where TEnum : struct, Enum Reads a declared enum name.
ReadGuid
public static Guid ReadGuid(JsonElement value) Reads a UUID string of 8-4-4-4-12 hexadecimal digits in either case.
ReadInt16
public static short ReadInt16(JsonElement value) Reads a JSON number whose value is a 16-bit integer.
ReadInt32
public static int ReadInt32(JsonElement value) Reads a JSON number whose value is a 32-bit integer.
ReadInt64
public static long ReadInt64(JsonElement value) Reads an exact 64-bit integer represented as a decimal string.
ReadInt64String
public static long ReadInt64String(JsonElement value) The same as BridgeWire.ReadInt64.
ReadInt8
public static sbyte ReadInt8(JsonElement value) Reads a JSON number whose value is a signed 8-bit integer.
ReadNullableString
public static string? ReadNullableString(JsonElement value) Reads a JSON string or null.
ReadRequiredString
public static string ReadRequiredString(JsonElement value) Compatibility spelling for a non-null JSON string.
ReadSingle
public static float ReadSingle(JsonElement value) Reads a JSON number as the nearest single-precision value, which must be finite.
ReadTimeOnly
public static TimeOnly ReadTimeOnly(JsonElement value) Reads an RFC 3339 partial-time with a fraction of up to seven digits.
ReadTimeSpan
public static TimeSpan ReadTimeSpan(JsonElement value) Reads an ISO 8601 duration -?P(nD)?(T(nH)?(nM)?(n(.f)?S)?)? (values.md, duration). A day is 24 hours; components may exceed their usual range, and the total must fit a TimeSpan.
ReadUInt16
public static ushort ReadUInt16(JsonElement value) Reads a JSON number whose value is an unsigned 16-bit integer.
ReadUInt32
public static uint ReadUInt32(JsonElement value) Reads a JSON number whose value is an unsigned 32-bit integer.
ReadUInt64
public static ulong ReadUInt64(JsonElement value) Reads an exact unsigned 64-bit integer represented as a decimal string.
ReadUInt64String
public static ulong ReadUInt64String(JsonElement value) The same as BridgeWire.ReadUInt64.
ReadUInt8
public static byte ReadUInt8(JsonElement value) Reads a JSON number whose value is an unsigned 8-bit integer.
ReadUpload
public static RunicUpload ReadUpload(JsonElement value) Reads an upload value (blobs/1): an object whose id names an unclaimed upload of the request's Window and connection. Its other members are ignored; the upload's name, type and size are those the host received.
Exceptions
FormatExceptionThe value is not an upload object, or names no such upload.
RequiredProperty
public static JsonElement RequiredProperty(JsonElement value, string name) Reads a named property from a JSON object.
StructuralEquals
public static bool StructuralEquals(string left, string right) Compares two complete JSON documents after canonicalization.
StructuralEquals
public static bool StructuralEquals(JsonElement left, JsonElement right) Compares two JSON values after canonicalization.
WriteBigInteger
public static void WriteBigInteger(Utf8JsonWriter writer, BigInteger value) Writes an arbitrary-precision integer as a decimal JSON string.
WriteBlob
public static void WriteBlob(Utf8JsonWriter writer, RunicBlob value) Writes a blob value (blobs/1): {"url","type","size","name"}, with the URL the Window's host serves the blob at. The URL is empty when the blob is written outside a Window's Bridge or the host serves no blobs.
WriteDateOnly
public static void WriteDateOnly(Utf8JsonWriter writer, DateOnly value) Writes an RFC 3339 full-date (yyyy-MM-dd).
WriteDateTime
public static void WriteDateTime(Utf8JsonWriter writer, DateTime value) Writes a date-time: nothing after the time for DateTimeKind.Unspecified, Z for DateTimeKind.Utc, and the machine's offset for DateTimeKind.Local.
WriteDateTimeOffset
public static void WriteDateTimeOffset(Utf8JsonWriter writer, DateTimeOffset value) Writes a date-time with its offset, Z for a zero offset.
WriteDecimal
public static void WriteDecimal(Utf8JsonWriter writer, decimal value) Writes a decimal as a JSON string with its scale; a negative zero loses its sign.
WriteDouble
public static void WriteDouble(Utf8JsonWriter writer, double value) Writes a finite double-precision JSON number.
WriteEnum
public static void WriteEnum<TEnum>(Utf8JsonWriter writer, TEnum value) where TEnum : struct, Enum Writes a declared enum name.
WriteFiniteNumber
public static void WriteFiniteNumber(Utf8JsonWriter writer, float value) Writes a finite single-precision value as the shortest decimal number that rounds to it (0.1, not 0.100000001); negative zero is written as 0.
WriteFiniteNumber
public static void WriteFiniteNumber(Utf8JsonWriter writer, double value) Writes a finite double-precision JSON number; negative zero is written as 0.
WriteGuid
public static void WriteGuid(Utf8JsonWriter writer, Guid value) Writes a UUID string of lowercase hexadecimal digits in D format.
WriteInt64
public static void WriteInt64(Utf8JsonWriter writer, long value) Writes a 64-bit integer as a decimal JSON string.
WriteIntegerString
public static void WriteIntegerString<TInteger>(Utf8JsonWriter writer, TInteger value) where TInteger : IBinaryInteger<TInteger> Writes an exact integer as a decimal JSON string.
WriteNullableString
public static void WriteNullableString(Utf8JsonWriter writer, string? value) Writes a JSON string or null.
WriteSingle
public static void WriteSingle(Utf8JsonWriter writer, float value) Writes a finite single-precision JSON number.
WriteTimeOnly
public static void WriteTimeOnly(Utf8JsonWriter writer, TimeOnly value) Writes a time without trailing zeros in its fraction (10:30:00, 10:30:00.5).
WriteTimeSpan
public static void WriteTimeSpan(Utf8JsonWriter writer, TimeSpan value) Writes an ISO 8601 duration in its normal form: the sign, days, then T and the nonzero hours, minutes and seconds (P1DT2H3M4.5S); zero is PT0S.
WriteUInt64
public static void WriteUInt64(Utf8JsonWriter writer, ulong value) Writes an unsigned 64-bit integer as a decimal JSON string.
WriteUpload
public static void WriteUpload(Utf8JsonWriter writer, RunicUpload value) Writes an upload value (blobs/1): {"id","name","type","size"}.