67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections;
|
|
using BCG.Utilities;
|
|
|
|
namespace BCG {
|
|
/// <summary>
|
|
/// Controls (ie creates dynamically) an IClientDeserializer and then passes data to it.
|
|
/// </summary>
|
|
public class ClientDeserializationController : IClientDeserializer {
|
|
private IClientDeserializer myDeserializer;
|
|
private int _n_desers = 0;
|
|
|
|
public ClientDeserializationController() { }
|
|
|
|
#region IClientDeserializer Members
|
|
|
|
/// <summary>
|
|
/// Deserializes bytes into operation and data. If it gets a non create before a create, both
|
|
/// the out arrays get initialized to empty arrays
|
|
/// </summary>
|
|
/// <param name="streams"></param>
|
|
/// <param name="theOps"></param>
|
|
/// <param name="theRows"></param>
|
|
public void deserialize(Stream[] streams, out byte[] theOps, out Array theRows) {
|
|
bts.Log.Gen.info($"ClientDeserializationController.deserialize len: {streams[0].Length - streams[0].Position}");
|
|
if (myDeserializer != null) {
|
|
myDeserializer.deserialize(streams, out theOps, out theRows);
|
|
} else {
|
|
Stream totalStream = UtilityMethods.getAggregatedStream(streams);
|
|
long initialPos = totalStream.Position;
|
|
BinaryReader br = new BinaryReader(totalStream);
|
|
byte op;
|
|
try {
|
|
op = br.ReadByte();
|
|
} catch (EndOfStreamException) {
|
|
op = Byte.MaxValue;
|
|
}
|
|
if (op == StreamOpCode.create) {
|
|
br.ReadString(); //pubsubclientdeserializer
|
|
string deserName = br.ReadString();
|
|
myDeserializer = Activator.CreateInstance(Type.GetType(deserName))
|
|
as IClientDeserializer;
|
|
totalStream.Position = initialPos;
|
|
myDeserializer.deserialize(new Stream[] { totalStream }, out theOps, out theRows);
|
|
} else {
|
|
// BlueEventLog.logEvent ("Received a non create before a create", BlueEventLevel.Warning);
|
|
theOps = new byte[] { };
|
|
theRows = new object[] { };
|
|
}
|
|
}
|
|
var msgs = StreamIOMessage.assemble_msgs(theOps, theRows);
|
|
int i = 0;
|
|
foreach (var m in msgs) {
|
|
bts.Log.Gen.info($"ClientDeserializationController n_desers: {_n_desers} msg no: {i++}: {m}");
|
|
}
|
|
_n_desers++;
|
|
// log it here
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
} |