Exemple #1
0
        public static Tuple <byte, byte> GetType(XPacketType type)
        {
            if (!TypeDictionary.ContainsKey(type))
            {
                throw new Exception($"Packet type {type:G} is not registered.");
            }

            return(TypeDictionary[type]);
        }
Exemple #2
0
        public static void RegisterType(XPacketType type, byte btype, byte bsubtype)
        {
            if (TypeDictionary.ContainsKey(type))
            {
                throw new Exception($"Packet type {type:G} is already registered.");
            }

            TypeDictionary.Add(type, Tuple.Create(btype, bsubtype));
        }
        private void SaveCallMap(FileStream stream, XPacketType type, Dictionary <int, FunctionCall> callMap)
        {
            long startPos = stream.Length;

            // write empty size of packet to be set at the end of the function
            stream.Write(BitConverter.GetBytes(0));

            stream.WriteByte((byte)type);

            // write the length of map
            stream.Write(BitConverter.GetBytes(callMap.Count));

            // write the call pairs
            foreach (var call in callMap.Values)
            {
                stream.Write(BitConverter.GetBytes(call.Source));
                stream.Write(BitConverter.GetBytes(call.Destination));
            }

            // write size of packet
            stream.Position = startPos;
            stream.Write(BitConverter.GetBytes((int)(stream.Length - startPos)));
            stream.Position = stream.Length;
        }
Exemple #4
0
        private void SaveCallMap(FileStream stream, XPacketType type, Dictionary<int, FunctionCall> callMap)
        {
            long startPos = stream.Length;

            // write empty size of packet to be set at the end of the function
            stream.Write(BitConverter.GetBytes(0));

            stream.WriteByte((byte)type);

            // write the length of map
            stream.Write(BitConverter.GetBytes(callMap.Count));

            // write the call pairs
            foreach (var call in callMap.Values)
            {
                stream.Write(BitConverter.GetBytes(call.Source));
                stream.Write(BitConverter.GetBytes(call.Destination));
            }

            // write size of packet
            stream.Position = startPos;
            stream.Write(BitConverter.GetBytes((int)(stream.Length - startPos)));
            stream.Position = stream.Length;
        }
        public static XPacket Serialize(XPacketType type, object obj, bool strict = false)
        {
            var t = XPacketTypeManager.GetType(type);

            return(Serialize(t.Item1, t.Item2, obj, strict));
        }
Exemple #6
0
        public static XPacket Create(XPacketType type)
        {
            var t = XPacketTypeManager.GetType(type);

            return(Create(t.Item1, t.Item2));
        }