Files
spark/src/DataStreamSuite/PubSub/PubsubDeserializationController.cs
T
John Colvin a76cbafdbd cleanup: Fix numerous build warnings in DataStreamSuite
Nearly all warnings were due to nullability issues, since the concept of
nullable reference types did not exist when the DataStream code was
originally written.

* Compression related files
  - BZip2InputStream  (disable nullability warnings)
  - BZip2OutputStream (disable nullability warnings)
  - DeflaterHuffman   (disable nullability warnings)
  - Inflater          (disable nullability warnings)
  - InflaterDynHeader (disable nullability warnings)
  - ParallelJoinTest  (disable nullability warnings)
  - TarHeader
  - TarInputStream    (disable nullability warnings)
  - ZipEntry
  - ZipFile
  - ZipInputStream

* AsyncTCPConnection_APM
* AsyncTCPConnection_APM
* InflaterHuffmanTree
* ManagedSubscriber
* ManagedTCPMessageHub
* MapStream
* PubSubClientMessage
  - Normalize indentation/whitespace
  - Fix some typos
  - Address nullability issues to fix build warnings
  - Modernize code
* PubSubMessageReactor
* PubSubServerManagedTCPConnection
* PubSubSingleTagStateEvent
* PubSubState
* PublisherCore
* PubsubDeserializationController
* RemoteMessage
  - make 'message' nullable to resolve warnings elsewhere (in calling code)
* SharedStreamConfig
* SingleTagData
* SubscriberCore
* SuperMapStream
* SystemHeartbeatPublisher
* SystemStatsPublisher
* ThreadSafeQueue
* TradeBarsStream

fix build (warn): Only use Registry on windows
2025-11-21 14:54:58 -05:00

73 lines
3.2 KiB
C#

using System;
using System.IO;
using System.Collections;
using BCG.Utilities;
using mbts.utils;
namespace BCG {
/// <summary>
/// Controls (ie creates dynamically) an IPubsubDeserializer based on the type name which is
/// part of the published data. Since its also a IPubsubDeserializer, all subsequent calls
/// are passed though to the interface
/// </summary>
public class PubsubDeserializationController : IPubsubDeserializer {
private IPubsubDeserializer? myDeserializer;
public PubsubDeserializationController() { }
public void update(Stream stream) {
bts.Log.Gen.info("PubsubDeserializationController.update stream: {stream.Position} / {stream.Length}");
byte[] ops;
Array rows;
deserialize(new Stream[] { stream }, out ops, out rows);
}
public void update(byte[] bytes) {
bts.Log.Gen.info("PubsubDeserializationController.update bytes: {bytes.Length}");
byte[] ops;
Array rows;
deserialize(new Stream[] { new MemoryStream(bytes, 0, bytes.Length, false, true) }, out ops, out rows);
}
#region IPubsubDeserializer Members
public void deserialize(Stream[] streams, out byte[] theOps, out Array theRows) {
if (myDeserializer != null) {
myDeserializer.deserialize(streams, out theOps, out theRows);
bts.Log.Gen.info($"PubsubDeserializationController.deserialize myDeserializer: {myDeserializer} ops: {theOps.Length} theRows: {theRows.Length}");
} else {
Stream totalStream = UtilityMethods.getAggregatedStream(streams);
long initialPos = totalStream.Position;
BinaryReader br = new BinaryReader(totalStream);
byte opCode = br.ReadByte();
bts.Log.Gen.info($"PubsubDeserializationController.deserialize opCode: {opCode}");
if (opCode == StreamOpCode.create) {
string deserName = br.ReadString();
// TODOds
if (deserName == "BCG.PubsubUniversalDeserializer, DataStreamGateway") // so we can play old replay files which would not include the assembly name
deserName = "BCG.PubsubUniversalDeserializer, DataStreamCore";
ArgumentNullException.ThrowIfNull(myDeserializer);
var deserType = Type.GetType(deserName);
ArgumentNullException.ThrowIfNull(deserType);
myDeserializer = Activator.CreateInstance(deserType) as IPubsubDeserializer;
ArgumentNullException.ThrowIfNull(myDeserializer);
totalStream.Position = initialPos;
myDeserializer.deserialize(new Stream[] { totalStream }, out theOps, out theRows);
bts.Log.Gen.info($"PubsubDeserializationController.deserialize myDeserializer: {myDeserializer} ops: {theOps.Length} theRows: {theRows.Length}");
} else {
bts.Log.Gen.error($"Received a non create before a create. Bad op code was : {opCode} ");
theOps = new byte[] { };
theRows = new object[] { };
}
}
}
public byte[] getState() {
return myDeserializer == null ? new byte[] { } : myDeserializer.getState();
}
#endregion
}
}