public static byte[] Encode(VideoTimePeriodsPacket packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, VideoInfo.Encode(packet));
         PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriods));
         return(ms.ToArray());
     }
 }
Esempio n. 2
0
        public static LocalVideosInfoPacket Decode(Stream ms)
        {
            ITimePeriod tp     = TimePeriodPacket.Decode(ms);
            int         length = PacketBase.ReadInt(ms);

            VideoTimePeriodsPacket[] vis = new VideoTimePeriodsPacket[length];
            for (int i = 0; i < length; i++)
            {
                vis[i] = VideoTimePeriodsPacket.Decode(ms);
            }
            return(new LocalVideosInfoPacket(tp, vis));
        }
Esempio n. 3
0
 public static byte[] Encode(LocalVideosInfoPacket packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, TimePeriodPacket.Encode(packet.TimePeriod));
         PacketBase.WriteBytes(ms, packet.ValidTimePeriods.Length);
         for (int i = 0; i < packet.ValidTimePeriods.Length; i++)
         {
             PacketBase.WriteBytes(ms, VideoTimePeriodsPacket.Encode(packet.ValidTimePeriods[i]));
         }
         return(ms.ToArray());
     }
 }
 private void write()
 {
     try
     {
         if (!new FileInfo(_fileName).Directory.Exists)
         {
             new FileInfo(_fileName).Directory.Create();
         }
         using (FileStream fs = new FileStream(_fileName, FileMode.Create, FileAccess.Write, FileShare.Read))
         {
             write(fs, ParamCode.DownloadBase, DownloadInfoParam.Encode(DownloadInfo));
             write(fs, ParamCode.VideoBaseInfo, VideoBasePacket.Encode(VideoBase));
             write(fs, ParamCode.TimePeriods, VideoTimePeriodsPacket.Encode(TimePeriods));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
        private void readPacket(Stream ms)
        {
            int length = PacketBase.ReadInt(ms);
            int code   = PacketBase.ReadInt(ms);

            byte[] buffer = PacketBase.ReadByteArray(ms, length - 4);
            switch ((ParamCode)code)
            {
            case ParamCode.VideoBaseInfo:
                if (buffer.Length > 20 && (VideoBase == null || VideoBase.Length == 0))
                {
                    VideoBase = VideoBasePacket.Decode(buffer);
                }
                break;

            case ParamCode.TimePeriods:
                TimePeriods = VideoTimePeriodsPacket.Decode(buffer);
                break;

            case ParamCode.DownloadBase:
                DownloadInfo = DownloadInfoParam.Decode(buffer);
                break;
            }
        }
 public void UpdateTimePeriods(VideoTimePeriodsPacket packet)
 {
     TimePeriods = packet;
 }