From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 427482887F for ; Fri, 30 Aug 2019 17:48:39 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id puGBTYKS5eAP for ; Fri, 30 Aug 2019 17:48:39 -0400 (EDT) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id F08AD2887B for ; Fri, 30 Aug 2019 17:48:38 -0400 (EDT) Received: by mail-lf1-f65.google.com with SMTP id r5so6417288lfc.3 for ; Fri, 30 Aug 2019 14:48:38 -0700 (PDT) From: Cyrill Gorcunov Subject: [tarantool-patches] [PATCH 2/5] box/console: Add explicit output EOS mapping Date: Sat, 31 Aug 2019 00:48:05 +0300 Message-Id: <20190830214808.17422-3-gorcunov@gmail.com> In-Reply-To: <20190830214808.17422-1-gorcunov@gmail.com> References: <20190830214808.17422-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tml Cc: Alexander Turenko , Konstantin Osipov , Kirill Yukhin , Cyrill Gorcunov 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. Part-of #3834 --- src/box/lua/console.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 6cbb6b405..5ca5cad1f 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -11,6 +11,7 @@ local urilib = require('uri') local yaml = require('yaml') local net_box = require('net.box') +local LUA_TERM = ';' local YAML_TERM = '\n...\n' local PUSH_TAG_HANDLE = '!push!' @@ -19,6 +20,10 @@ local PUSH_TAG_HANDLE = '!push!' -- compatibility reason. 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"] = YAML_TERM, ["lua"] = LUA_TERM } output_handlers["yaml"] = function(status, opts, ...) local err @@ -42,9 +47,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 @@ -75,9 +82,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) -- 2.20.1