WriteBoolean() публичный Метод

public WriteBoolean ( bool value ) : void
value bool
Результат void
Пример #1
0
        public int TightMarshalNestedObject1(DataStructure o, BooleanStream bs)
        {
            bs.WriteBoolean(o != null);
            if (null == o)
            {
                return(0);
            }

            if (o.IsMarshallAware())
            {
                MarshallAware ma       = (MarshallAware)o;
                byte[]        sequence = ma.GetMarshalledForm(this);
                bs.WriteBoolean(sequence != null);
                if (sequence != null)
                {
                    return(1 + sequence.Length);
                }
            }

            byte type = o.GetDataStructureType();

            if (type == 0)
            {
                throw new IOException("No valid data structure type for: " + o + " of type: " + o.GetType());
            }

            BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(type);

            Tracer.Debug("Marshalling type: " + type + " with structure: " + o);
            return(1 + dsm.TightMarshal1(this, o, bs));
        }
Пример #2
0
        protected int TightMarshalBrokerError1(OpenWireFormat wireFormat, BrokerError o, BooleanStream bs)
        {
            if (o == null)
            {
                bs.WriteBoolean(false);
                return(0);
            }
            else
            {
                int rc = 0;
                bs.WriteBoolean(true);
                rc += TightMarshalString1(o.ExceptionClass, bs);
                rc += TightMarshalString1(o.Message, bs);
                if (wireFormat.StackTraceEnabled)
                {
                    rc += 2;
                    StackTraceElement[] stackTrace = o.StackTraceElements;
                    for (int i = 0; i < stackTrace.Length; i++)
                    {
                        StackTraceElement element = stackTrace[i];
                        rc += TightMarshalString1(element.ClassName, bs);
                        rc += TightMarshalString1(element.MethodName, bs);
                        rc += TightMarshalString1(element.FileName, bs);
                        rc += 4;
                    }
                    rc += TightMarshalBrokerError1(wireFormat, o.Cause, bs);
                }

                return(rc);
            }
        }
Пример #3
0
 public virtual int TightMarshalLong1(OpenWireFormat wireFormat, long o, BooleanStream bs)
 {
     if (o == 0L)
     {
         bs.WriteBoolean(false);
         bs.WriteBoolean(false);
         return(0);
     }
     else
     {
         ulong ul = (ulong)o;
         if ((ul & 0xFFFFFFFFFFFF0000ul) == 0L)
         {
             bs.WriteBoolean(false);
             bs.WriteBoolean(true);
             return(2);
         }
         else if ((ul & 0xFFFFFFFF00000000ul) == 0L)
         {
             bs.WriteBoolean(true);
             bs.WriteBoolean(false);
             return(4);
         }
         else
         {
             bs.WriteBoolean(true);
             bs.WriteBoolean(true);
             return(8);
         }
     }
 }
Пример #4
0
        protected virtual int TightMarshalString1(String value, BooleanStream bs)
        {
            bs.WriteBoolean(value != null);
            if (value != null)
            {
                int strlen = value.Length;

                int    utflen      = 0;
                int    c           = 0;
                bool   isOnlyAscii = true;
                char[] charr       = value.ToCharArray();
                for (int i = 0; i < strlen; i++)
                {
                    c = charr[i];
                    if ((c >= 0x0001) && (c <= 0x007F))
                    {
                        utflen++;
                    }
                    else if (c > 0x07FF)
                    {
                        utflen     += 3;
                        isOnlyAscii = false;
                    }
                    else
                    {
                        isOnlyAscii = false;
                        utflen     += 2;
                    }
                }

                if (utflen >= Int16.MaxValue)
                {
                    throw new IOException("Encountered a String value that is too long to encode.");
                }

                bs.WriteBoolean(isOnlyAscii);
                return(utflen + 2);
            }
            else
            {
                return(0);
            }
        }
Пример #5
0
 protected virtual int TightMarshalObjectArray1(
     OpenWireFormat wireFormat,
     DataStructure[] objects,
     BooleanStream bs)
 {
     if (objects != null)
     {
         int rc = 0;
         bs.WriteBoolean(true);
         rc += 2;
         for (int i = 0; i < objects.Length; i++)
         {
             rc += TightMarshalNestedObject1(wireFormat, objects[i], bs);
         }
         return(rc);
     }
     else
     {
         bs.WriteBoolean(false);
         return(0);
     }
 }
Пример #6
0
        public int TightMarshalNestedObject1(DataStructure o, BooleanStream bs)
        {
            bs.WriteBoolean(o != null);
            if(null == o)
            {
                return 0;
            }

            if(o.IsMarshallAware())
            {
                MarshallAware ma = (MarshallAware) o;
                byte[] sequence = ma.GetMarshalledForm(this);
                bs.WriteBoolean(sequence != null);
                if(sequence != null)
                {
                    return 1 + sequence.Length;
                }
            }

            byte type = o.GetDataStructureType();
            if(type == 0)
            {
                throw new IOException("No valid data structure type for: " + o + " of type: " + o.GetType());
            }

            BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(type);

            Tracer.Debug("Marshalling type: " + type + " with structure: " + o);
            return 1 + dsm.TightMarshal1(this, o, bs);
        }
