Exemplo n.º 1
0
        public static byte[] Encode <T>(T t)
        {
            var arh = ArchManagedByte.InvokeWriter();

            int      mapHash = new Random().Next();
            int      mapID   = 50;
            DateTime dt      = DateTime.Now;
            string   json    = JsonConvert.SerializeObject(t);

            arh.wI(mapHash);
            arh.wI(mapID);
            arh.wDateTime(dt);
            arh.wSt(json);

            return(arh.toArray());
        }
Exemplo n.º 2
0
        public static T Decode <T>(byte[] array)
        {
            var arh = ArchManagedByte.InvokeReader(array);

            int      mapHash = arh.rInt();
            int      mapID   = arh.rInt();
            DateTime dt      = arh.rDateTime();
            string   json    = arh.rString();

            if (mapID != 50)
            {
                throw new WrongMapLibException("Wrong mapID");
            }

            return(JsonConvert.DeserializeObject <T>(json));
        }
Exemplo n.º 3
0
        public byte[] readStream(TcpClient client)
        {
            lock (this)
            {
                NetworkStream stream = client.GetStream();
                while (stream.DataAvailable)
                {
                    byte[] arLength = new byte[sizeof(short)];
                    stream.Read(arLength, offset: 0, size: arLength.Length);
                    IArchByteBoxReader reader = ArchManagedByte.InvokeReader(arLength);
                    short  Length             = reader.rShort();
                    byte[] byffer             = new byte[Length];
                    stream.Read(byffer, offset: 0, size: byffer.Length);

                    return(byffer);
                }
                return(null);
            }
        }