This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if NETCOREAPP3_1 | |
using System; | |
using System.Linq; | |
using System.Text; | |
using System.Buffers; | |
using NUnit.Framework; | |
using System.Reflection; | |
using System.Buffers.Binary; | |
using static FastExpressionCompiler.LightExpression.Expression; | |
// ReSharper disable InconsistentNaming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if NETCOREAPP3_1 | |
using System; | |
using System.Linq; | |
using System.Text; | |
using System.Buffers; | |
using NUnit.Framework; | |
using System.Reflection; | |
using System.Buffers.Binary; | |
using static FastExpressionCompiler.LightExpression.Expression; | |
// ReSharper disable InconsistentNaming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if NETCOREAPP3_1 | |
using System; | |
using System.Linq; | |
using System.Text; | |
using System.Buffers; | |
using NUnit.Framework; | |
using System.Reflection; | |
using System.Buffers.Binary; | |
using static FastExpressionCompiler.LightExpression.Expression; | |
// ReSharper disable InconsistentNaming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ref struct SpanWriter | |
{ | |
private readonly Span<byte> _buffer; | |
private int _position; | |
public int Remaining => Count - Position; | |
public int Count { get; } | |
public int Position | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DofusFrameDecoder : HeaderFrameDecoder<DofusMetadata> | |
{ | |
protected override bool TryParseHeader(ref SequenceReader<byte> input, out DofusMetadata frame, out int length) | |
{ | |
frame = default; | |
length = 0; | |
if (!input.TryReadBigEndian(out short header)) return false; | |
if (!input.TryReadBigEndian(out int instanceId)) return false; | |
var messageId = header >> 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Provide a thread-safe way to handle immutable objects. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
public static class With<T> | |
{ | |
static With() => Cache.Register(); | |
/// <summary> | |
/// Create a new instance of <see cref="T"/> with the specified property to replace with the provided <see cref="value"/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomVarTests | |
{ | |
private static readonly ISizing Sizing = new SizingBuilder() | |
.Register(new CustomVarInt16SizeStorage()) | |
.Register(new CustomVarUInt16SizeStorage()) | |
.Register(new CustomVarInt32SizeStorage()) | |
.Register(new CustomVarUInt32SizeStorage()) | |
.Register(new CustomVarInt64SizeStorage()) | |
.Register(new CustomVarUInt64SizeStorage()).Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomVarInt16BinaryStorage : IBinaryStorage<CustomVar<short>> | |
{ | |
public Func<IReader, CustomVar<short>> ReadValue => reader => | |
{ | |
var result = 0; | |
for (var offset = 0; offset < 16; offset += 7) | |
{ | |
var readByte = reader.ReadValue<sbyte>(); | |
var hasNext = (readByte & 128) == 128; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Use this strategy to output logs to your console. | |
/// </summary> | |
public class ConsoleOutputStrategy : LoggingStrategy | |
{ | |
private readonly Dictionary<LogLevel, ConsoleColor> _colorWrapper = new Dictionary<LogLevel, ConsoleColor>() | |
{ | |
{LogLevel.Trace, ConsoleColor.DarkGreen }, | |
{LogLevel.Debug, ConsoleColor.Green }, | |
{LogLevel.Info, ConsoleColor.Blue }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public delegate TObj InitializerDlg(); | |
public static Delegate GetDynamicDlg() | |
{ | |
var ctor = typeof(TObj).GetTypeInfo() | |
.DeclaredConstructors | |
.First( | |
c => c.GetParameters().Length < 1); | |
var method = new DynamicMethod( |
NewerOlder