// <auto-generated/>

namespace MyTelegram.Services.Serializers;
// Count:81
// MyTelegram.Core
public class AcksDataReceivedEventEventDataSerializer : IEventDataSerializer<AcksDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AcksDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public AcksDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new AcksDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class AppCodeCreatedIntegrationEventEventDataSerializer : IEventDataSerializer<AppCodeCreatedIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AppCodeCreatedIntegrationEvent data)
    {
        writer.Write(data.UserId);
        writer.WriteString(data.PhoneNumber);
        writer.WriteString(data.Code);
        writer.Write(data.Expire);
    }

    public AppCodeCreatedIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var phoneNumber = buffer.ReadString2() ?? string.Empty;
        var code = buffer.ReadString2() ?? string.Empty;
        var expire = buffer.ReadInt32();

        return new AppCodeCreatedIntegrationEvent(userId, phoneNumber, code, expire );
    }
}

public class AuthCacheItemEventDataSerializer : IEventDataSerializer<AuthCacheItem>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AuthCacheItem data)
    {
        writer.Write(data.Nonce);
        writer.Write(data.ServerNonce);
        writer.Write(data.P);
        writer.Write(data.Q);
        writer.WriteBool(data.IsPermanent);
        writer.Write(data.NewNonce);
        writer.Write(data.A);
        writer.Write(data.Ga);
        writer.Write(data.DcId);
    }

    public AuthCacheItem Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var nonce = buffer.ReadBytes();
        var serverNonce = buffer.ReadBytes();
        var p = buffer.ReadBytes();
        var q = buffer.ReadBytes();
        var isPermanent = buffer.ReadBoolean();
        var newNonce = buffer.ReadBytes();
        var a = buffer.ReadBytes();
        var ga = buffer.ReadBytes();
        var dcId = buffer.ReadNullableInt32();

        return new AuthCacheItem(nonce, serverNonce, p, q, isPermanent, newNonce, a, ga, dcId );
    }
}

public class AuthKeyCacheItemEventDataSerializer : IEventDataSerializer<AuthKeyCacheItem>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AuthKeyCacheItem data)
    {
        writer.Write(data.AuthKeyData);
        writer.Write(data.ServerSalt);
        writer.WriteBool(data.IsPermanent);
        writer.Write(data.UserId);
    }

    public AuthKeyCacheItem Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyData = buffer.ReadBytes();
        var serverSalt = buffer.ReadInt64();
        var isPermanent = buffer.ReadBoolean();
        var userId = buffer.ReadInt64();

        return new AuthKeyCacheItem(authKeyData, serverSalt, isPermanent, userId );
    }
}

public class AuthKeyCreatedIntegrationEventEventDataSerializer : IEventDataSerializer<AuthKeyCreatedIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AuthKeyCreatedIntegrationEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.Data);
        writer.Write(data.ServerSalt);
        writer.WriteBool(data.IsPermanent);
        writer.Write(data.SetClientDhParamsAnswer);
        writer.Write(data.DcId);
    }

    public AuthKeyCreatedIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var reqMsgId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var serverSalt = buffer.ReadInt64();
        var isPermanent = buffer.ReadBoolean();
        var setClientDhParamsAnswer = buffer.ReadMemory();
        var dcId = buffer.ReadNullableInt32();

        var rentLength = data.Length + setClientDhParamsAnswer.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);
        var setClientDhParamsAnswerMemory = memory.Slice(0, setClientDhParamsAnswer.Length);
        setClientDhParamsAnswer.CopyTo(setClientDhParamsAnswerMemory);
        setClientDhParamsAnswer = setClientDhParamsAnswerMemory;
        memory = memory.Slice(setClientDhParamsAnswer.Length);

        return new AuthKeyCreatedIntegrationEvent(connectionId, reqMsgId, data, serverSalt, isPermanent, setClientDhParamsAnswer, dcId )
        {
            MemoryOwner = owner
        };
    }
}

public class AuthKeyNotFoundEventEventDataSerializer : IEventDataSerializer<AuthKeyNotFoundEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AuthKeyNotFoundEvent data)
    {
        writer.Write(data.AuthKeyId);
        writer.WriteString(data.ConnectionId);
    }

    public AuthKeyNotFoundEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var connectionId = buffer.ReadString2() ?? string.Empty;

        return new AuthKeyNotFoundEvent(authKeyId, connectionId );
    }
}

