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()); } }
static byte[] getBytes(Guid guid, DownloadCode code, object obj) { using (MemoryStream ms = new MemoryStream()) { PacketBase.WriteBytes(ms, guid); PacketBase.WriteBytes(ms, (int)code); switch (code) { case DownloadCode.DownloadInfo: PacketBase.WriteBytes(ms, DownloadInfoParam.Encode((DownloadInfoParam)obj)); break; case DownloadCode.Name: case DownloadCode.Quality: case DownloadCode.ErrorInfo: PacketBase.WriteBytes(ms, (string)obj); break; case DownloadCode.Size: case DownloadCode.Speed: PacketBase.WriteBytes(ms, (long)obj); break; case DownloadCode.IsLocalDownload: PacketBase.WriteBytes(ms, (bool)obj); break; case DownloadCode.TimePeriodsAll: case DownloadCode.TimePeriodsCompleted: PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray((TimePeriodPacket[])obj)); break; case DownloadCode.Status: PacketBase.WriteBytes(ms, (int)(DownloadStatus)obj); break; case DownloadCode.UpdatedLastestTime: PacketBase.WriteBytes(ms, (DateTime)obj); break; case DownloadCode.GoTop: break; } return(ms.ToArray()); } }
public static byte[] Encode(IDownloadInfoExpand packet) { using (MemoryStream ms = new MemoryStream()) { PacketBase.WriteBytes(ms, packet.GuidCode); PacketBase.WriteBytes(ms, DownloadInfoParam.Encode(packet.DownloadInfo)); PacketBase.WriteBytes(ms, packet.Name); PacketBase.WriteBytes(ms, packet.Quality); PacketBase.WriteBytes(ms, packet.Size); PacketBase.WriteBytes(ms, packet.IsLocalDownload); PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriodsAll)); PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriodsCompleted)); PacketBase.WriteBytes(ms, (int)packet.DownloadStatus); PacketBase.WriteBytes(ms, packet.ErrorInfo); PacketBase.WriteBytes(ms, packet.UpdatedLastestTime); PacketBase.WriteBytes(ms, packet.Speed); return(ms.ToArray()); } }