/// <summary> /// Encodes a <see cref="NetBitArray"/> to this buffer. /// </summary> public static void Write(this IBitBuffer buffer, NetBitArray bitArray) { buffer.WriteVar(bitArray.Length); ReadOnlySpan <uint> values = bitArray.GetBuffer().Span; int bitsLeft = NetUtility.PowOf2Mod(bitArray.Length, NetBitArray.BitsPerElement); if (bitsLeft == 0) { for (int i = 0; i < values.Length; i++) { buffer.Write(values[i]); } } else { for (int i = 0; i < values.Length - 1; i++) { buffer.Write(values[i]); } uint last = values[^ 1];
/// <summary> /// Write variable sized <see cref="int"/>. /// </summary> /// <returns>Amount of bytes written.</returns> public static int WriteVar(this IBitBuffer buffer, int value) { uint zigzag = (uint)(value << 1) ^ (uint)(value >> 31); return(buffer.WriteVar(zigzag)); }
/// <summary> /// Writes a <see cref="TimeSpan"/>. /// </summary> public static void Write(this IBitBuffer buffer, TimeSpan time) { buffer.WriteVar(time.Ticks); }
/// <summary> /// Write variable sized <see cref="long"/>. /// </summary> /// <returns>Amount of bytes written.</returns> public static int WriteVar(this IBitBuffer buffer, long value) { ulong zigzag = (ulong)(value << 1) ^ (ulong)(value >> 63); return(buffer.WriteVar(zigzag)); }