wyUpdate.Common.ReadFiles.ReachedEndByte C# (CSharp) Method

ReachedEndByte() public static method

public static ReachedEndByte ( Stream fs, byte endByte, byte readValue ) : bool
fs Stream
endByte byte
readValue byte
return bool
        public static bool ReachedEndByte(Stream fs, byte endByte, byte readValue)
        {
            if (endByte == readValue)
                return true;

            if (fs.Length == fs.Position)
                //prevent infinite loops because the end of the file has been reached
                //but the 'end byte' hasn't been detected.
                throw new Exception("Premature end of file.");

            return false;
        }

Usage Example

Example #1
0
        public static UpdateHelperData FromByteArray(byte[] data)
        {
            UpdateHelperData updateHelperData = new UpdateHelperData();

            using (MemoryStream memoryStream = new MemoryStream(data))
            {
                byte b = (byte)memoryStream.ReadByte();
                while (!ReadFiles.ReachedEndByte(memoryStream, b, byte.MaxValue))
                {
                    switch (b)
                    {
                    case 1:
                        updateHelperData.Action = (UpdateAction)ReadFiles.ReadInt(memoryStream);
                        break;

                    case 2:
                        updateHelperData.UpdateStep = (UpdateStep)ReadFiles.ReadInt(memoryStream);
                        break;

                    case 128:
                        updateHelperData.ExtraDataIsRTF.Add(item: true);
                        break;

                    case 3:
                        updateHelperData.ExtraData.Add(ReadFiles.ReadString(memoryStream));
                        if (updateHelperData.ExtraDataIsRTF.Count != updateHelperData.ExtraData.Count)
                        {
                            updateHelperData.ExtraDataIsRTF.Add(item: false);
                        }
                        break;

                    case 4:
                        updateHelperData.ProcessID = ReadFiles.ReadInt(memoryStream);
                        break;

                    case 5:
                        updateHelperData.Progress = ReadFiles.ReadInt(memoryStream);
                        break;

                    case 6:
                        updateHelperData.ResponseType = (Response)ReadFiles.ReadInt(memoryStream);
                        break;

                    default:
                        ReadFiles.SkipField(memoryStream, b);
                        break;
                    }
                    b = (byte)memoryStream.ReadByte();
                }
                return(updateHelperData);
            }
        }
All Usage Examples Of wyUpdate.Common.ReadFiles::ReachedEndByte