Пример #1
0
        public static DataPackage UnPack(this DynamicBuffer dynamicBuffer)
        {
            dynamicBuffer.MarkReaderIndex();
            int messageLength = 0;

            if (dynamicBuffer.TryReadInt(ref messageLength))
            {
                int readByteLength = dynamicBuffer.ReadableBytes();
                if (messageLength > readByteLength)
                {
                    dynamicBuffer.ResetReaderIndex();
                    return(null);
                }
                else
                {
                    byte[] messageBytes = new byte[messageLength];
                    dynamicBuffer.ReadBytes(messageBytes, 0, messageLength);
                    dynamicBuffer.DiscardReadBytes();
                    return(DataPackage.Parse(messageBytes));
                }
            }
            return(null);
        }