Esempio n. 1
0
        public static unsafe void RestoreFromBytes()
        {
            var id1   = new Random().Next <ClusterMemberId>();
            var bytes = Span.AsReadOnlyBytes(id1);
            var id2   = new ClusterMemberId(bytes);

            Equal(id1, id2);
        }
        public static async Task DecodeAsAllocatedBuffer()
        {
            using var dto = new MemoryTransferObject(sizeof(long));
            Span.AsReadOnlyBytes(42L).CopyTo(dto.Content.Span);
            using var memory = await dto.ToMemoryAsync();

            Equal(42L, BitConverter.ToInt64(memory.Memory.Span));
        }
        public static async Task ToBlittableType()
        {
            var bytes = new byte[sizeof(decimal)];

            Span.AsReadOnlyBytes(42M).CopyTo(bytes);
            var dto = new BinaryTransferObject(bytes);

            Equal(42M, await dto.ToType <decimal, BinaryTransferObject>());
        }
        public static async Task BufferedDTO()
        {
            using var dto = new MemoryTransferObject(sizeof(long));
            Span.AsReadOnlyBytes(42L).CopyTo(dto.Content.Span);
            Equal(sizeof(long), dto.As <IDataTransferObject>().Length);
            True(dto.As <IDataTransferObject>().IsReusable);
            var writer = new ArrayBufferWriter <byte>();
            await dto.WriteToAsync(writer);

            Equal(sizeof(long), writer.WrittenCount);
            Equal(42L, BitConverter.ToInt64(writer.WrittenSpan));
            var memory = await dto.ToByteArrayAsync();

            Equal(42L, BitConverter.ToInt64(memory, 0));
        }
Esempio n. 5
0
 /// <summary>
 /// Returns hexadecimal representation of this identifier.
 /// </summary>
 /// <returns>The hexadecimal representation of this identifier.</returns>
 public override string ToString()
 => Span.AsReadOnlyBytes(this).ToHex();