public Unmarshal ( |
||
dataIn | ||
return | void |
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 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 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; bool _tightEncodingEnabled; lock (this.marshalLock) { dsm = GetDataStreamMarshallerForType(dataType); _tightEncodingEnabled = this.tightEncodingEnabled; } 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 DataStructure TightUnmarshalNestedObject(BinaryReader dis, BooleanStream bs) { if (bs.ReadBoolean()) { DataStructure data; BaseDataStreamMarshaller dsm; byte dataType = dis.ReadByte(); lock (this.marshalLock) { dsm = GetDataStreamMarshallerForType(dataType); } 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 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 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 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 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; }
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) { } }