internal RecordingConnection(IConnection connection) { try { _recordingInputStream = new RecordingInputStream(connection.InputStream.BaseStream); _recordingOutputStream = new RecordingOutputStream(connection.OutputStream.BaseStream); _inStream = new StreamReader(_recordingInputStream); _outStream = new StreamWriter(_recordingOutputStream); } catch (IOException e) { throw new RuntimeException(e); } }
public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context, BitVectorReader presenceMapReader) { try { ScalarValue priorValue = null; IDictionary dict = null; QName key = Key; ScalarValue value; int pmapIndex = presenceMapReader.Index; if (IsPresent(presenceMapReader)) { if (context.TraceEnabled) { inStream = new RecordingInputStream(inStream); } if (!_operatorCodec.ShouldDecodeType) { return(_operatorCodec.DecodeValue(null, null, this)); } if (_operatorCodec.DecodeNewValueNeedsPrevious) { dict = context.GetDictionary(Dictionary); priorValue = context.Lookup(dict, decodeTemplate, key); ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType); } ScalarValue decodedValue = _typeCodec.Decode(inStream); value = _operatorCodec.DecodeValue(decodedValue, priorValue, this); if (context.TraceEnabled) { context.DecodeTrace.Field(this, value, decodedValue, ((RecordingInputStream)inStream).Buffer, pmapIndex); } } else { if (_operatorCodec.DecodeEmptyValueNeedsPrevious) { dict = context.GetDictionary(Dictionary); priorValue = context.Lookup(dict, decodeTemplate, key); ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType); } value = _operatorCodec.DecodeEmptyValue(priorValue, this); } ValidateDecodedValueIsCorrectForType(value, _fastType); #warning TODO: Review if this previous "if" statement is needed. // if (Operator != Template.Operator.Operator.DELTA || value != null) if (value != null && (_operatorCodec.DecodeNewValueNeedsPrevious || _operatorCodec.DecodeEmptyValueNeedsPrevious)) { context.Store(dict ?? context.GetDictionary(Dictionary), decodeTemplate, key, value); } return(value); } catch (DynErrorException e) { throw new DynErrorException(e, e.Error, "Error occurred while decoding {0}", this); } }
public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context, BitVectorReader presenceMapReader) { try { ScalarValue priorValue = null; IDictionary dict = null; QName key = Key; ScalarValue value; int pmapIndex = presenceMapReader.Index; if (IsPresent(presenceMapReader)) { if (context.TraceEnabled) { inStream = new RecordingInputStream(inStream); } if (!OperatorCodec.ShouldDecodeType) { return(OperatorCodec.DecodeValue(null, null, this)); } if (OperatorCodec.DecodeNewValueNeedsPrevious) { dict = context.GetDictionary(Dictionary); priorValue = context.Lookup(dict, decodeTemplate, key); ValidateDictionaryTypeAgainstFieldType(priorValue, FastType); } ScalarValue decodedValue = TypeCodec.Decode(inStream); value = OperatorCodec.DecodeValue(decodedValue, priorValue, this); if (context.TraceEnabled) { context.DecodeTrace.Field(this, value, decodedValue, ((RecordingInputStream)inStream).Buffer, pmapIndex); } } else { if (OperatorCodec.DecodeEmptyValueNeedsPrevious) { dict = context.GetDictionary(Dictionary); priorValue = context.Lookup(dict, decodeTemplate, key); ValidateDictionaryTypeAgainstFieldType(priorValue, FastType); } value = OperatorCodec.DecodeEmptyValue(priorValue, this); } ValidateDecodedValueIsCorrectForType(value, FastType); // Delta the only operator that ALWAYS return true on IsPresent(presenceMapReader) (UsesPresenceMapBit from AlwaysPresentOperatorCodec always return false) and need previous if ((value != null || !(Operator is Operator.DeltaOperator)) && (OperatorCodec.DecodeNewValueNeedsPrevious || OperatorCodec.DecodeEmptyValueNeedsPrevious)) { context.Store(dict ?? context.GetDictionary(Dictionary), decodeTemplate, key, value); } return(value); } catch (DynErrorException e) { throw new DynErrorException(e, e.Error, "Error occurred while decoding {0}", this); } }