Ejemplo n.º 1
0
        //variant
        public void Write(object val)
        {
            if (val == null)
            {
                throw new NotSupportedException("Cannot send null variant");
            }

            if (val is DValue)
            {
                DValue dv = (DValue)val;

                if (dv.endianness != endianness)
                {
                    throw new NotImplementedException("Writing opposite endian DValues not yet implemented.");
                }

                Write(dv.signature);
                WritePad(dv.signature.Alignment);
                stream.Write(dv.data, 0, dv.data.Length);
                return;
            }

            Type type = val.GetType();

            WriteVariant(type, val);
        }
Ejemplo n.º 2
0
        // Used primarily for reading variant values
        object ReadValue(Signature sig)
        {
            if (sig.IsPrimitive)
            {
                return(ReadValue(sig[0]));
            }

            Type t = null;

            try {
                t = sig.ToType();
            } catch (NotSupportedException e) {
                // We don't catch other exceptions as they indicate a malformed signature
                if (Protocol.Verbose)
                {
                    Console.Error.WriteLine(e.Message);
                }
            }

            /*
             * if (t == null) {
             *      StepOver (sig);
             *      return null;
             * }
             */

            if (t == null)
            {
                ReadPad(sig.Alignment);
                int startPos = pos;
                StepOver(sig);
                int ln = pos - startPos;

                DValue dv = new DValue();
                dv.endianness = endianness;
                dv.signature  = sig;
                dv.data       = new byte[ln];
                Array.Copy(data, startPos, dv.data, 0, ln);
                return(dv);
            }

            return(ReadValue(t));
        }
Ejemplo n.º 3
0
        // Used primarily for reading variant values
        object ReadValue(Signature sig)
        {
            if (sig.IsPrimitive)
                return ReadValue (sig[0]);

            Type t = null;
            try {
                t = sig.ToType ();
            } catch (NotSupportedException e) {
                // We don't catch other exceptions as they indicate a malformed signature
                if (Protocol.Verbose)
                    Console.Error.WriteLine (e.Message);
            }

            /*
            if (t == null) {
                StepOver (sig);
                return null;
            }
            */

            if (t == null) {
                ReadPad (sig.Alignment);
                int startPos = pos;
                StepOver (sig);
                int ln = pos - startPos;

                DValue dv = new DValue();
                dv.endianness = endianness;
                dv.signature = sig;
                dv.data = new byte[ln];
                Array.Copy (data, startPos, dv.data, 0, ln);
                return dv;
            }

            return ReadValue (t);
        }