예제 #1
0
        /// <summary>
        ///     Returns a specific instance e.g. a MetaFrame, Key- or DeltaFrame.
        /// </summary>
        /// <param name="networkMessageHeader">The NetworkMessageHeader which was already parsed from the input stream.</param>
        /// <param name="inputStream">The input stream which should be parsed.</param>
        /// <param name="writerID">
        ///     Optionally the original WriterID. This is only required when a chunked DataFrame is parsed,
        ///     because it does not contain the real WriterID.
        /// </param>
        /// <returns>
        ///     Either a <c>MetaFrame</c>, <c>KeyFrame</c> or <c>DeltaFrame</c> if the message could be parsed successfully or
        ///     <c>null</c> if the binary message could not be parsed.
        /// </returns>
        private NetworkMessage GetSpecificMessage(NetworkMessageHeader networkMessageHeader, Stream inputStream, ushort?writerID = null)
        {
            NetworkMessage parsedMessage = null;

            switch (networkMessageHeader.ExtendedFlags2.MessageType)
            {
            case MessageType.DiscoveryResponse:
                Logger.Debug("ParsePayload - Discovery Response");
                parsedMessage = ParseMetaFrame(inputStream, networkMessageHeader, Options);
                break;

            case MessageType.DataSetMessage:
                Logger.Debug("ParsePayload - DataSetMessage");
                DataFrame dataFrame = null;
                if (writerID != null)
                {
                    // If a writeID is present we have a chunked message,
                    // and we must not try to parse the Header, because there's no
                    // header in case of a chunked DataSetMessage.
                    dataFrame = new DataFrame();
                    if (!DataFrame.DecodeChunk(inputStream, ref dataFrame))
                    {
                        Logger.Error($"Unable to decode chunked DataFrame: {dataFrame}.");
                        return(null);
                    }
                    dataFrame.PayloadHeader.DataSetWriterID = new[] { writerID.Value };
                }
                else
                {
                    dataFrame = DataFrame.Decode(inputStream);
                    if (dataFrame == null)
                    {
                        Logger.Error($"Unable to decode DataFrame: {networkMessageHeader}.");
                        return(null);
                    }
                }
                dataFrame.NetworkMessageHeader = networkMessageHeader;
                parsedMessage = ParseDataSetFrame(inputStream, dataFrame);
                break;

            default:
                Logger.Warn($"ParsePayload - Not supported message type: {networkMessageHeader.ExtendedFlags2.MessageType}");
                break;
            }
            return(parsedMessage);
        }