Пример #7
0
 protected int TightMarshalBrokerError1(OpenWireFormat wireFormat, BrokerError o, BooleanStream bs)
 {
     if (o == null)
     {
         bs.WriteBoolean(false);
         return 0;
     }
     else
     {
         int rc = 0;
         bs.WriteBoolean(true);
         rc += TightMarshalString1(o.ExceptionClass, bs);
         rc += TightMarshalString1(o.Message, bs);
         if (wireFormat.StackTraceEnabled)
         {
             rc += 2;
             StackTraceElement[] stackTrace = o.StackTraceElements;
             for (int i = 0; i < stackTrace.Length; i++)
             {
                 StackTraceElement element = stackTrace[i];
                 rc += TightMarshalString1(element.ClassName, bs);
                 rc += TightMarshalString1(element.MethodName, bs);
                 rc += TightMarshalString1(element.FileName, bs);
                 rc += 4;
             }
             rc += TightMarshalBrokerError1(wireFormat, o.Cause, bs);
         }
         
         return rc;
     }
 }
Пример #8
0
 protected virtual int TightMarshalObjectArray1(
     OpenWireFormat wireFormat,
     DataStructure[] objects,
     BooleanStream bs)
 {
     if (objects != null)
     {
         int rc = 0;
         bs.WriteBoolean(true);
         rc += 2;
         for (int i = 0; i < objects.Length; i++)
         {
             rc += TightMarshalNestedObject1(wireFormat, objects[i], bs);
         }
         return rc;
     }
     else
     {
         bs.WriteBoolean(false);
         return 0;
     }
 }
Пример #9
0
 public virtual int TightMarshalLong1(OpenWireFormat wireFormat, long o, BooleanStream bs)
 {
     if (o == 0L)
     {
         bs.WriteBoolean(false);
         bs.WriteBoolean(false);
         return 0;
     }
     else
     {
         ulong ul = (ulong) o;
         if ((ul & 0xFFFFFFFFFFFF0000ul) == 0L)
         {
             bs.WriteBoolean(false);
             bs.WriteBoolean(true);
             return 2;
         }
         else if ((ul & 0xFFFFFFFF00000000ul) == 0L)
         {
             bs.WriteBoolean(true);
             bs.WriteBoolean(false);
             return 4;
         }
         else
         {
             bs.WriteBoolean(true);
             bs.WriteBoolean(true);
             return 8;
         }
     }
 }
Пример #10
0
 protected virtual int TightMarshalString1(String value, BooleanStream bs)
 {
     bs.WriteBoolean(value != null);
     if (value != null)
     {
         int strlen = value.Length;
         
         int utflen = 0;
         int c = 0;
         bool isOnlyAscii = true;
         char[] charr = value.ToCharArray();
         for (int i = 0; i < strlen; i++)
         {
             c = charr[i];
             if ((c >= 0x0001) && (c <= 0x007F))
             {
                 utflen++;
             }
             else if (c > 0x07FF)
             {
                 utflen += 3;
                 isOnlyAscii = false;
             }
             else
             {
                 isOnlyAscii = false;
                 utflen += 2;
             }
         }
         
         if (utflen >= Int16.MaxValue)
             throw new IOException("Encountered a String value that is too long to encode.");
         
         bs.WriteBoolean(isOnlyAscii);
         return utflen + 2;
     }
     else
     {
         return 0;
     }
 }
Пример #11
0
        protected void AssertMarshalBooleans(int count, GetBooleanValueDelegate valueDelegate)
        {
            BooleanStream bs = new BooleanStream();
            for(int i = 0; i < count; i++)
            {
                bs.WriteBoolean(valueDelegate(i, count));
            }
            MemoryStream buffer = new MemoryStream();
            BinaryWriter ds = new EndianBinaryWriter(buffer);
            bs.Marshal(ds);
            ds.Write(endOfStreamMarker);

            // now lets read from the stream

            MemoryStream ins = new MemoryStream(buffer.ToArray());
            BinaryReader dis = new EndianBinaryReader(ins);
            bs = new BooleanStream();
            bs.Unmarshal(dis);

            for(int i = 0; i < count; i++)
            {
                bool expected = valueDelegate(i, count);

                try
                {
                    bool actual = bs.ReadBoolean();
                    Assert.AreEqual(expected, actual);
                }
                catch(Exception e)
                {
                    Assert.Fail("Failed to parse bool: " + i + " out of: " + count + " due to: " + e);
                }
            }
            int marker = dis.ReadInt32();
            Assert.AreEqual(endOfStreamMarker, marker, "did not match: " + endOfStreamMarker + " and " + marker);

            // lets try read and we should get an exception
            try
            {
                dis.ReadByte();
                Assert.Fail("Should have reached the end of the stream");
            }
            catch(EndOfStreamException)
            {
            }
        }