예제 #1
0
        public static RouterHeader GetHeaderFromBytes(byte[] message)
        {
            var routerHeader = new RouterHeader();

            routerHeader.Type     = (MessageBusType)message[0];
            routerHeader.Priority = message[1];
            var ticks = ((long)message[3]) + ((long)message[4] << 8) + ((long)message[5] << 16)
                        + ((long)message[6] << 24) + ((long)message[7] << 32) + ((long)message[8] << 40)
                        + ((long)message[9] << 48) + ((long)message[10] << 56);

            routerHeader.CreatedAt = new DateTime(ticks);

            var bodyLength = (message[11]) + (message[12] << 8) + (message[13] << 16) + (message[14] << 24);
            var arraybody  = new byte[bodyLength];

            Array.Copy(message, 15, arraybody, 0, bodyLength);
            routerHeader.BodyType = Encoding.UTF8.GetString(arraybody);

            var messagePosition = 15 + bodyLength;

            routerHeader.MessageLength = (message[messagePosition]) + (message[messagePosition + 1] << 8) +
                                         (message[messagePosition + 2] << 16) + (message[messagePosition + 3] << 24);
            routerHeader.MessagePosition = messagePosition + 4;

            routerHeader.Identification = new Identification();

            var idPosition = routerHeader.MessagePosition + routerHeader.MessageLength;
            var idLength   = (message[idPosition]) + (message[idPosition + 1] << 8) + (message[idPosition + 2] << 16) + (message[idPosition + 3] << 24);

            if (idLength > 0)
            {
                var idArray = new byte[idLength];
                Array.Copy(message, idPosition + 4, idArray, 0, idLength);
                routerHeader.Identification.Id = Encoding.UTF8.GetString(idArray);

                var typePosition = idPosition + 4 + idLength;
                var typeLength   = (message[typePosition]) + (message[typePosition + 1] << 8) +
                                   (message[typePosition + 2] << 16) + (message[typePosition + 3] << 24);
                var typeArray = new byte[typeLength];
                Array.Copy(message, typePosition + 4, typeArray, 0, typeLength);
                routerHeader.Identification.Type = Encoding.UTF8.GetString(typeArray);
            }
            return(routerHeader);
        }
예제 #2
0
        public static RouterHeader GetHeaderFromBytes(byte[] message)
        {
            var routerHeader = new RouterHeader();
            routerHeader.Type = (MessageBusType)message[0];
            routerHeader.Priority = message[1];
            var ticks = ((long)message[3]) + ((long)message[4] << 8) + ((long)message[5] << 16)
                         + ((long)message[6] << 24) + ((long)message[7] << 32) + ((long)message[8] << 40)
                         + ((long)message[9] << 48) + ((long)message[10] << 56);
            routerHeader.CreatedAt = new DateTime(ticks);

            var bodyLength = (message[11]) + (message[12] << 8) + (message[13] << 16) + (message[14] << 24);
            var arraybody = new byte[bodyLength];
            Array.Copy(message, 15, arraybody, 0, bodyLength);
            routerHeader.BodyType = Encoding.UTF8.GetString(arraybody);

            var messagePosition = 15 + bodyLength;
            routerHeader.MessageLength = (message[messagePosition]) + (message[messagePosition + 1] << 8) +
                                         (message[messagePosition + 2] << 16) + (message[messagePosition + 3] << 24);
            routerHeader.MessagePosition = messagePosition + 4;

            routerHeader.Identification = new Identification();

            var idPosition = routerHeader.MessagePosition + routerHeader.MessageLength;
            var idLength = (message[idPosition]) + (message[idPosition + 1] << 8) + (message[idPosition + 2] << 16) + (message[idPosition + 3] << 24);
            if (idLength > 0)
            {
                var idArray = new byte[idLength];
                Array.Copy(message, idPosition + 4, idArray, 0, idLength);
                routerHeader.Identification.Id = Encoding.UTF8.GetString(idArray);

                var typePosition = idPosition + 4 + idLength;
                var typeLength = (message[typePosition] ) + (message[typePosition + 1] << 8) +
                                 (message[typePosition + 2] << 16) + (message[typePosition + 3] << 24);
                var typeArray = new byte[typeLength];
                Array.Copy(message, typePosition + 4, typeArray, 0, typeLength);
                routerHeader.Identification.Type = Encoding.UTF8.GetString(typeArray);
            }
            return routerHeader;
        }