コード例 #1
0
        public byte[] GetBytes()
        {
            var eventTypeBytes = Encoding.UTF8.GetBytes(EventTypeCode);

            byte[] actorIdBytes;
            if (GrainId is long id)
            {
                actorIdBytes = BitConverter.GetBytes(id);
            }
            else if (GrainId is string strId)
            {
                actorIdBytes = Encoding.UTF8.GetBytes(strId);
            }
            else
            {
                throw new PrimaryKeyTypeException(EventTypeCode);
            }
            using var ms = new PooledMemoryStream();
            ms.WriteByte((byte)TransportType.Event);
            ms.Write(BitConverter.GetBytes((ushort)eventTypeBytes.Length));
            ms.Write(BitConverter.GetBytes((ushort)actorIdBytes.Length));
            ms.Write(BitConverter.GetBytes((ushort)BaseBytes.Length));
            ms.Write(BitConverter.GetBytes(EventBytes.Length));
            ms.Write(eventTypeBytes);
            ms.Write(actorIdBytes);
            ms.Write(BaseBytes);
            ms.Write(EventBytes);
            return(ms.ToArray());
        }
コード例 #2
0
ファイル: EventBytesTransport.cs プロジェクト: zszqwe/Ray
 public byte[] GetBytes()
 {
     if (allBytes == default)
     {
         var    eventTypeBytes = Encoding.Default.GetBytes(EventType);
         byte[] actorIdBytes;
         if (ActorId is long id)
         {
             actorIdBytes = BitConverter.GetBytes(id);
         }
         else if (ActorId is string strId)
         {
             actorIdBytes = Encoding.Default.GetBytes(strId);
         }
         else
         {
             throw new PrimaryKeyTypeException(EventType);
         }
         using (var ms = new PooledMemoryStream())
         {
             ms.WriteByte((byte)TransportType.Event);
             ms.Write(BitConverter.GetBytes((ushort)eventTypeBytes.Length));
             ms.Write(BitConverter.GetBytes((ushort)actorIdBytes.Length));
             ms.Write(BitConverter.GetBytes((ushort)BaseBytes.Length));
             ms.Write(BitConverter.GetBytes(EventBytes.Length));
             ms.Write(eventTypeBytes);
             ms.Write(actorIdBytes);
             ms.Write(BaseBytes);
             ms.Write(EventBytes);
             allBytes = ms.ToArray();
         }
     }
     return(allBytes);
 }
コード例 #3
0
        public byte[] GetBytes()
        {
            var eventTypeBytes = Encoding.Default.GetBytes(TypeFullName);

            using var ms = new PooledMemoryStream();
            ms.WriteByte((byte)TransportType.Common);
            ms.Write(BitConverter.GetBytes((ushort)eventTypeBytes.Length));
            ms.Write(Bytes);
            return(ms.ToArray());
        }
コード例 #4
0
        public byte[] GetBytes()
        {
            var eventTypeBytes = Encoding.UTF8.GetBytes(EventTypeCode);
            var eventIdBytes   = Encoding.UTF8.GetBytes(EventId);

            using var ms = new PooledMemoryStream();
            ms.WriteByte((byte)TransportType.Event);
            ms.Write(BitConverter.GetBytes((ushort)eventTypeBytes.Length));
            ms.Write(BitConverter.GetBytes((ushort)eventIdBytes.Length));
            ms.Write(BitConverter.GetBytes(EventBytes.Length));
            ms.Write(eventTypeBytes);
            ms.Write(eventIdBytes);
            ms.Write(EventBytes);
            return(ms.ToArray());
        }
コード例 #5
0
        public static void MemoryStream_WriteByte_BeyondCapacity()
        {
            using (PooledMemoryStream memoryStream = new PooledMemoryStream())
            {
                long   origLength = memoryStream.Length;
                byte[] bytes      = new byte[10];
                for (int i = 0; i < bytes.Length; i++)
                {
                    bytes[i] = (byte)i;
                }
                int spanPastEnd = 5;
                memoryStream.Seek(spanPastEnd, SeekOrigin.End);

                // Test WriteByte
                origLength            = memoryStream.Length;
                memoryStream.Position = memoryStream.Length + spanPastEnd;
                memoryStream.WriteByte(0x42);
                long expected = origLength + spanPastEnd + 1;
                Assert.Equal(expected, memoryStream.Position);
                Assert.Equal(expected, memoryStream.Length);
            }
        }