public class AuthKeyUnRegisteredIntegrationEventEventDataSerializer : IEventDataSerializer<AuthKeyUnRegisteredIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, AuthKeyUnRegisteredIntegrationEvent data)
    {
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.TempAuthKeyId);
    }

    public AuthKeyUnRegisteredIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var permAuthKeyId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();

        return new AuthKeyUnRegisteredIntegrationEvent(permAuthKeyId, tempAuthKeyId );
    }
}

public class BindUidToAuthKeyIntegrationEventEventDataSerializer : IEventDataSerializer<BindUserIdToAuthKeyIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, BindUserIdToAuthKeyIntegrationEvent data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
    }

    public BindUserIdToAuthKeyIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();

        return new BindUserIdToAuthKeyIntegrationEvent(authKeyId, permAuthKeyId, userId );
    }
}

public class BindUidToSessionEventEventDataSerializer : IEventDataSerializer<BindUserIdToSessionEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, BindUserIdToSessionEvent data)
    {
        writer.Write(data.UserId);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
    }

    public BindUserIdToSessionEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();

        return new BindUserIdToSessionEvent(userId, authKeyId, permAuthKeyId );
    }
}

public class BindUserIdToAuthKeySuccessEventEventDataSerializer : IEventDataSerializer<BindUserIdToAuthKeySuccessEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, BindUserIdToAuthKeySuccessEvent data)
    {
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
    }

    public BindUserIdToAuthKeySuccessEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();

        return new BindUserIdToAuthKeySuccessEvent(tempAuthKeyId, permAuthKeyId, userId );
    }
}

public class ChannelMemberBannedEventEventDataSerializer : IEventDataSerializer<ChannelMemberBannedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, ChannelMemberBannedEvent data)
    {
        writer.Write(data.ChannelId);
        writer.Write(data.UserId);
        writer.Write(data.BannedRights);
        writer.Write(data.UntilDate);
    }

    public ChannelMemberBannedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var channelId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();
        var bannedRights = buffer.ReadInt32();
        var untilDate = buffer.ReadInt32();

        return new ChannelMemberBannedEvent(channelId, userId, bannedRights, untilDate );
    }
}

public class ChannelMemberChangedEventEventDataSerializer : IEventDataSerializer<ChannelMemberChangedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, ChannelMemberChangedEvent data)
    {
        writer.Write(data.ChannelId);
        writer.Write((byte)data.MemberStateChangeType);
        writer.Write(data.MemberUidList);
    }

    public ChannelMemberChangedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var channelId = buffer.ReadInt64();
        var memberStateChangeType = (MemberStateChangeType)buffer.ReadByte();
        var memberUidList = buffer.ReadList();

        return new ChannelMemberChangedEvent(channelId, memberStateChangeType, memberUidList );
    }
}

public class ChatMemberChangedEventEventDataSerializer : IEventDataSerializer<ChatMemberChangedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, ChatMemberChangedEvent data)
    {
        writer.Write(data.ChatId);
        writer.Write((byte)data.MemberStateChangeType);
        writer.Write(data.MemberUidList);
    }

    public ChatMemberChangedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var chatId = buffer.ReadInt64();
        var memberStateChangeType = (MemberStateChangeType)buffer.ReadByte();
        var memberUidList = buffer.ReadList();

        return new ChatMemberChangedEvent(chatId, memberStateChangeType, memberUidList );
    }
}

public class ClientDisconnectedEventEventDataSerializer : IEventDataSerializer<ClientDisconnectedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, ClientDisconnectedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.AuthKeyId);
        writer.Write(data.SessionId);
    }

    public ClientDisconnectedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var authKeyId = buffer.ReadInt64();
        var sessionId = buffer.ReadInt64();

        return new ClientDisconnectedEvent(connectionId, authKeyId, sessionId );
    }
}

public class CreateEncryptedPushMessageEventEventDataSerializer : IEventDataSerializer<CreateEncryptedPushMessageEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, CreateEncryptedPushMessageEvent data)
    {
        writer.Write(data.InboxOwnerPeerId);
        writer.Write(data.Data);
        writer.Write(data.Qts);
        writer.Write(data.InboxOwnerPermAuthKeyId);
    }

    public CreateEncryptedPushMessageEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var inboxOwnerPeerId = buffer.ReadInt64();
        var data = buffer.ReadBytes();
        var qts = buffer.ReadInt32();
        var inboxOwnerPermAuthKeyId = buffer.ReadInt64();

        return new CreateEncryptedPushMessageEvent(inboxOwnerPeerId, data, qts, inboxOwnerPermAuthKeyId );
    }
}

