Esempio n. 1
0
 public void AddArgument(bool isField, out NamedArgumentTypeEncoder typeEncoder, out NameEncoder name, out LiteralEncoder literal)
 {
     Builder.WriteByte(isField ? (byte)0x53 : (byte)0x54);
     typeEncoder = new NamedArgumentTypeEncoder(Builder);
     name        = new NameEncoder(Builder);
     literal     = new LiteralEncoder(Builder);
 }
Esempio n. 2
0
        public static void TypedConstant(this LiteralEncoder encoder, TypedConstant constant)
        {
            switch (constant.Kind)
            {
            case TypedConstantKind.Primitive:
                encoder.Scalar().Constant(constant.Value);
                break;

            case TypedConstantKind.Enum:
                encoder.Scalar().Constant(constant.Value);
                break;

            // This looks more correct, but the code above matches what the C# compiler produces
            //  encoder.TaggedScalar(
            //      type => type.Enum(constant.Type.ToString()),
            //      scalar => scalar.Constant(constant.Value)
            //);

            case TypedConstantKind.Type:
                encoder.Scalar().SystemType(constant.Type.ToString());
                break;

            case TypedConstantKind.Array:
            {
                LiteralsEncoder arrayEncoder = encoder.Vector().Count(constant.Values.Length);
                foreach (var arrayConstant in constant.Values)
                {
                    arrayEncoder.AddLiteral().TypedConstant(arrayConstant);
                }
                break;
            }
            }
        }
 static void EncodeLiteral(LiteralEncoder litEnc, CustomAttributeTypedArgument arg)
 {
     if (arg.Value is Type type)
     {
         // Type reference
         litEnc.Scalar().SystemType(type.FullName);
     }
     else if (arg.Value is ReadOnlyCollection <CustomAttributeTypedArgument> array)
     {
         // Array of values
         var subLitEnc = litEnc.Vector().Count(array.Count);
         foreach (var el in array)
         {
             EncodeLiteral(subLitEnc.AddLiteral(), el);
         }
     }
     else if (arg.Value is null)
     {
         if (arg.ArgumentType.IsArray)
         {
             litEnc.Scalar().NullArray();
         }
         else
         {
             litEnc.Scalar().Constant(null);
         }
     }
     else
     {
         // Check argument type supported (ie: simple scalar values)
         PrimitiveTypeCodeFromSystemTypeCode(arg.Value.GetType());
         litEnc.Scalar().Constant(arg.Value);
     }
 }
        public void LiteralEncoder_Scalar()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);

            Assert.Same(b, e.Builder);

            var s = e.Scalar();

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, s.Builder);
        }
Esempio n. 5
0
        public void LiteralEncoder_TaggedScalar()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);

            Assert.Same(b, e.Builder);

            var parts = e.TaggedScalar();

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, parts.Item1.Builder);
            Assert.Same(b, parts.Item2.Builder);
            b.Clear();

            e.TaggedScalar(
                part => Assert.Same(b, part.Builder),
                part => Assert.Same(b, part.Builder));

            Assert.Throws <ArgumentNullException>(() => e.TaggedScalar(null, _ => { }));
            Assert.Throws <ArgumentNullException>(() => e.TaggedScalar(_ => { }, null));
        }
        public void LiteralEncoder_TaggedScalar()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);

            Assert.Same(b, e.Builder);

            CustomAttributeElementTypeEncoder elementType;
            ScalarEncoder scalar;

            e.TaggedScalar(out elementType, out scalar);

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, elementType.Builder);
            Assert.Same(b, scalar.Builder);
            b.Clear();

            e.TaggedScalar(
                et => Assert.Same(b, et.Builder),
                s => Assert.Same(b, s.Builder));

            Assert.Throws <ArgumentNullException>(() => e.TaggedScalar(null, s => { }));
            Assert.Throws <ArgumentNullException>(() => e.TaggedScalar(et => { }, null));
        }
        public void LiteralEncoder_TaggedVector()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);

            Assert.Same(b, e.Builder);

            CustomAttributeArrayTypeEncoder arrayType;
            VectorEncoder vector;

            e.TaggedVector(out arrayType, out vector);

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, arrayType.Builder);
            Assert.Same(b, vector.Builder);
            b.Clear();

            e.TaggedVector(
                at => Assert.Same(b, at.Builder),
                v => Assert.Same(b, v.Builder));

            Assert.Throws <ArgumentNullException>(() => e.TaggedVector(null, v => { }));
            Assert.Throws <ArgumentNullException>(() => e.TaggedVector(at => { }, null));
        }
Esempio n. 8
0
 public static void EncodeConstant(this LiteralEncoder encoder, object constant)
 {
     encoder.Scalar().Constant(constant);
 }
