本文整理汇总了C#中Marshaller.StartMarshal方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.StartMarshal方法的具体用法?C# Marshaller.StartMarshal怎么用?C# Marshaller.StartMarshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Marshaller
的用法示例。
在下文中一共展示了Marshaller.StartMarshal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestStructure
public void TestStructure()
{
for (int i = 1; i <= RepeatCnt; i++)
{
Console.WriteLine(">>> Iteration started: " + i);
// 1. Generate and shuffle objects.
IList<BranchedType> objs = new List<BranchedType>();
for (int j = 0; j < 6 * ObjectsPerMode; j++)
objs.Add(new BranchedType((j%6) + 1));
objs = IgniteUtils.Shuffle(objs);
// 2. Create new marshaller.
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType));
BinaryConfiguration cfg = new BinaryConfiguration
{
TypeConfigurations = new List<BinaryTypeConfiguration> { typeCfg }
};
Marshaller marsh = new Marshaller(cfg);
// 3. Marshal all data and ensure deserialized object is fine.
// Use single stream to test object offsets
using (var stream = new BinaryHeapStream(128))
{
var writer = marsh.StartMarshal(stream);
foreach (var obj in objs)
{
Console.WriteLine(">>> Write object [mode=" + obj.mode + ']');
writer.WriteObject(obj);
}
stream.Seek(0, SeekOrigin.Begin);
var reader = marsh.StartUnmarshal(stream);
foreach (var obj in objs)
{
var other = reader.ReadObject<BranchedType>();
Assert.IsTrue(obj.Equals(other));
}
}
Console.WriteLine();
// 4. Ensure that all fields are recorded.
var desc = marsh.GetDescriptor(typeof (BranchedType));
CollectionAssert.AreEquivalent(new[] {"mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8"},
desc.WriterTypeStructure.FieldTypes.Keys);
}
}
示例2: Write
/// <summary>
/// Writes this instance to the stream.
/// </summary>
/// <param name="stream">Stream.</param>
/// <param name="marsh">Marshaller.</param>
public void Write(IBinaryStream stream, Marshaller marsh)
{
var writer = marsh.StartMarshal(stream);
try
{
Marshal(writer);
}
finally
{
marsh.FinishMarshal(writer);
}
}
示例3: IgniteConfiguration
/// <summary>
/// Initializes a new instance of the <see cref="IgniteConfiguration"/> class.
/// </summary>
/// <param name="configuration">The configuration to copy.</param>
public IgniteConfiguration(IgniteConfiguration configuration)
{
IgniteArgumentCheck.NotNull(configuration, "configuration");
CopyLocalProperties(configuration);
using (var stream = IgniteManager.Memory.Allocate().GetStream())
{
var marsh = new Marshaller(configuration.BinaryConfiguration);
configuration.Write(marsh.StartMarshal(stream));
stream.SynchronizeOutput();
stream.Seek(0, SeekOrigin.Begin);
ReadCore(marsh.StartUnmarshal(stream));
}
}
示例4: BinarizableReadBenchmark
/// <summary>
/// Initializes a new instance of the <see cref="BinarizableReadBenchmark"/> class.
/// </summary>
public BinarizableReadBenchmark()
{
_marsh = new Marshaller(new BinaryConfiguration
{
TypeConfigurations = new List<BinaryTypeConfiguration>
{
new BinaryTypeConfiguration(typeof (Address)),
new BinaryTypeConfiguration(typeof (TestModel))
}
});
_mem = _memMgr.Allocate();
var stream = _mem.GetStream();
//_marsh.StartMarshal(stream).Write(_model);
_marsh.StartMarshal(stream).Write(_address);
stream.SynchronizeOutput();
}
示例5: WriteInvocationResult
/// <summary>
/// Writes method invocation result.
/// </summary>
/// <param name="stream">Stream.</param>
/// <param name="marsh">Marshaller.</param>
/// <param name="methodResult">Method result.</param>
/// <param name="invocationError">Method invocation error.</param>
public static void WriteInvocationResult(IBinaryStream stream, Marshaller marsh, object methodResult,
Exception invocationError)
{
Debug.Assert(stream != null);
Debug.Assert(marsh != null);
var writer = marsh.StartMarshal(stream);
BinaryUtils.WriteInvocationResult(writer, invocationError == null, invocationError ?? methodResult);
}
示例6: WritePartitions
/// <summary>
/// Writes the partitions assignment to a stream.
/// </summary>
/// <param name="parts">The parts.</param>
/// <param name="stream">The stream.</param>
/// <param name="marsh">The marshaller.</param>
internal static void WritePartitions(IEnumerable<IEnumerable<IClusterNode>> parts,
PlatformMemoryStream stream, Marshaller marsh)
{
Debug.Assert(parts != null);
Debug.Assert(stream != null);
Debug.Assert(marsh != null);
IBinaryRawWriter writer = marsh.StartMarshal(stream);
var partCnt = 0;
writer.WriteInt(partCnt); // reserve size
foreach (var part in parts)
{
if (part == null)
throw new IgniteException("IAffinityFunction.AssignPartitions() returned invalid partition: null");
partCnt++;
var nodeCnt = 0;
var cntPos = stream.Position;
writer.WriteInt(nodeCnt); // reserve size
foreach (var node in part)
{
nodeCnt++;
writer.WriteGuid(node.Id);
}
var endPos = stream.Position;
stream.Seek(cntPos, SeekOrigin.Begin);
stream.WriteInt(nodeCnt);
stream.Seek(endPos, SeekOrigin.Begin);
}
stream.SynchronizeOutput();
stream.Seek(0, SeekOrigin.Begin);
writer.WriteInt(partCnt);
}