예제 #1
0
 public void SetEncodingFilter(EncodingType encodingType, IEncoding encoding)
 {
     if (encodingType != null && encoding != null && !"*".Equals(encodingType.Name, StringComparison.Ordinal))
     {
         this.OutputStream = encoding.Encode(encodingType, this.OutputStream);
         this.Headers["Content-Encoding"] = encodingType.Name;
     }
 }
 public static byte[] Encode <T>(this IEncoding <T> encoding, T value)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         using (IBitWriter suitableBitWriter = stream.CreateSuitableBitWriter())
             encoding.Encode(value, suitableBitWriter);
         return(stream.ToArray());
     }
 }
예제 #3
0
 public static string ToHexString <T>(T obj, IEncoding <T> encoding)
 {
     using (OrientedBitStream inMemoryBitStream = CreateSuitableInMemoryBitStream())
     {
         IBitWriter suitableBitWriter = inMemoryBitStream.CreateSuitableBitWriter();
         encoding.Encode(obj, suitableBitWriter);
         inMemoryBitStream.Position = 0L;
         byte[] numArray = new byte[inMemoryBitStream.Length / 8L];
         inMemoryBitStream.Read(numArray, 0, numArray.Length);
         return(numArray.ToHexString());
     }
 }
 public void Encode(IoElement element, IBitWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException(nameof(writer));
     }
     if (element.EventId > byte.MaxValue)
     {
         throw new ArgumentException("The event I/O id is not valid.", nameof(element));
     }
     IoProperty[] array1 = element.Where(x => x.Size == 1).Where(new Func <IoProperty, bool>(EncodePropertyFilter)).ToArray();
     IoProperty[] array2 = element.Where(x => x.Size == 2).Where(new Func <IoProperty, bool>(EncodePropertyFilter)).ToArray();
     IoProperty[] array3 = element.Where(x => x.Size == 4).Where(new Func <IoProperty, bool>(EncodePropertyFilter)).ToArray();
     IoProperty[] array4 = element.Where(x => x.Size == 8).Where(new Func <IoProperty, bool>(EncodePropertyFilter)).ToArray();
     writer.Write((byte)element.EventId);
     Encoding8.Encode(array1, writer);
     Encoding16.Encode(array2, writer);
     Encoding32.Encode(array3, writer);
     Encoding64.Encode(array4, writer);
 }
예제 #5
0
        public void SetEncodingFilter(EncodingType encodingType, IEncoding encoding)
        {
            if (encodingType != null && encoding != null)
            {
                string contentEncoding = encoding.ContentEncoding(encodingType);

                if (!"*".Equals(contentEncoding, StringComparison.Ordinal))
                {
                    this.Headers["Content-Encoding"] = contentEncoding;
                    this.httpResponse.Filter = encoding.Encode(encodingType, this.httpResponse.Filter);
                }
            }
        }
예제 #6
0
 public JsonResult Variables(string pattern)
 {
     return(new JsonResult(_encoding.Encode(pattern)));
 }
예제 #7
0
        public int Compile()
        {
            Stream s = null;

            OutputFile = Path.GetFullPath(OutputFile);
            string directory = Path.GetDirectoryName(OutputFile);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (Decode && Archive)
            {
                if (!Directory.Exists(OutputFile) || args.Length != 1)
                {
                    Console.Error.WriteLine("Usage: KeyCompiler.exe -decode -archive -out <directory> <archive>");

                    return(1);
                }

                s = File.Open(args [0], FileMode.Open, FileAccess.Read);

                try {
                    return(UnpackArchive(s, OutputFile));
                } finally {
                    s.Close();
                }
            }
            else if (Decode)
            {
                if (args.Length != 1)
                {
                    Console.Error.WriteLine("Usage: KeyCompiler.exe -decode -out <file.skm> <file.sk>");

                    return(1);
                }

                s = File.Open(args [0], FileMode.Open, FileAccess.Read);
                encoding.Decode(out keymask, out statebit,
                                out defaultMap, out shiftedMap, s);
                s.Close();

                s = File.Open(OutputFile, FileMode.Create, FileAccess.Write);
                Decompile(s);
                s.Close();
            }
            else if (Archive)
            {
                s = File.Open(OutputFile, FileMode.Create, FileAccess.Write);
                CreateArchive(s, args);
                s.Close();
            }
            else
            {
                int parseResult;

                this.source = args [0];
                parseResult = Parse(this.source);

                if (parseResult != 0)
                {
                    Console.Error.WriteLine("Failed to parse file `{0}'", this.source);
                    return(parseResult);
                }

                Console.WriteLine("Encoding to `{0}'...", OutputFile);

                s = File.Open(OutputFile, FileMode.Create, FileAccess.Write);
                encoding.Encode(keymask, statebit, defaultMap, shiftedMap, s);
            }

            return(0);
        }