Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • src
  • Pole.Core
  • EventBus
  • Event
  • EventBase.cs
Find file
BlameHistoryPermalink
  • 丁松杰's avatar
    修改 内部逻辑 · b2ed39db
    丁松杰 committed 5 years ago
    b2ed39db
EventBase.cs 919 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
using Pole.Core.Utils;
using System;
using System.Collections.Generic;
using System.Text;

namespace Pole.Core.EventBus.Event
{
    public class EventBase
    {
        public EventBase() { }
        public EventBase(long version, long timestamp)
        {
            Version = version;
            Timestamp = timestamp;
        }
        public long Version { get; set; }
        public long Timestamp { get; set; }
        public byte[] GetBytes()
        {
            using var ms = new PooledMemoryStream();
            ms.Write(BitConverter.GetBytes(Version));
            ms.Write(BitConverter.GetBytes(Timestamp));
            return ms.ToArray();
        }
        public static EventBase FromBytes(byte[] bytes)
        {
            var bytesSpan = bytes.AsSpan();
            return new EventBase(BitConverter.ToInt64(bytesSpan), BitConverter.ToInt64(bytesSpan.Slice(sizeof(long))));
        }
    }
}