Skip to content

Instantly share code, notes, and snippets.

View lukasz-pyrzyk's full-sized avatar
🏠
Working from home

Łukasz Pyrzyk lukasz-pyrzyk

🏠
Working from home
View GitHub Profile
using System;
using System.Net;
namespace XGain
{
public class StartArgs : EventArgs
{
public StartArgs(ProcessingType processingType, EndPoint localEndpoint)
{
ProcessingType = processingType;
using System;
namespace XGain
{
public class ErrorArgs : EventArgs
{
public ErrorArgs(Exception ex)
{
Date = DateTime.Now;
Exception = ex;
using System;
using XGain.Sockets;
namespace XGain
{
public class MessageArgs : EventArgs
{
public MessageArgs()
{
}
@lukasz-pyrzyk
lukasz-pyrzyk / XGainServer.cs
Last active March 23, 2016 20:51
StartSynchronously
[..]
namespace XGain
{
public class XGainServer : IServer
{
public event EventHandler<StartArgs> OnStart;
public event EventHandler<MessageArgs> OnNewMessage;
public event EventHandler<ErrorArgs> OnError;
private readonly Func<IProcessor<MessageArgs>> _requestProcessorResolver;
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
using ProtoBuf;
namespace Kronos.Core.Requests
{
[ProtoContract]
public enum RequestType : ushort
{
[ProtoEnum]
Unknown = 0,
using ProtoBuf;
namespace Kronos.Core.StatusCodes
{
[ProtoContract]
public enum RequestStatusCode : ushort
{
[ProtoEnum]
Unknown = 0,
[ProtoContract]
public class InsertRequest : Request
{
public override RequestType RequestType { get; set; } = RequestType.Insert;
[ProtoMember(1)]
public string Key { get; set; }
[ProtoMember(2)]
public byte[] Object { get; set; }
[ProtoContract]
[ProtoInclude(500, typeof(InsertRequest))]
public abstract class Request
{
public virtual RequestType RequestType { get; set; }
}
public class SerializationUtils
{
public const PrefixStyle Style = PrefixStyle.Fixed32;
public static int GetLengthOfPackage(byte[] buffer)
{
int size;
Serializer.TryReadLengthPrefix(buffer, 0, buffer.Length, Style, out size);
return size;
}