Esempio n. 9
0
 public void AddArgument(bool isField, out NamedArgumentTypeEncoder typeEncoder, out NameEncoder name, out LiteralEncoder literal)
 {
     Builder.WriteByte(isField ? (byte)0x53 : (byte)0x54);
     typeEncoder = new NamedArgumentTypeEncoder(Builder);
     name = new NameEncoder(Builder);
     literal = new LiteralEncoder(Builder);
 }
Esempio n. 10
0
 public Encoder()
 {
     int num;
     this._state = new Base.State();
     this._repDistances = new uint[4];
     this._optimum = new Optimal[0x1000];
     this._matchFinder = null;
     this._rangeEncoder = new SharpCompress.Compressor.LZMA.RangeCoder.Encoder();
     this._isMatch = new BitEncoder[0xc0];
     this._isRep = new BitEncoder[12];
     this._isRepG0 = new BitEncoder[12];
     this._isRepG1 = new BitEncoder[12];
     this._isRepG2 = new BitEncoder[12];
     this._isRep0Long = new BitEncoder[0xc0];
     this._posSlotEncoder = new BitTreeEncoder[4];
     this._posEncoders = new BitEncoder[0x72];
     this._posAlignEncoder = new BitTreeEncoder(4);
     this._lenEncoder = new LenPriceTableEncoder();
     this._repMatchLenEncoder = new LenPriceTableEncoder();
     this._literalEncoder = new LiteralEncoder();
     this._matchDistances = new uint[0x224];
     this._numFastBytes = 0x20;
     this._posSlotPrices = new uint[0x100];
     this._distancesPrices = new uint[0x200];
     this._alignPrices = new uint[0x10];
     this._distTableSize = 0x2c;
     this._posStateBits = 2;
     this._posStateMask = 3;
     this._numLiteralPosStateBits = 0;
     this._numLiteralContextBits = 3;
     this._dictionarySize = 0x400000;
     this._dictionarySizePrev = uint.MaxValue;
     this._numFastBytesPrev = uint.MaxValue;
     this._matchFinderType = EMatchFinderType.BT4;
     this._writeEndMark = false;
     this.reps = new uint[4];
     this.repLens = new uint[4];
     this.properties = new byte[5];
     this.tempPrices = new uint[0x80];
     this._trainSize = 0;
     for (num = 0; num < 0x1000L; num++)
     {
         this._optimum[num] = new Optimal();
     }
     for (num = 0; num < 4L; num++)
     {
         this._posSlotEncoder[num] = new BitTreeEncoder(6);
     }
 }
Esempio n. 11
0
        public void LiteralEncoder_TaggedScalar()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);
            Assert.Same(b, e.Builder);

            CustomAttributeElementTypeEncoder elementType;
            ScalarEncoder scalar;
            e.TaggedScalar(out elementType, out scalar);

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, elementType.Builder);
            Assert.Same(b, scalar.Builder);
            b.Clear();

            e.TaggedScalar(
                et => Assert.Same(b, et.Builder),
                s => Assert.Same(b, s.Builder));

            Assert.Throws<ArgumentNullException>(() => e.TaggedScalar(null, s => { }));
            Assert.Throws<ArgumentNullException>(() => e.TaggedScalar(et => { }, null));
        }
Esempio n. 12
0
        public void LiteralEncoder_Scalar()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);
            Assert.Same(b, e.Builder);

            var s = e.Scalar();
            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, s.Builder);
        }
Esempio n. 13
0
        public void LiteralEncoder_TaggedVector()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);
            Assert.Same(b, e.Builder);

            CustomAttributeArrayTypeEncoder arrayType;
            VectorEncoder vector;
            e.TaggedVector(out arrayType, out vector);

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, arrayType.Builder);
            Assert.Same(b, vector.Builder);
            b.Clear();

            e.TaggedVector(
                at => Assert.Same(b, at.Builder), 
                v => Assert.Same(b, v.Builder));

            Assert.Throws<ArgumentNullException>(() => e.TaggedVector(null, v => { }));
            Assert.Throws<ArgumentNullException>(() => e.TaggedVector(at => { }, null));
        }
Esempio n. 14
0
        public void LiteralEncoder_TaggedScalar()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);
            Assert.Same(b, e.Builder);

            var parts = e.TaggedScalar();

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, parts.Item1.Builder);
            Assert.Same(b, parts.Item2.Builder);
            b.Clear();

            e.TaggedScalar(
                part => Assert.Same(b, part.Builder),
                part => Assert.Same(b, part.Builder));

            Assert.Throws<ArgumentNullException>(() => e.TaggedScalar(null, _ => { }));
            Assert.Throws<ArgumentNullException>(() => e.TaggedScalar(_ => { }, null));
        }