public DataStructure TightUnmarshalNestedObject(BinaryReader dis, BooleanStream bs) { if (bs.ReadBoolean()) { byte dataType = dis.ReadByte(); BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(dataType); DataStructure data = dsm.CreateObject(); if (data.IsMarshallAware() && bs.ReadBoolean()) { dis.ReadInt32(); dis.ReadByte(); BooleanStream bs2 = new BooleanStream(); bs2.Unmarshal(dis); dsm.TightUnmarshal(this, data, dis, bs2); } else { dsm.TightUnmarshal(this, data, dis, bs); } return(data); } return(null); }
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)); }
public void TightMarshalNestedObject2(DataStructure o, BinaryWriter ds, BooleanStream bs) { if (!bs.ReadBoolean()) { return; } byte type = o.GetDataStructureType(); ds.Write(type); if (o.IsMarshallAware() && bs.ReadBoolean()) { MarshallAware ma = (MarshallAware)o; byte[] sequence = ma.GetMarshalledForm(this); ds.Write(sequence, 0, sequence.Length); } else { BaseDataStreamMarshaller dsm = (BaseDataStreamMarshaller)dataMarshallers[type & 0xFF]; if (dsm == null) { throw new IOException("Unknown data type: " + type); } dsm.TightMarshal2(this, o, ds, bs); } }
public Object Unmarshal(BinaryReader dis) { // lets ignore the size of the packet if (!sizePrefixDisabled) { dis.ReadInt32(); } // first byte is the type of the packet byte dataType = dis.ReadByte(); if (dataType != NULL_TYPE) { BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(dataType); Object data = dsm.CreateObject(); if (tightEncodingEnabled) { BooleanStream bs = new BooleanStream(); bs.Unmarshal(dis); dsm.TightUnmarshal(this, data, dis, bs); return(data); } else { dsm.LooseUnmarshal(this, data, dis); return(data); } } return(null); }
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); } }
public void addMarshaller(BaseDataStreamMarshaller marshaller) { byte type = marshaller.GetDataStructureType(); lock (this.marshalLock) { dataMarshallers[type & 0xFF] = marshaller; } }
private BaseDataStreamMarshaller GetDataStreamMarshallerForType(byte dataType) { BaseDataStreamMarshaller dsm = this.dataMarshallers[dataType & 0xFF]; if (null == dsm) { throw new IOException("Unknown data type: " + dataType); } return(dsm); }
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); } }
public DataStructure LooseUnmarshalNestedObject(BinaryReader dis) { if (dis.ReadBoolean()) { byte dataType = dis.ReadByte(); BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(dataType); DataStructure data = dsm.CreateObject(); dsm.LooseUnmarshal(this, data, dis); return(data); } return(null); }
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); } }
public DataStructure LooseUnmarshalNestedObject(BinaryReader dis) { if (dis.ReadBoolean()) { byte dataType = dis.ReadByte(); BaseDataStreamMarshaller dsm = (BaseDataStreamMarshaller)dataMarshallers[dataType & 0xFF]; if (dsm == null) { throw new IOException("Unknown data type: " + dataType); } DataStructure data = dsm.CreateObject(); dsm.LooseUnmarshal(this, data, dis); return(data); } else { return(null); } }
public Object Unmarshal(BinaryReader dis) { // lets ignore the size of the packet if (!sizePrefixDisabled) { dis.ReadInt32(); } // first byte is the type of the packet byte dataType = dis.ReadByte(); if (dataType != NULL_TYPE) { BaseDataStreamMarshaller dsm = dataMarshallers[dataType & 0xFF]; if (dsm == null) { throw new IOException("Unknown data type: " + dataType); } Tracer.Debug("Parsing type: " + dataType + " with: " + dsm); Object data = dsm.CreateObject(); if (tightEncodingEnabled) { BooleanStream bs = new BooleanStream(); bs.Unmarshal(dis); dsm.TightUnmarshal(this, data, dis, bs); return(data); } else { dsm.LooseUnmarshal(this, data, dis); return(data); } } else { return(null); } }
public void TightMarshalNestedObject2(DataStructure o, BinaryWriter ds, BooleanStream bs) { if (!bs.ReadBoolean()) { return; } byte type = o.GetDataStructureType(); ds.Write(type); if (o.IsMarshallAware() && bs.ReadBoolean()) { MarshallAware ma = (MarshallAware)o; byte[] sequence = ma.GetMarshalledForm(this); ds.Write(sequence, 0, sequence.Length); } else { BaseDataStreamMarshaller dsm = GetDataStreamMarshallerForType(type); dsm.TightMarshal2(this, o, ds, bs); } }
public DataStructure TightUnmarshalNestedObject(BinaryReader dis, BooleanStream bs) { if (bs.ReadBoolean()) { byte dataType = dis.ReadByte(); BaseDataStreamMarshaller dsm = (BaseDataStreamMarshaller)dataMarshallers[dataType & 0xFF]; if (dsm == null) { throw new IOException("Unknown data type: " + dataType); } DataStructure data = dsm.CreateObject(); if (data.IsMarshallAware() && bs.ReadBoolean()) { dis.ReadInt32(); dis.ReadByte(); BooleanStream bs2 = new BooleanStream(); bs2.Unmarshal(dis); dsm.TightUnmarshal(this, data, dis, bs2); // TODO: extract the sequence from the dis and associate it. // MarshallAware ma = (MarshallAware)data // ma.setCachedMarshalledForm(this, sequence); } else { dsm.TightUnmarshal(this, data, dis, bs); } return(data); } else { return(null); } }
public void addMarshaller(BaseDataStreamMarshaller marshaller) { byte type = marshaller.GetDataStructureType(); dataMarshallers[type & 0xFF] = marshaller; }