Пример #1
0
        public void WriteResult(IFastJsonWriter writer, object?result, IWorkSession session)
        {
            if (result == null)
            {
                writer.WriteValue((string?)null);
                return;
            }

            if (result is string s)
            {
                writer.WriteValue(s);
                return;
            }

            var targetName = GetAndEnsureTargetName(session);

            if (targetName == TargetNames.Ast)
            {
                var astTarget = _astTargets[session.LanguageName];
                astTarget.SerializeAst(result, writer, session);
                return;
            }

            if (targetName == TargetNames.Explain)
            {
                _explainer.Serialize((ExplanationResult)result, writer);
                return;
            }

            if (targetName == TargetNames.Run)
            {
                _executor.Serialize((ExecutionResult)result, writer);
                return;
            }

            var decompiler = _decompilers[targetName];

            using (var streams = (CompilationStreamPair)result)
                using (var stringWriter = writer.OpenString()) {
                    decompiler.Decompile(streams, stringWriter);
                }
        }
Пример #2
0
        public void WriteResult(IFastJsonWriter writer, object result, IWorkSession session)
        {
            if (result == null)
            {
                writer.WriteValue((string)null);
                return;
            }

            if (result is string s)
            {
                writer.WriteValue(s);
                return;
            }

            var targetName = session.GetTargetName();

            if (targetName == TargetNames.Ast)
            {
                var astTarget = _astTargets.GetValueOrDefault(session.LanguageName);
                astTarget.SerializeAst(result, writer, session);
                return;
            }

            if (targetName == TargetNames.Explain)
            {
                _explainer.Serialize((ExplanationResult)result, writer);
                return;
            }

            if (targetName == TargetNames.Run)
            {
                _executor.Serialize((ExecutionResult)result, writer);
                return;
            }

            var decompiler = _decompilers[targetName];

            using (var stream = (Stream)result)
                using (var stringWriter = writer.OpenString()) {
                    decompiler.Decompile(stream, stringWriter);
                }
        }