LooseMarshal() public method

public LooseMarshal ( OpenWireFormat wireFormat, Object o, BinaryWriter dataOut ) : void
wireFormat OpenWireFormat
o Object
dataOut System.IO.BinaryWriter
return void
Beispiel #1
0
        public void Marshal(Object o, BinaryWriter ds)
        {
            int size = 1;

            if (o != null)
            {
                DataStructure            c    = (DataStructure)o;
                byte                     type = c.GetDataStructureType();
                BaseDataStreamMarshaller dsm  = dataMarshallers[type & 0xFF];
                if (dsm == null)
                {
                    throw new IOException("Unknown data type: " + type);
                }

                if (tightEncodingEnabled)
                {
                    BooleanStream bs = new BooleanStream();
                    size += dsm.TightMarshal1(this, c, bs);
                    size += bs.MarshalledSize();

                    if (!sizePrefixDisabled)
                    {
                        ds.Write(size);
                    }

                    ds.Write(type);
                    bs.Marshal(ds);
                    dsm.TightMarshal2(this, c, ds, bs);
                }
                else
                {
                    BinaryWriter looseOut = ds;
                    MemoryStream ms       = null;
                    // If we are prefixing then we need to first write it to memory,
                    // otherwise we can write direct to the stream.
                    if (!sizePrefixDisabled)
                    {
                        ms       = new MemoryStream();
                        looseOut = new OpenWireBinaryWriter(ms);
                        looseOut.Write(size);
                    }

                    looseOut.Write(type);
                    dsm.LooseMarshal(this, c, looseOut);

                    if (!sizePrefixDisabled)
                    {
                        ms.Position = 0;
                        looseOut.Write((int)ms.Length - 4);
                        ds.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    }
                }
            }
            else
            {
                ds.Write(size);
                ds.Write(NULL_TYPE);
            }
        }
Beispiel #2
0
        public void LooseMarshalNestedObject(DataStructure o, BinaryWriter dataOut)
        {
            dataOut.Write(o != null);
            if (o != null)
            {
                byte type = o.GetDataStructureType();
                dataOut.Write(type);

                BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(type);
                dsm.LooseMarshal(this, o, dataOut);
            }
        }
Beispiel #3
0
 public void LooseMarshalNestedObject(DataStructure o, BinaryWriter dataOut)
 {
     dataOut.Write(o != null);
     if (o != null)
     {
         byte type = o.GetDataStructureType();
         dataOut.Write(type);
         BaseDataStreamMarshaller dsm = (BaseDataStreamMarshaller)dataMarshallers[type & 0xFF];
         if (dsm == null)
         {
             throw new IOException("Unknown data type: " + type);
         }
         dsm.LooseMarshal(this, o, dataOut);
     }
 }