public class CreatePushMessageEventEventDataSerializer : IEventDataSerializer<CreatePushMessageEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, CreatePushMessageEvent data)
    {
        writer.Write(data.ToPeer);
        writer.Write(data.Data);
        writer.Write(data.Pts);
        writer.Write(data.OnlyPushToThisAuthKeyId);
    }

    public CreatePushMessageEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var toPeer = buffer.ReadPeer();
        var data = buffer.ReadBytes();
        var pts = buffer.ReadInt32();
        var onlyPushToThisAuthKeyId = buffer.ReadInt64();

        return new CreatePushMessageEvent(toPeer, data, pts, onlyPushToThisAuthKeyId );
    }
}

public class DataReceivedEventEventDataSerializer : IEventDataSerializer<DataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public DataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new DataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class DataResultResponseReceivedEventEventDataSerializer : IEventDataSerializer<DataResultResponseReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DataResultResponseReceivedEvent data)
    {
        writer.Write(data.ReqMsgId);
        writer.Write(data.Data);
    }

    public DataResultResponseReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var reqMsgId = buffer.ReadInt64();
        var data = buffer.ReadMemory();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new DataResultResponseReceivedEvent(reqMsgId, data )
        {
            MemoryOwner = owner
        };
    }
}

public class DataResultResponseWithUserIdReceivedEventEventDataSerializer : IEventDataSerializer<DataResultResponseWithUserIdReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DataResultResponseWithUserIdReceivedEvent data)
    {
        writer.Write(data.ReqMsgId);
        writer.Write(data.Data);
        writer.Write(data.UserId);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
    }

    public DataResultResponseWithUserIdReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var reqMsgId = buffer.ReadInt64();
        var data = buffer.ReadBytes();
        var userId = buffer.ReadInt64();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();

        return new DataResultResponseWithUserIdReceivedEvent(reqMsgId, data, userId, authKeyId, permAuthKeyId );
    }
}

public class DeviceRegisteredEventEventDataSerializer : IEventDataSerializer<DeviceRegisteredEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DeviceRegisteredEvent data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.SessionId);
    }

    public DeviceRegisteredEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var sessionId = buffer.ReadInt64();

        return new DeviceRegisteredEvent(authKeyId, permAuthKeyId, sessionId );
    }
}

public class DomainEventMessageEventDataSerializer : IEventDataSerializer<DomainEventMessage>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DomainEventMessage data)
    {
        writer.WriteString(data.EventId);
        writer.WriteString(data.Message);
        writer.Write(data.Headers);
    }

    public DomainEventMessage Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var eventId = buffer.ReadString2() ?? string.Empty;
        var message = buffer.ReadString2() ?? string.Empty;
        var headers = buffer.ReadDictionary();

        return new DomainEventMessage(eventId, message, headers );
    }
}

public class DownloadDataReceivedEventEventDataSerializer : IEventDataSerializer<DownloadDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DownloadDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public DownloadDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new DownloadDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class DuplicateCommandEventEventDataSerializer : IEventDataSerializer<DuplicateCommandEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, DuplicateCommandEvent data)
    {
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
    }

    public DuplicateCommandEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();

        return new DuplicateCommandEvent(permAuthKeyId, userId, reqMsgId );
    }
}

public class FileDataResultResponseReceivedEventEventDataSerializer : IEventDataSerializer<FileDataResultResponseReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, FileDataResultResponseReceivedEvent data)
    {
        writer.Write(data.ReqMsgId);
        writer.Write(data.Data);
    }

    public FileDataResultResponseReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var reqMsgId = buffer.ReadInt64();
        var data = buffer.ReadMemory();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new FileDataResultResponseReceivedEvent(reqMsgId, data )
        {
            MemoryOwner = owner
        };
    }
}

public class FutureAuthTokenCacheItemEventDataSerializer : IEventDataSerializer<FutureAuthTokenCacheItem>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, FutureAuthTokenCacheItem data)
    {
        writer.Write(data.UserId);
        writer.WriteString(data.AuthTokenId);
    }

    public FutureAuthTokenCacheItem Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var authTokenId = buffer.ReadString2() ?? string.Empty;

        return new FutureAuthTokenCacheItem(userId, authTokenId );
    }
}

