Пример #1
0
 /// <summary>
 /// Reads bytes into the given span.
 /// </summary>
 /// <param name="destination">The destination span.</param>
 /// <exception cref="EndOfMessageException"></exception>
 public static void Read(this IBitBuffer buffer, Span <byte> destination)
 {
     if (!buffer.TryRead(destination))
     {
         throw new EndOfMessageException();
     }
 }
Пример #2
0
        /// <summary>
        /// Reads the bytes of a <typeparamref name="T"/> value from the buffer.
        /// </summary>
        public static bool TryRead <T>(this IBitBuffer buffer, out T value)
            where T : unmanaged
        {
            Unsafe.SkipInit(out value);
            Span <T>    span  = MemoryMarshal.CreateSpan(ref value, 1);
            Span <byte> bytes = MemoryMarshal.AsBytes(span);

            return(buffer.TryRead(bytes));
        }
Пример #3
0
        public static bool ReadUInt32(this IBitBuffer buffer, out uint result)
        {
            Span <byte> tmp = stackalloc byte[sizeof(uint)];

            if (buffer.TryRead(tmp))
            {
                result = BinaryPrimitives.ReadUInt32LittleEndian(tmp);
                return(true);
            }
            result = default;
            return(false);
        }
Пример #4
0
 public static bool TryRead(this IBitBuffer buffer, int count, out byte[] data)
 {
     data = new byte[count];
     return(buffer.TryRead(data));
 }