public static byte[] Encode(VideoBasePacket packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, packet.Time);
         PacketBase.WriteBytes(ms, packet.Header.Length);
         PacketBase.WriteBytes(ms, packet.Header);
         PacketBase.WriteBytes(ms, packet.Length);
         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 UpdateVideoBase(VideoBasePacket packet)
 {
     VideoBase = packet;
     write();
 }