public class FutureSaltCacheItemEventDataSerializer : IEventDataSerializer<FutureSaltCacheItem>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, FutureSaltCacheItem data)
    {
        writer.Write(data.Salt);
        writer.Write(data.ValidSince);
        writer.Write(data.ValidUntil);
    }

    public FutureSaltCacheItem Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var salt = buffer.ReadInt64();
        var validSince = buffer.ReadInt32();
        var validUntil = buffer.ReadInt32();

        return new FutureSaltCacheItem(salt, validSince, validUntil );
    }
}

public class GlobalPrivacySettingsCacheItemEventDataSerializer : IEventDataSerializer<GlobalPrivacySettingsCacheItem>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, GlobalPrivacySettingsCacheItem data)
    {
        writer.WriteBool(data.ArchiveAndMuteNewNoncontactPeers);
        writer.WriteBool(data.KeepArchivedUnmuted);
        writer.WriteBool(data.KeepArchivedFolders);
        writer.WriteBool(data.HideReadMarks);
        writer.WriteBool(data.NewNoncontactPeersRequirePremium);
    }

    public GlobalPrivacySettingsCacheItem Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var archiveAndMuteNewNoncontactPeers = buffer.ReadBoolean();
        var keepArchivedUnmuted = buffer.ReadBoolean();
        var keepArchivedFolders = buffer.ReadBoolean();
        var hideReadMarks = buffer.ReadBoolean();
        var newNoncontactPeersRequirePremium = buffer.ReadBoolean();

        return new GlobalPrivacySettingsCacheItem(archiveAndMuteNewNoncontactPeers, keepArchivedUnmuted, keepArchivedFolders, hideReadMarks, newNoncontactPeersRequirePremium );
    }
}

public class LayeredAuthKeyIdMessageCreatedIntegrationEventEventDataSerializer : IEventDataSerializer<LayeredAuthKeyIdMessageCreatedIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, LayeredAuthKeyIdMessageCreatedIntegrationEvent data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Pts);
        writer.Write(data.Qts);
        writer.Write(data.GlobalSeqNo);
    }

    public LayeredAuthKeyIdMessageCreatedIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var pts = buffer.ReadInt32();
        var qts = buffer.ReadNullableInt32();
        var globalSeqNo = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new LayeredAuthKeyIdMessageCreatedIntegrationEvent(authKeyId, data, pts, qts, globalSeqNo )
        {
            MemoryOwner = owner
        };
    }
}

public class LayeredPushMessageCreatedIntegrationEventEventDataSerializer : IEventDataSerializer<LayeredPushMessageCreatedIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, LayeredPushMessageCreatedIntegrationEvent data)
    {
        writer.Write((byte)data.PeerType);
        writer.Write(data.PeerId);
        writer.Write(data.Data);
        writer.Write(data.ExcludeAuthKeyId);
        writer.Write(data.ExcludeUserId);
        writer.Write(data.OnlySendToUserId);
        writer.Write(data.OnlySendToThisAuthKeyId);
        writer.Write(data.Pts);
        writer.Write(data.Qts);
        writer.Write(data.GlobalSeqNo);
        writer.Write(data.PushData);
        writer.Write(data.ExcludeUserIds);
    }

    public LayeredPushMessageCreatedIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var peerType = (PeerType)buffer.ReadByte();
        var peerId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var excludeAuthKeyId = buffer.ReadNullableInt64();
        var excludeUserId = buffer.ReadNullableInt64();
        var onlySendToUserId = buffer.ReadNullableInt64();
        var onlySendToThisAuthKeyId = buffer.ReadNullableInt64();
        var pts = buffer.ReadInt32();
        var qts = buffer.ReadNullableInt32();
        var globalSeqNo = buffer.ReadInt64();
        var pushData = buffer.ReadPushData();
        var excludeUserIds = buffer.ReadList();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new LayeredPushMessageCreatedIntegrationEvent(peerType, peerId, data, excludeAuthKeyId, excludeUserId, onlySendToUserId, onlySendToThisAuthKeyId, pts, qts, globalSeqNo, pushData, excludeUserIds )
        {
            MemoryOwner = owner
        };
    }
}

