Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Konstantin Osipov <kostja@tarantool.org>,
	Alexander Turenko <alexander.turenko@tarantool.org>,
	Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [tarantool-patches] [PATCH 2/6] box/console: Add explicit output EOS mapping
Date: Fri,  6 Sep 2019 00:28:11 +0300	[thread overview]
Message-ID: <20190905212815.7311-3-gorcunov@gmail.com> (raw)
In-Reply-To: <20190905212815.7311-1-gorcunov@gmail.com>

This will help us to distinguish end of string/stream
in text protocols (such as remote console connection).

Note that we start printing ";" terminator for every
lua output. Actually current yaml output does the
same but inside console.c module.

And since lua output is yet a new feature in stabilization
phase we're safe to make such changes without breaking api.

We keep the eos values in table because we will need to
fetch eos from active format in later patches, thus it
is easier to use dictionary here. Moreover in future
we might need to extend this eos table for other
serializers.

Part-of #3834
---
 src/box/lua/console.lua | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 22bafab3a..5430e6787 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -11,7 +11,6 @@ local urilib = require('uri')
 local yaml = require('yaml')
 local net_box = require('net.box')
 
-local YAML_TERM = '\n...\n'
 local PUSH_TAG_HANDLE = '!push!'
 
 --
@@ -20,6 +19,11 @@ local PUSH_TAG_HANDLE = '!push!'
 local default_output_format = { ["fmt"] = "yaml", ["opts"] = nil }
 local output_handlers = { }
 
+--
+-- End of streams/strings. They will allow to recognize blocks
+-- depending on output format.
+local output_eos = { ["yaml"] = '\n...\n', ["lua"] = ';' }
+
 output_handlers["yaml"] = function(status, opts, ...)
     local err
     if status then
@@ -42,9 +46,11 @@ end
 
 output_handlers["lua"] = function(status, opts, ...)
     --
-    -- Don't print nil if there is no data
+    -- If no data present at least EOS should be put,
+    -- otherwise wire readers won't be able to find
+    -- where end of string is.
     if not ... then
-        return ""
+        return output_eos["lua"]
     end
     -- Map internal symbols in case if they are
     -- not inside tables and serpent won't handle
@@ -54,7 +60,7 @@ output_handlers["lua"] = function(status, opts, ...)
     }
     for k,v in pairs(map_direct_symbols) do
         if k == ... then
-            return v
+            return v .. output_eos["lua"]
         end
     end
     --
@@ -75,9 +81,9 @@ output_handlers["lua"] = function(status, opts, ...)
         nocode = true,
     }
     if opts == "block" then
-        return serpent.block(..., serpent_opts)
+        return serpent.block(..., serpent_opts) .. output_eos["lua"]
     end
-    return serpent.line(..., serpent_opts)
+    return serpent.line(..., serpent_opts) .. output_eos["lua"]
 end
 
 local function output_verify_opts(fmt, opts)
@@ -309,7 +315,7 @@ local text_connection_mt = {
         -- @retval     nil Error.
         --
         read = function(self)
-            local ret = self._socket:read(YAML_TERM)
+            local ret = self._socket:read(output_eos["yaml"])
             if ret and ret ~= '' then
                 return ret
             end
-- 
2.20.1

  parent reply	other threads:[~2019-09-05 21:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05 21:28 [tarantool-patches] [PATCH v3 0/6] box/console: Improve lua mode for remote console Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 1/6] box/console: Add mapping for direct symbols Cyrill Gorcunov
2019-09-09 15:11   ` [tarantool-patches] " Sergey Ostanevich
2019-09-09 15:54     ` [tarantool-patches] " Cyrill Gorcunov
2019-09-10  3:59       ` [tarantool-patches] Re[2]: [tarantool-patches] " Sergey Ostanevich
2019-09-05 21:28 ` Cyrill Gorcunov [this message]
2019-09-05 21:28 ` [tarantool-patches] [PATCH 3/6] box/console: Refactor command handling Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 4/6] box/console: Fix hang in remote console lua mode Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 5/6] box/console: Provide console.eos() api Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 6/6] box/console: Rename output_parse to parse_output Cyrill Gorcunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190905212815.7311-3-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 2/6] box/console: Add explicit output EOS mapping' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox