예제 #1
0
        public new static UniviewStreamPacket Decode(MemoryStream ms)
        {
            DateTime time   = PacketBase.ReadTime(ms);
            DataType type   = (DataType)PacketBase.ReadInt(ms);
            string   dTag   = PacketBase.ReadString(ms);
            int      length = PacketBase.ReadInt(ms);

            byte[] buf = PacketBase.ReadByteArray(ms, length);
            return(new UniviewStreamPacket(time, type, buf, dTag));
        }
예제 #2
0
        public void TestPacketBase_DateTime()
        {
            DateTime time   = new DateTime(2016, 5, 25, 17, 28, 10, 123);
            var      buffer = PacketBase.GetBytes(time);

            using (MemoryStream ms = new MemoryStream(buffer))
            {
                var time2 = PacketBase.ReadTime(ms);
                Assert.AreEqual(time, time2);
            }
        }
예제 #3
0
        private void onReceiveCompleted(object sender, ReceiveEventArgs args)
        {
            try
            {
                if (args.ByteLength > 0)
                {
                    using (MemoryStream ms = new MemoryStream(args.ReceivedBytes))
                    {
                        ParamCode code   = (ParamCode)PacketBase.ReadInt(ms);
                        byte[]    buffer = null;
                        switch (code)
                        {
                        case ParamCode.VideoInfosTimePeriods:
                            updateVideoInfosTimePeriods(VideoDataInfoParam.Decode(ms));
                            break;

                        case ParamCode.DownloadBegin:
                            beginDownload(DownloadInfoParam.Decode(ms));
                            break;

                        case ParamCode.DownloadToLocal:
                            downloadToLocal(PacketBase.ReadString(ms));
                            break;

                        case ParamCode.VideoPacket:
                            getVideoStreamsPacket(VideoDataParam.Decode(ms));
                            break;

                        case ParamCode.ProbeTime:
                            setProbeTime(PacketBase.ReadTime(ms));
                            break;

                        case ParamCode.DownloadInfosAll:
                            feedbackDownloadInfosToClient();
                            break;

                        case ParamCode.DownloadControl:
                            var controlCode = (DownloadControlCode)PacketBase.ReadInt(ms);
                            onDownloadControl(controlCode, ms);
                            break;

                        case ParamCode.LocalDownloadPath:
                            onLocalDownloadPath(PacketBase.ReadString(ms));
                            break;

                        case ParamCode.LocalDownloadBegin:
                            onLocalDownloadStart(LocalDownloadInfoPacket.Decode(ms));
                            break;
                        }
                        if (buffer != null)
                        {
                            send((ParamCode)code, buffer);
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                sendMessage(MessageType.Warn, ex.Message, null);
            }
            catch (Exception ex)
            {
                sendMessage(MessageType.Error, ex.Message, null);
                Console.WriteLine(ex.ToString());
            }
        }