public class MessengerCommandDataReceivedEventEventDataSerializer : IEventDataSerializer<MessengerCommandDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, MessengerCommandDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public MessengerCommandDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new MessengerCommandDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class MessengerDataReceivedEventEventDataSerializer : IEventDataSerializer<MessengerDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, MessengerDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public MessengerDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new MessengerDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class MessengerQueryDataReceivedEventEventDataSerializer : IEventDataSerializer<MessengerQueryDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, MessengerQueryDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public MessengerQueryDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new MessengerQueryDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class NewDeviceCreatedEventEventDataSerializer : IEventDataSerializer<NewDeviceCreatedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, NewDeviceCreatedEvent data)
    {
        writer.Write(data.RequestInfo);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.UserId);
        writer.Write(data.ApiId);
        writer.WriteString(data.AppName);
        writer.WriteString(data.AppVersion);
        writer.Write(data.Hash);
        writer.WriteBool(data.OfficialApp);
        writer.WriteBool(data.PasswordPending);
        writer.WriteString(data.DeviceModel);
        writer.WriteString(data.Platform);
        writer.WriteString(data.SystemVersion);
        writer.WriteString(data.SystemLangCode);
        writer.WriteString(data.LangPack);
        writer.WriteString(data.LangCode);
        writer.WriteString(data.Ip);
        writer.Write(data.Layer);
        writer.Write(data.Parameters);
    }

    public NewDeviceCreatedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var requestInfo = buffer.ReadRequestInfo();
        var permAuthKeyId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();
        var apiId = buffer.ReadInt32();
        var appName = buffer.ReadString2() ?? string.Empty;
        var appVersion = buffer.ReadString2() ?? string.Empty;
        var hash = buffer.ReadInt64();
        var officialApp = buffer.ReadBoolean();
        var passwordPending = buffer.ReadBoolean();
        var deviceModel = buffer.ReadString2() ?? string.Empty;
        var platform = buffer.ReadString2() ?? string.Empty;
        var systemVersion = buffer.ReadString2() ?? string.Empty;
        var systemLangCode = buffer.ReadString2() ?? string.Empty;
        var langPack = buffer.ReadString2() ?? string.Empty;
        var langCode = buffer.ReadString2() ?? string.Empty;
        var ip = buffer.ReadString2() ?? string.Empty;
        var layer = buffer.ReadInt32();
        var parameters = buffer.ReadDictionary();

        return new NewDeviceCreatedEvent(requestInfo, permAuthKeyId, tempAuthKeyId, userId, apiId, appName, appVersion, hash, officialApp, passwordPending, deviceModel, platform, systemVersion, systemLangCode, langPack, langCode, ip, layer, parameters );
    }
}

public class NewPtsMessageHasSentEventEventDataSerializer : IEventDataSerializer<NewPtsMessageHasSentEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, NewPtsMessageHasSentEvent data)
    {
        writer.Write(data.UserId);
        writer.Write(data.ToPeer);
        writer.Write(data.MsgId);
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Pts);
        writer.Write(data.GlobalSeqNo);
        writer.Write(data.ReqMsgId);
    }

    public NewPtsMessageHasSentEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var toPeer = buffer.ReadPeer();
        var msgId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var pts = buffer.ReadInt32();
        var globalSeqNo = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();

        return new NewPtsMessageHasSentEvent(userId, toPeer, msgId, tempAuthKeyId, permAuthKeyId, pts, globalSeqNo, reqMsgId );
    }
}

public class NewQtsMessageHasSentEventEventDataSerializer : IEventDataSerializer<NewQtsMessageHasSentEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, NewQtsMessageHasSentEvent data)
    {
        writer.Write(data.UserId);
        writer.Write(data.ToPeer);
        writer.Write(data.MsgId);
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Qts);
        writer.Write(data.GlobalSeqNo);
        writer.Write(data.ReqMsgId);
    }

    public NewQtsMessageHasSentEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var toPeer = buffer.ReadPeer();
        var msgId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var qts = buffer.ReadInt32();
        var globalSeqNo = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();

        return new NewQtsMessageHasSentEvent(userId, toPeer, msgId, tempAuthKeyId, permAuthKeyId, qts, globalSeqNo, reqMsgId );
    }
}

public class PingTimeoutEventEventDataSerializer : IEventDataSerializer<PingTimeoutEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, PingTimeoutEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.AuthKeyId);
    }

    public PingTimeoutEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var authKeyId = buffer.ReadInt64();

        return new PingTimeoutEvent(connectionId, authKeyId );
    }
}

public class PushDataReceivedEventEventDataSerializer : IEventDataSerializer<PushDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, PushDataReceivedEvent data)
    {
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
    }

    public PushDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new PushDataReceivedEvent(objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer )
        {
            MemoryOwner = owner
        };
    }
}

