コード例 #1
0
ファイル: Scalar.cs プロジェクト: shariqkudcs/openfastdotnet
        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);
            }
        }
コード例 #2
0
 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);
     }
 }