protected override void EncodeInternal(BinaryWriter output)
 {
     if (Value == 0.0d)
         output.WriteOpcode(MarshalOpcode.RealZero);
     else
     {
         output.WriteOpcode(MarshalOpcode.Real);
         output.Write(Value);
     }
 }
        protected override void EncodeInternal(BinaryWriter output)
        {
            switch (Value)
            {
                case true:
                    output.WriteOpcode(MarshalOpcode.BoolTrue);
                    break;

                case false:
                    output.WriteOpcode(MarshalOpcode.BoolFalse);
                    break;
            }
        }
Beispiel #3
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.Token);
     if (RawToken != null)
         output.Write(RawToken);
     else if (Token != null)
         output.Write(Encoding.ASCII.GetBytes(Token));
     else
         throw new InvalidDataException("Fill either RawToken or Token with data for encoding");
 }
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.ChecksumedStream);
     var ms = new MemoryStream();
     var tmp = new BinaryWriter(ms);
     Data.Encode(tmp);
     var data = ms.ToArray();
     Checksum = Adler32.Checksum(data);
     output.Write(Checksum);
     output.Write(data);
 }
Beispiel #5
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.SubStream);
     var tempMs = new MemoryStream();
     var temp = new BinaryWriter(tempMs);
     temp.Write((byte)0x7E);
     temp.Write((uint)0);
     Data.Encode(temp);
     output.WriteSizeEx((uint)tempMs.Length);
     output.Write(tempMs.ToArray());
 }
Beispiel #6
0
        protected override void EncodeInternal(BinaryWriter output)
        {
            output.WriteOpcode(MarshalOpcode.SubStream);

            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);

            binaryWriter.Write(Marshal.Process(Data));

            output.WriteSizeEx((uint)memoryStream.Length);
            output.Write(memoryStream.ToArray());
        }
Beispiel #7
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     if (Value == 1)
         output.WriteOpcode(MarshalOpcode.IntegerOne);
     else if (Value == 0)
         output.WriteOpcode(MarshalOpcode.IntegerZero);
     else if (Value == -1)
         output.WriteOpcode(MarshalOpcode.IntegerMinusOne);
     else if (Value < 127)
     {
         output.WriteOpcode(MarshalOpcode.IntegerByte);
         output.Write((byte)Value);
     }
     else if (Value < 32768)
     {
         output.WriteOpcode(MarshalOpcode.IntegerSignedShort);
         output.Write((short)Value);
     }
     else
     {
         output.WriteOpcode(MarshalOpcode.IntegerLong);
         output.Write(Value);
     }
 }
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.Buffer);
     output.WriteSizeEx(Data.Length);
     output.Write(Data);
 }
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.Object);
     new PyString(Name).Encode(output);
     Arguments.Encode(output);
 }
Beispiel #10
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(IsType2 ? MarshalOpcode.ObjectEx2 : MarshalOpcode.ObjectEx1);
     Header.Encode(output);
     // list
     output.Write(PackedTerminator);
     // dict
     output.Write(PackedTerminator);
 }
Beispiel #11
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.SubStruct);
     Definition.Encode(output);
 }
Beispiel #12
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.Dict);
     output.WriteSizeEx(Dictionary.Count);
     foreach (var pair in Dictionary)
     {
         pair.Value.Encode(output);
         pair.Key.Encode(output);
     }
 }
Beispiel #13
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.None);
 }
Beispiel #14
0
        protected override void EncodeInternal(BinaryWriter output)
        {
            output.WriteOpcode(IsType2 ? MarshalOpcode.ObjectEx2 : MarshalOpcode.ObjectEx1);
            Header.Encode(output);

            // list
            if (List != null)
            {
                if (List.Count > 0)
                {
                    foreach (PyObject item in List)
                    {
                        item.Encode(output);
                    }
                }
            }

            output.Write(PackedTerminator);

            // dict
            if (Dictionary != null)
            {
                if (Dictionary.Count > 0)
                {
                    foreach (var pair in Dictionary)
                    {
                        pair.Key.Encode(output);
                        pair.Value.Encode(output);
                    }
                }
            }

            output.Write(PackedTerminator);
        }
Beispiel #15
0
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.IntegerLongLong);
     output.Write(Value);
 }
 protected override void EncodeInternal(BinaryWriter output)
 {
     output.WriteOpcode(MarshalOpcode.IntegerVar);
     output.WriteSizeEx(Raw.Length);
     output.Write(Raw);
 }
        protected override void EncodeInternal(BinaryWriter output)
        {
            if (ForceUTF8)
            {
                output.WriteOpcode(MarshalOpcode.WStringUTF8);
                output.WriteSizeEx(Raw.Length);
                output.Write(Raw);
                return;
            }

            int idx;
            if (Raw.Length == 0)
                output.WriteOpcode(MarshalOpcode.StringEmpty);
            else if (Raw.Length == 1)
            {
                output.WriteOpcode(MarshalOpcode.StringChar);
                output.Write(Raw[0]);
            }
            else if ((idx = StringTable.Entries.IndexOf(Value)) >= 0)
            {
                output.WriteOpcode(MarshalOpcode.StringTable);
                output.Write((byte)(idx+1));
            }
            else
            {
                /*if (Raw.Length < 0xFF)
                {
                    output.WriteOpcode(MarshalOpcode.StringShort);
                    output.Write((byte)Raw.Length);
                    output.Write(Raw);
                }
                else*/
                {
                    output.WriteOpcode(MarshalOpcode.StringLong);
                    output.WriteSizeEx(Raw.Length);
                    output.Write(Raw);
                }
            }
        }