public bool MatchesPacket(BaseClass_Packet p2Match) { if (p2Match.PacketKey != PacketKey) { return(false); } return(MatchesThisPacket(p2Match)); }
public void PushModulePacket(BaseClass_Packet value) { module_rx_queue.Enqueue(value); }
public static bool DeSerializeKnownPacket(ref byte[] bytesIn, SerializationType sT, ref BaseClass_Packet outPack) { if (KnownPacketTypes.ContainsKey(outPack.PacketKey)) { switch (sT) { case SerializationType.text_JSON: { outPack = ((BaseClass_Packet)(JsonSerializer.Deserialize(bytesIn, KnownPacketTypes.GetValueOrDefault(outPack.PacketKey)))); if (outPack != null) { if (outPack.GetType() == KnownPacketTypes.GetValueOrDefault(outPack.PacketKey)) { return(true); } } } return(false); default: throw new NotImplementedException("De-serialization Types other than JSON are not yet Supported!"); } } else { return(false); } }
/// <summary> /// Constructor from Packets /// </summary> /// <param name="cmdPack">Command Packet</param> /// <param name="rspPack">Response Packet</param> public BaseClass_CommandResponse(BaseClass_Packet cmdPack, BaseClass_Packet rspPack) { cmdPacket = cmdPack; rspPacket = rspPack; }
protected override bool MatchesThisPacket(BaseClass_Packet p2Match) { return(((ExitPacket_3)p2Match).ShouldExitWillExit == ShouldExitWillExit); }
protected override bool MatchesThisPacket(BaseClass_Packet p2Match) { return(((UnknownPacket_2)p2Match).UnknownBytes == UnknownBytes); }
protected override bool MatchesThisPacket(BaseClass_Packet p2Match) { return(((StatusPacket_1)p2Match).CleanBaseLibVersion == CleanBaseLibVersion); }
protected override bool MatchesThisPacket(BaseClass_Packet p2Match) { return(((ExceptionPacket_0)p2Match).PackedException.Message == PackedException.Message); }
public static bool DeSerializeDefaultPacket(ref byte[] bytesIn, SerializationType sT, out BaseClass_Packet outPack) { switch (sT) { case SerializationType.text_JSON: { outPack = JsonSerializer.Deserialize <BaseClass_Packet>(new ReadOnlySpan <byte>(bytesIn)); if (outPack == null) { return(false); } switch (outPack.PacketKey) { case 0: outPack = JsonSerializer.Deserialize <ExceptionPacket_0>(new ReadOnlySpan <byte>(bytesIn)); return(true); case 1: outPack = JsonSerializer.Deserialize <StatusPacket_1>(new ReadOnlySpan <byte>(bytesIn)); return(true); } } break; default: throw new NotImplementedException("De-serialization Types other than JSON are not yet Supported!"); } return(false); }
public static List <BaseClass_Packet> ParsePackets(SerializationType DeSerializationTypeSelect, List <byte> bytes2Parse) { BaseClass_Packet DeserializedPacket = null; List <BaseClass_Packet> outPacks = null; switch (DeSerializationTypeSelect) { case SerializationType.text_JSON: { int openIndex = 0; int closeIndex = 0; int openDepth = 0; int byteLength = 0; for (int i = 0; i < bytes2Parse.Count; i++) { if (bytes2Parse[i] == jsonOpenDelim) { openDepth++; if (openDepth == 1) { openIndex = i; } } else if (bytes2Parse[i] == jsonCloseDelim) { openDepth--; if (openDepth == 0) { closeIndex = i; byteLength = closeIndex - openIndex + 1; byte[] packetTokenBytes = bytes2Parse.GetRange(openIndex, byteLength).ToArray(); if (byteLength > 2) { if (DeSerializeDefaultPacket(ref packetTokenBytes, DeSerializationTypeSelect, out DeserializedPacket)) { if (outPacks == null) { outPacks = new List <BaseClass_Packet>(); } outPacks.Add(DeserializedPacket); } else if (BaseClass_ModuleExecutionSystem.DeSerializeKnownPacket(ref packetTokenBytes, DeSerializationTypeSelect, ref DeserializedPacket)) { if (outPacks == null) { outPacks = new List <BaseClass_Packet>(); } outPacks.Add(DeserializedPacket); } else { if (outPacks == null) { outPacks = new List <BaseClass_Packet>(); } outPacks.Add(new UnknownPacket_2 { UnknownBytes = packetTokenBytes }); } } } } } } break; default: throw new NotImplementedException("De-Serialization types other than text JSON are not yet supported."); } return(outPacks); }
protected abstract bool MatchesThisPacket(BaseClass_Packet p2Match);