Exemplo n.º 1
0
 private static StreamCopyHelper ConstructCopyHelperForCommand(Command command, Stream input, Stream delta)
 {
     switch (command.Kind)
     {
         case CommandKind.Literal:
             // for a literal command, we copy bytes from the delta stream
             return new StreamCopyHelper(command.Parameter1, delta);
         case CommandKind.Copy:
             // for a copy command, we seek to the specified point and copy from the input stream
             input.Seek(command.Parameter1, SeekOrigin.Begin);
             return new StreamCopyHelper(command.Parameter2, input);
         case CommandKind.End:
             return null;
         default:
             throw new InvalidDataException(string.Format("Unknown command {0}", command.Parameter1));
     }
 }
Exemplo n.º 2
0
        private static Command ReadCommand(BinaryReader s)
        {
            // the first byte indicates which kind and format it is
            var commandFormat = GetCommandFormat(s.ReadByte());

            // then we might have to read the parameters in
            Command result = new Command();
            result.Kind = commandFormat.Kind;
            if (commandFormat.Length1 > 0)
            {
                result.Parameter1 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length1));
            }
            else
            {
                // some of the commands encode the parameter directly into the command byte
                result.Parameter1 = commandFormat.ImmediateValue;
            }

            if (commandFormat.Length2 > 0)
            {
                result.Parameter2 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length2));
            }

            return result;
        }