public static void Apply(this IProtocolConverter protocolConverter, byte[] destination, ref int index, object data, DataFlag dataFlag) { protocolConverter.Apply(destination, ref index, new DataContext() { Data = data, DataFlag = dataFlag }); }
protected virtual int PrepareSendData(byte[] sendBuffer, RequestHeader requestHeader, DataContent dataContent) { var index = 4; var converterHeader = this.ConverterHeader; var converterHeaderContext = new DataContext() { Data = converterHeader, DataFlag = DataFlag.Header, }; var requestHeaderContext = new DataContext() { Data = requestHeader, DataFlag = DataFlag.Header }; DataContext[] dataContexts = null; if (DataInject != null) { var injectContext = new DataInjectContext() { ConverterHeader = ConverterHeader, RequestHeader = requestHeader, DataContent = dataContent, }; dataContexts = DataInject.SendData(ResolverSession, injectContext)?.ToArray(); converterHeader = injectContext.ConverterHeader; converterHeaderContext.Data = converterHeader; } protocolConverter.Apply(sendBuffer, ref index, converterHeaderContext, requestHeaderContext); var headerEndIndex = index; if (dataContexts != null) { protocolConverter.Apply(sendBuffer, ref index, dataContexts); } protocolConverter.Apply(sendBuffer, ref index, dataContent.DataContexts); if (SecurityInject != null) { var securityContext = new SecurityInjectContext() { ConverterHeader = converterHeader, RequestHeader = requestHeader, HeaderEndIndex = headerEndIndex, Data = sendBuffer, Length = index }; SecurityInject?.SendSecurity(ResolverSession, securityContext); index = securityContext.Length; } sendBuffer.InsertLength(index - 4); return(index); }