public DescendantGenericPacketEncodingDecorator(EncodingDecorator encoding, IEnumerable <EncodingDecorator> encodingsList) : this(encoding)
 {
     foreach (var encodingItem in encodingsList)
     {
         Register(encodingItem);
     }
 }
 public DescendantFlagPacketEncoding(EncodingDecorator encoding, IEnumerable <EncodingDecorator> encodingsList, bool containLength = false) : this(encoding, containLength)
 {
     foreach (var encodingItem in encodingsList)
     {
         Register(encodingItem);
     }
 }
        public DescendantPacketEncoding(EncodingDecorator encoding) : base(encoding)
        {
            _idDictionary = new Dictionary <Type, byte>();
            IdDictionary  = new ReadOnlyDictionary <Type, byte>(_idDictionary);

            _encodingDictionary = new Dictionary <byte, EncodingDecorator>();
            EncodingDictionary  = new ReadOnlyDictionary <byte, EncodingDecorator>(_encodingDictionary);
        }
        public DescendantGenericPacketEncodingDecorator(EncodingDecorator encoding) : base(encoding)
        {
            _idDictionary = new Dictionary <Type, string>();
            IdDictionary  = new ReadOnlyDictionary <Type, string>(_idDictionary);

            _encodingDictionary = new Dictionary <string, EncodingDecorator>();
            EncodingDictionary  = new ReadOnlyDictionary <string, EncodingDecorator>(_encodingDictionary);
        }
        public DescendantFlagPacketEncoding(EncodingDecorator encoding, bool containLength = false) : base(encoding)
        {
            ContainLength = containLength;
            _idDictionary = new Dictionary <Type, byte>();
            IdDictionary  = new ReadOnlyDictionary <Type, byte>(_idDictionary);

            _encodingList = new List <EncodingDecorator>(8);
            EncodingList  = ((List <EncodingDecorator>)_encodingList).AsReadOnly();
        }
Ejemplo n.º 6
0
        public static EncodingDecorator GetChildEncoding <TP, TC>(this EncodingDecorator encodingDecorator) where TP : class, IDescendantPacket, new() where TC : IAncestorPacket
        {
            var descendantPacketEncoding = encodingDecorator.FindDecoratedEncoding <DescendantPacketEncoding <TP> >();

            if (descendantPacketEncoding == null)
            {
                throw new ArgumentException();
            }
            return(descendantPacketEncoding.EncodingDictionary[descendantPacketEncoding.IdDictionary[typeof(TC)]]);
        }
        public EncodingDecorator Build()
        {
            EncodingDecorator encoding = null;

            for (var i = SetupActions.Count - 1; i >= 0; i--)
            {
                encoding = SetupActions[i](encoding);
            }
            return(encoding);
        }
 public static EncodingDecorator FindDecoratedEncoding <T>(this EncodingDecorator packetEncoding) where T : IEncoding <IPacket>
 {
     while (packetEncoding is EncodingDecorator item)
     {
         if (item is T)
         {
             return(item);
         }
         packetEncoding = packetEncoding.Encoding;
     }
     return(null);
 }
Ejemplo n.º 9
0
 public static T FindDecoratedEncoding <T>(this EncodingDecorator packetEncoding) where T : class, IEncoding <IPacket>
 {
     while (packetEncoding is { } item)
     {
         if (item is T encoding)
         {
             return(encoding);
         }
         packetEncoding = packetEncoding.Encoding;
     }
     return(null);
 }
        public void Register(EncodingDecorator encoding)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            var enc = encoding.FindDecoratedEncoding <IAncestorPacketEncoding <IAncestorPacket> >();

            if (enc == null)
            {
                throw new NotSupportedException();
            }

            _idDictionary.Add(enc.PacketType, enc.Id);
            _encodingDictionary.Add(enc.Id, encoding);
        }
        public void Register(EncodingDecorator encoding)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            var enc = (IAncestorPacketEncoding <IAncestorPacket, TG>)encoding.FindDecoratedEncoding <AncestorGenericPacketEncodingDecorator <TG> >();

            if (enc == null)
            {
                throw new NotSupportedException();
            }

            var key = enc.Id.ToString();

            _idDictionary.Add(enc.PacketType, key);
            _encodingDictionary.Add(key, encoding);
            keyLength = key.Length;
        }
 public FunctionPacketEncoding(EncodingDecorator encoding, byte id, Type packetType) : base(encoding, id, packetType)
 {
 }
Ejemplo n.º 13
0
 protected EncodingDecorator(EncodingDecorator encoding)
 {
     Encoding = encoding;
 }
Ejemplo n.º 14
0
 public UnixTimeEpochPacketEncoding(EncodingDecorator encoding) : base(encoding)
 {
 }
 public AncestorPacketEncoding(EncodingDecorator encoding, byte id, Type packetType) : base(encoding)
 {
     Id         = id;
     PacketType = packetType;
 }
Ejemplo n.º 16
0
 public PropertyPacketEncoding(EncodingDecorator encoding, byte propertySize, Func <IPropertyPacket <T>, byte[]> Encode, Action <byte[], IPropertyPacket <T> > Decode) : base(encoding)
 {
     _encode      = Encode;
     _decode      = Decode;
     PropertySize = propertySize;
 }
 public HeaderPacketEncoding(EncodingDecorator encoding, byte[] header) : base(encoding)
 {
     Header = header;
 }
Ejemplo n.º 18
0
 public PropertyPacketEncoding(EncodingDecorator encoding, byte propertySize) : base(encoding)
 {
     PropertySize = propertySize;
 }
Ejemplo n.º 19
0
 public AncestorPacketEncoding(EncodingDecorator encoding, byte id, Type packetType) : base(encoding, id, packetType)
 {
 }
Ejemplo n.º 20
0
 public AncestorGenericPacketEncodingDecorator(EncodingDecorator encoding, T id, Type packetType) : base(encoding)
 {
     Id         = id;
     PacketType = packetType;
 }