public class PushMessageToPeerEventEventDataSerializer : IEventDataSerializer<PushMessageToPeerEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, PushMessageToPeerEvent data)
    {
        writer.Write(data.PeerType);
        writer.Write(data.PeerId);
        writer.Write(data.Data);
        writer.Write(data.ExcludeAuthKeyId);
        writer.Write(data.ExcludeUid);
        writer.Write(data.OnlySendToThisAuthKeyId);
        writer.Write(data.Pts);
        writer.Write(data.GlobalSeqNo);
    }

    public PushMessageToPeerEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var peerType = buffer.ReadInt32();
        var peerId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var excludeAuthKeyId = buffer.ReadInt64();
        var excludeUid = buffer.ReadInt64();
        var onlySendToThisAuthKeyId = buffer.ReadInt64();
        var pts = buffer.ReadInt32();
        var globalSeqNo = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new PushMessageToPeerEvent(peerType, peerId, data, excludeAuthKeyId, excludeUid, onlySendToThisAuthKeyId, pts, globalSeqNo )
        {
            MemoryOwner = owner
        };
    }
}

public class PushNotificationCreatedEventEventDataSerializer : IEventDataSerializer<PushNotificationCreatedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, PushNotificationCreatedEvent data)
    {
        writer.Write(data.Data);
    }

    public PushNotificationCreatedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var data = buffer.ReadPushData();

        return new PushNotificationCreatedEvent(data );
    }
}

public class RpcMessageHasSentEventEventDataSerializer : IEventDataSerializer<RpcMessageHasSentEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, RpcMessageHasSentEvent data)
    {
        writer.Write(data.ReqMsgId);
        writer.Write(data.UserId);
        writer.Write(data.MsgId);
        writer.Write(data.GlobalSeqNo);
    }

    public RpcMessageHasSentEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var reqMsgId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();
        var msgId = buffer.ReadInt64();
        var globalSeqNo = buffer.ReadInt64();

        return new RpcMessageHasSentEvent(reqMsgId, userId, msgId, globalSeqNo );
    }
}

public class SessionPasswordStateChangedEventEventDataSerializer : IEventDataSerializer<SessionPasswordStateChangedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, SessionPasswordStateChangedEvent data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write((byte)data.PasswordState);
    }

    public SessionPasswordStateChangedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var passwordState = (PasswordState)buffer.ReadByte();

        return new SessionPasswordStateChangedEvent(authKeyId, passwordState );
    }
}

public class SessionRevokedEventEventDataSerializer : IEventDataSerializer<SessionRevokedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, SessionRevokedEvent data)
    {
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
        writer.Write(data.RevokedPermAuthKeyIdList);
    }

    public SessionRevokedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();
        var revokedPermAuthKeyIdList = buffer.ReadList();

        return new SessionRevokedEvent(permAuthKeyId, userId, revokedPermAuthKeyIdList );
    }
}

public class SetSessionPasswordStateEventEventDataSerializer : IEventDataSerializer<SetSessionPasswordStateEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, SetSessionPasswordStateEvent data)
    {
        writer.Write(data.UserId);
        writer.Write((byte)data.PasswordState);
    }

    public SetSessionPasswordStateEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var passwordState = (PasswordState)buffer.ReadByte();

        return new SetSessionPasswordStateEvent(userId, passwordState );
    }
}

public class StickerDataReceivedEventEventDataSerializer : IEventDataSerializer<StickerDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, StickerDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public StickerDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new StickerDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class TakeoutCacheItemEventDataSerializer : IEventDataSerializer<TakeoutCacheItem>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, TakeoutCacheItem data)
    {
        writer.WriteBool(data.Contacts);
        writer.WriteBool(data.MessageUsers);
        writer.WriteBool(data.MessageChats);
        writer.WriteBool(data.MessageMegagroups);
        writer.WriteBool(data.MessageChannels);
        writer.WriteBool(data.Files);
        writer.Write(data.FileMaxSize);
    }

    public TakeoutCacheItem Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var contacts = buffer.ReadBoolean();
        var messageUsers = buffer.ReadBoolean();
        var messageChats = buffer.ReadBoolean();
        var messageMegagroups = buffer.ReadBoolean();
        var messageChannels = buffer.ReadBoolean();
        var files = buffer.ReadBoolean();
        var fileMaxSize = buffer.ReadNullableInt64();

        return new TakeoutCacheItem(contacts, messageUsers, messageChats, messageMegagroups, messageChannels, files, fileMaxSize );
    }
}

