/// <summary> /// Constructs an instance of this class by using passed test site and given marshaling configuration. /// </summary> /// <param name="host">The message runtime host</param> /// <param name="config">The marshaling configuration</param> public MessageUtils(IRuntimeHost host, MarshalingConfiguration config) { this.marshaler = new Marshaler(host, config); this.host = host; disableValidation = IsDisableValidation(); InitMethodTable(initializers, typeof(InitializerAttribute), true); InitMethodTable(validators, typeof(ValidatorAttribute), false); }
/// <summary> /// Create native marshaller. /// </summary> /// <param name="type">Type of struct.</param> /// <param name="switchValue">Switch attribute value if presents.</param> /// <param name="sizeValue">Size attribute value if presents.</param> /// <param name="lengthValue">Length attribute value if presents.</param> /// <param name="marshalDesccriptor">marshal descriptor</param> /// <returns>created marshaller</returns> private static Marshaler CreateNativeMarshaller( Type type, object switchValue, object sizeValue, object lengthValue, bool force32Bit, int align, out MarshalingDescriptor marshalDesccriptor ) { MarshalingConfiguration mc = NativeMarshalingConfiguration.Configuration; if (align != -1) { mc.Alignment = align; } if (force32Bit) { mc.IntPtrSize = 4; } Marshaler marshaller = new Marshaler(mc); SwitchAttribute switchAttr = null; SizeAttribute sizeAttr = null; LengthAttribute lengthAttr = null; string nameSuffix = DateTime.UtcNow.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture); if (switchValue != null) { string switchSymbolName = "switch_" + nameSuffix; marshaller.DefineSymbol(switchSymbolName, switchValue); switchAttr = new SwitchAttribute(switchSymbolName); } if (sizeValue != null) { string sizeSymbolName = "size_" + nameSuffix; marshaller.DefineSymbol(sizeSymbolName, sizeValue); sizeAttr = new SizeAttribute(sizeSymbolName); } if (lengthValue != null) { string lengthSymbolName = "length_" + nameSuffix; marshaller.DefineSymbol(lengthSymbolName, lengthValue); lengthAttr = new LengthAttribute(lengthSymbolName); } TypeCustomAttributeProvider attrProvider = new TypeCustomAttributeProvider(switchAttr, sizeAttr, lengthAttr); marshalDesccriptor = new MarshalingDescriptor(type, attrProvider); return(marshaller); }
/// <summary> /// Constructs a channel which uses underlying stream and the given marshaler configuration. /// </summary> /// <param name="host">The message runtime host.</param> /// <param name="stream">The general stream object.</param> /// <param name="marshalingConfig">The marshaling configuration.</param> public Channel( IRuntimeHost host, Stream stream, MarshalingConfiguration marshalingConfig) { if (stream == null) { throw new ArgumentNullException("stream"); } this.readerMarshaler = new Marshaler(host, marshalingConfig); this.writerMarshaler = new Marshaler(host, marshalingConfig); this.stream = stream; this.readerLock = new object(); this.writerLock = new object(); if (stream.CanSeek) { readOffset = writeOffset = stream.Position; } }
/// <summary> /// Constructor /// </summary> /// <param name="site">The test site</param> /// <param name="config">The marshaling configuration</param> public MessageUtils(ITestSite site, MarshalingConfiguration config) : base(ExtensionHelper.GetRuntimeHost(site), config) { this.site = site; }
/// <summary> /// Constructor /// </summary> /// <param name="configuration">The marshaling configuration</param> public Marshaler(MarshalingConfiguration configuration) : base(configuration) { }
/// <summary> /// Constructs a channel which uses underlying stream and given marshaler configuration. /// </summary> /// <param name="site">Test site</param> /// <param name="stream">The general stream object.</param> /// <param name="marshalingConfig">The marshaling configuration.</param> public ValidationChannel(ITestSite site, Stream stream, MarshalingConfiguration marshalingConfig) : base(site, stream, marshalingConfig) { messageUtil = new MessageUtils(site); }
/// <summary> /// Constructor /// </summary> /// <param name="site">The test site</param> /// <param name="stream">The data stream</param> /// <param name="marshalingConfig">The marshaling configuration</param> public Channel(ITestSite site, Stream stream, MarshalingConfiguration marshalingConfig) : base(ExtensionHelper.GetRuntimeHost(site), stream, marshalingConfig) { }
/// <summary> /// Constructs a TCP adapter with given marshaling configuration. /// The parameter adapterName is used for constructing default PTF property names in the configuration. /// </summary> /// <param name="adapterName">The adapter name</param> /// <param name="config">The marshaling configuration</param> protected TcpAdapterBase(string adapterName, MarshalingConfiguration config) { this.adapterName = adapterName; this.marshalingConfig = config; }
/// <summary> /// Constructs a TCP adapter. /// The parameter adapterName is used for constructing default PTF property names in the configuration. /// </summary> /// <param name="adapterName">The adapter name</param> protected TcpAdapterBase(string adapterName) { this.adapterName = adapterName; this.marshalingConfig = BlockMarshalingConfiguration.Configuration; }
/// <summary> /// Constructs the marshaler based on marshaling configuration, without test site. /// </summary> /// <param name="configuration">The marshaling configuration</param> public Marshaler(MarshalingConfiguration configuration) { this.config = configuration; }
/// <summary> /// Constructs the marshaler based on test site and marshaling configuration. /// </summary> /// <param name="host">The message runtime host</param> /// <param name="configuration">The marshaling configuration</param> public Marshaler(IRuntimeHost host, MarshalingConfiguration configuration) { this.host = host; this.config = configuration; this.tracing = host != null ? host.MarshallerTrace : false; }
/// <summary> /// Constructs a channel which uses underlying stream and given marshaler configuration. /// </summary> /// <param name="host">The message runtime host.</param> /// <param name="stream">The general stream object.</param> /// <param name="marshalingConfig">The marshaling configuration.</param> public ValidationChannel(IRuntimeHost host, Stream stream, MarshalingConfiguration marshalingConfig) : base(host, stream, marshalingConfig) { messageUtil = new MessageUtils(host); }