2025-07-27 23:46:54 +03:00
|
|
|
// See https://aka.ms/new-console-template for more information
|
2025-02-12 23:37:06 +03:00
|
|
|
|
2025-07-27 23:46:54 +03:00
|
|
|
using System.Formats.Cbor;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using BenchmarkDotNet.Running;
|
|
|
|
|
using mROA.Benchmark;
|
|
|
|
|
using mROA.Implementation;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Hello, World!");
|
|
|
|
|
var test = new CborTest();
|
|
|
|
|
test.ArrayWrite();
|
2025-08-03 00:32:32 +03:00
|
|
|
BenchmarkRunner.Run<VirtualOverhead>();
|
2025-07-27 23:46:54 +03:00
|
|
|
|
|
|
|
|
public static class CborExtensions
|
2025-02-12 23:01:28 +03:00
|
|
|
{
|
2025-07-27 23:46:54 +03:00
|
|
|
public static unsafe void WriteToCbor(this RequestId id, CborWriter writer)
|
2025-02-12 23:01:28 +03:00
|
|
|
{
|
2025-07-27 23:46:54 +03:00
|
|
|
Span<byte> span = stackalloc byte[16];
|
|
|
|
|
MemoryMarshal.Write(span, ref id);
|
|
|
|
|
writer.WriteByteString(span);
|
2025-02-12 23:37:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-07-27 23:46:54 +03:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static unsafe void WriteToCborInline(this RequestId id, CborWriter writer)
|
2025-02-20 16:10:09 +03:00
|
|
|
{
|
2025-07-27 23:46:54 +03:00
|
|
|
Span<byte> span = stackalloc byte[16];
|
|
|
|
|
MemoryMarshal.Write(span, ref id);
|
|
|
|
|
writer.WriteByteString(span);
|
|
|
|
|
}
|
2025-02-12 23:37:06 +03:00
|
|
|
|
2025-07-27 23:46:54 +03:00
|
|
|
public static void WriteToDest(this RequestId id, Span<byte> destination)
|
|
|
|
|
{
|
|
|
|
|
MemoryMarshal.Write(destination, ref id);
|
|
|
|
|
}
|
2025-02-12 23:37:06 +03:00
|
|
|
|
2025-07-27 23:46:54 +03:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
|
|
|
|
public static unsafe void WriteToCborOpt(this RequestId id, CborWriter writer)
|
|
|
|
|
{
|
|
|
|
|
Span<byte> span = stackalloc byte[16];
|
|
|
|
|
MemoryMarshal.Write(span, ref id);
|
|
|
|
|
writer.WriteByteString(span);
|
2025-02-12 23:01:28 +03:00
|
|
|
}
|
|
|
|
|
}
|