public class TransportErrorEventEventDataSerializer : IEventDataSerializer<TransportErrorEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, TransportErrorEvent data)
    {
        writer.Write(data.AuthKeyId);
        writer.WriteString(data.ConnectionId);
        writer.Write(data.TransportErrorCode);
    }

    public TransportErrorEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var transportErrorCode = buffer.ReadInt32();

        return new TransportErrorEvent(authKeyId, connectionId, transportErrorCode );
    }
}

public class UnRegisterAuthKeyEventEventDataSerializer : IEventDataSerializer<UnRegisterAuthKeyEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UnRegisterAuthKeyEvent data)
    {
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
    }

    public UnRegisterAuthKeyEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();

        return new UnRegisterAuthKeyEvent(permAuthKeyId, userId );
    }
}

public class UpdatesDataReceivedEventEventDataSerializer : IEventDataSerializer<UpdatesDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UpdatesDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public UpdatesDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new UpdatesDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class UploadDataReceivedEventEventDataSerializer : IEventDataSerializer<UploadDataReceivedEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UploadDataReceivedEvent data)
    {
        writer.WriteString(data.ConnectionId);
        writer.Write(data.RequestId);
        writer.Write(data.ObjectId);
        writer.Write(data.UserId);
        writer.Write(data.ReqMsgId);
        writer.Write(data.SeqNumber);
        writer.Write(data.AuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.Data);
        writer.Write(data.Layer);
        writer.Write(data.Date);
        writer.Write((byte)data.DeviceType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.SessionId);
        writer.Write(data.AccessHashKeyId);
    }

    public UploadDataReceivedEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var objectId = buffer.ReadUInt32();
        var userId = buffer.ReadInt64();
        var reqMsgId = buffer.ReadInt64();
        var seqNumber = buffer.ReadInt32();
        var authKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var layer = buffer.ReadInt32();
        var date = buffer.ReadInt64();
        var deviceType = (DeviceType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var sessionId = buffer.ReadInt64();
        var accessHashKeyId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new UploadDataReceivedEvent(connectionId, requestId, objectId, userId, reqMsgId, seqNumber, authKeyId, permAuthKeyId, data, layer, date, deviceType, clientIp, sessionId, accessHashKeyId )
        {
            MemoryOwner = owner
        };
    }
}

public class UserIsOnlineEventEventDataSerializer : IEventDataSerializer<UserIsOnlineEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UserIsOnlineEvent data)
    {
        writer.Write(data.UserId);
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
    }

    public UserIsOnlineEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();

        return new UserIsOnlineEvent(userId, tempAuthKeyId, permAuthKeyId );
    }
}

public class UserLoggedOutEventEventDataSerializer : IEventDataSerializer<UserLoggedOutEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UserLoggedOutEvent data)
    {
        writer.Write(data.UserId);
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
    }

    public UserLoggedOutEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var userId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();

        return new UserLoggedOutEvent(userId, tempAuthKeyId, permAuthKeyId );
    }
}

public class UserSignInSuccessEventEventDataSerializer : IEventDataSerializer<UserSignInSuccessEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UserSignInSuccessEvent data)
    {
        writer.Write(data.ReqMsgId);
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
        writer.Write((byte)data.PasswordState);
        writer.WriteBool(data.SendRpcErrorToClient);
    }

    public UserSignInSuccessEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var reqMsgId = buffer.ReadInt64();
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();
        var passwordState = (PasswordState)buffer.ReadByte();
        var sendRpcErrorToClient = buffer.ReadBoolean();

        return new UserSignInSuccessEvent(reqMsgId, tempAuthKeyId, permAuthKeyId, userId, passwordState, sendRpcErrorToClient );
    }
}

public class UserSignUpSuccessIntegrationEventEventDataSerializer : IEventDataSerializer<UserSignUpSuccessIntegrationEvent>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UserSignUpSuccessIntegrationEvent data)
    {
        writer.Write(data.TempAuthKeyId);
        writer.Write(data.PermAuthKeyId);
        writer.Write(data.UserId);
    }

    public UserSignUpSuccessIntegrationEvent Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var tempAuthKeyId = buffer.ReadInt64();
        var permAuthKeyId = buffer.ReadInt64();
        var userId = buffer.ReadInt64();

        return new UserSignUpSuccessIntegrationEvent(tempAuthKeyId, permAuthKeyId, userId );
    }
}

