Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Drawaes's full-sized avatar

Tim Seaward Drawaes

  • Pltfm Limited
  • London
View GitHub Profile
namespace TestApp
{
class Program
{
private static ConnectionDetails _connectionDetails;
static async Task Main(string[] args)
{
_connectionDetails = new ConnectionDetails()
{
private async ValueTask<SearchResultValue> BinarySearchBlocks(ReadOnlyMemory<byte> key)
{
var min = 0;
var max = _metaData.BlockCount - 1;
while (min <= max)
{
var mid = (min + max) / 2;
using var block = await GetKVBlock(mid);
var result = block.TryFindKey(key.Span);
var remainder = outputSpan.Length;
ref var pointer = ref MemoryMarshal.GetReference(span);
var currentCrc = (uint)0;
while(remainder >= 4)
{
var uintValue = Unsafe.As<byte, uint>(ref pointer);
currentCrc = System.Runtime.Intrinsics.X86.Sse42.Crc32(currentCrc, uintValue);
pointer = Unsafe.Add(ref pointer, 4);
@Drawaes
Drawaes / log.cs
Created March 31, 2020 23:20
Log Interface
using System;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
namespace RockR.Storage
{
public class WriteAheadLog
{
private Channel<QueueItem> _workQueue = Channel.CreateUnbounded<QueueItem>(new System.Threading.Channels.UnboundedChannelOptions()
private static ReadOnlySpan<byte> NewLine => new byte[] { (byte)'\r', (byte)'\n' };
static void Test()
{
//const ReadOnlySpan<byte> eol = new byte[] { 13, 10 };
var data = new byte[]{72,84,84,80,47,49,46,49,32,50, 48, 48, 32, 79, 75, 13, 10
, 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 116, 101, 120, 116
, 47, 112, 108, 97, 105, 110, 59, 32, 99, 104, 97, 114, 115, 101, 116, 61, 117, 116, 102
, 45, 56, 13 };
var ros = new ReadOnlySequence<byte>(data);
@Drawaes
Drawaes / Loop.cs
Last active January 26, 2020 07:45
private static async Task RunLoopClient(int loopCount)
{
var sw = System.Diagnostics.Stopwatch.StartNew();
var sc = new ServiceCollection();
var sp = sc.BuildServiceProvider();
var client = new ClientBuilder(sp).UseSockets().Build();
await using var connection = await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 7777));
using Bedrock.Framework;
using Bedrock.Framework.Protocols;
using Bedrock.Framework.Transports;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
var host = new WebHostBuilder()
.UseKestrel(options =>
{
options.Listen(new IPEndPoint(IPAddress.Loopback, 5001),
lo => lo.UseTls());
})
.UseLibuv()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
<configuration>
<packageSources>
<add key="dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
<add key="dotnet-corefx" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="aspnet" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
</packageSources>
</configuration>
public static unsafe ushort ReadUShort(ref this ByteBufferReader reader)
{
var firstSpan = reader.UnreadSegment;
ushort returnValue;
if (firstSpan.Length >= 2)
{
returnValue = BinaryPrimitives.ReadUInt16BigEndian(firstSpan);
}
else
{