// MyTelegram.Abstractions
public class EncryptedMessageEventDataSerializer : IEventDataSerializer<EncryptedMessage>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, EncryptedMessage data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write(data.MsgKey);
        writer.Write(data.EncryptedData);
        writer.WriteString(data.ConnectionId);
        writer.Write((byte)data.ConnectionType);
        writer.WriteString(data.ClientIp);
        writer.Write(data.RequestId);
        writer.Write(data.Date);
    }

    public EncryptedMessage Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var msgKey = buffer.ReadMemory();
        var encryptedData = buffer.ReadMemory();
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var connectionType = (ConnectionType)buffer.ReadByte();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var requestId = buffer.ReadGuid();
        var date = buffer.ReadInt64();

        var rentLength = msgKey.Length + encryptedData.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var msgKeyMemory = memory.Slice(0, msgKey.Length);
        msgKey.CopyTo(msgKeyMemory);
        msgKey = msgKeyMemory;
        memory = memory.Slice(msgKey.Length);
        var encryptedDataMemory = memory.Slice(0, encryptedData.Length);
        encryptedData.CopyTo(encryptedDataMemory);
        encryptedData = encryptedDataMemory;
        memory = memory.Slice(encryptedData.Length);

        return new EncryptedMessage(authKeyId, msgKey, encryptedData, connectionId, connectionType, clientIp, requestId, date )
        {
            MemoryOwner = owner
        };
    }
}

public class EncryptedMessageResponseEventDataSerializer : IEventDataSerializer<EncryptedMessageResponse>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, EncryptedMessageResponse data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write(data.Data);
        writer.WriteString(data.ConnectionId);
        writer.Write(data.SeqNumber);
    }

    public EncryptedMessageResponse Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var seqNumber = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new EncryptedMessageResponse(authKeyId, data, connectionId, seqNumber )
        {
            MemoryOwner = owner
        };
    }
}

public class UnencryptedMessageEventDataSerializer : IEventDataSerializer<UnencryptedMessage>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UnencryptedMessage data)
    {
        writer.Write(data.AuthKeyId);
        writer.WriteString(data.ClientIp);
        writer.WriteString(data.ConnectionId);
        writer.Write((byte)data.ConnectionType);
        writer.Write(data.MessageData);
        writer.Write(data.MessageDataLength);
        writer.Write(data.MessageId);
        writer.Write(data.ObjectId);
        writer.Write(data.RequestId);
        writer.Write(data.Date);
    }

    public UnencryptedMessage Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var clientIp = buffer.ReadString2() ?? string.Empty;
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var connectionType = (ConnectionType)buffer.ReadByte();
        var messageData = buffer.ReadMemory();
        var messageDataLength = buffer.ReadInt32();
        var messageId = buffer.ReadInt64();
        var objectId = buffer.ReadUInt32();
        var requestId = buffer.ReadGuid();
        var date = buffer.ReadInt64();

        var rentLength = messageData.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var messageDataMemory = memory.Slice(0, messageData.Length);
        messageData.CopyTo(messageDataMemory);
        messageData = messageDataMemory;
        memory = memory.Slice(messageData.Length);

        return new UnencryptedMessage(authKeyId, clientIp, connectionId, connectionType, messageData, messageDataLength, messageId, objectId, requestId, date )
        {
            MemoryOwner = owner
        };
    }
}

public class UnencryptedMessageResponseEventDataSerializer : IEventDataSerializer<UnencryptedMessageResponse>, ITransientDependency
{
    public object Deserialize(Type type, ReadOnlyMemory<byte> buffer)
    {
        return Deserialize(buffer);
    }
    public void Serialize(IBufferWriter<byte> writer, UnencryptedMessageResponse data)
    {
        writer.Write(data.AuthKeyId);
        writer.Write(data.Data);
        writer.WriteString(data.ConnectionId);
        writer.Write(data.ReqMsgId);
    }

    public UnencryptedMessageResponse Deserialize(ReadOnlyMemory<byte> buffer)
    {
        var authKeyId = buffer.ReadInt64();
        var data = buffer.ReadMemory();
        var connectionId = buffer.ReadString2() ?? string.Empty;
        var reqMsgId = buffer.ReadInt64();

        var rentLength = data.Length;
        var owner = MemoryPool<byte>.Shared.Rent(rentLength);
        var memory = owner.Memory.Slice(0, rentLength);
        var dataMemory = memory.Slice(0, data.Length);
        data.CopyTo(dataMemory);
        data = dataMemory;
        memory = memory.Slice(data.Length);

        return new UnencryptedMessageResponse(authKeyId, data, connectionId, reqMsgId )
        {
            MemoryOwner = owner
        };
    }
}

