首页 \ 问答 \ 协议缓冲区与平坦缓冲区(Protocol Buffers vs Flat Buffers [closed])

协议缓冲区与平坦缓冲区(Protocol Buffers vs Flat Buffers [closed])

所以,我目前正在研究Protocol Buffers广泛使用的项目,主要是为了将复杂对象存储在键值数据库中。

迁移到Flat Buffers是否会在性能方面提供相当大的好处?

更一般地说,是否有充分的理由使用Protocol Buffers而不是Flat Buffers?


So, I'm currently working on a project where Protocol Buffers is used extensively, mainly as a way to store complex objects in a key-value database.

Would a migration to Flat Buffers provide a considerable benefit in terms of performance?

More in general, is there ever a good reason to use Protocol Buffers instead of Flat Buffers?


原文:https://stackoverflow.com/questions/43054786
更新时间:2023-06-26 14:06

最满意答案

您想使用“先前在脚本中定义的变量”。 以下是变量:

file="path/to/input/file"
var="ssh_param"
msg="#New path defined"
new="/etc/ssh/file"

以下是使用这些变量的命令:

lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//')
if [ "$lineno" ]
then
    sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file"
else
    sed -i -r "$ s|$|\n$msg\n$var $new|" "$file"
fi

笔记:

  • 从您的示例中可以看出,变量名称可能在脚本中多次出现,但只有最后一个名称未被注释。 我们在这里使用它来简化代码。 脚本中变量最后一次出现的行号可从以下位置找到:

    lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//')
    

    grep -n部分查找出现变量名的行号列表。 tail -n1只返回最后一行。 sed命令从输出中删除除行号以外的所有行号。

  • 替换是通过以下命令完成的:

    sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file"`
    

    这使用sed的能力来操作特定的行号。 该行由三行代替:第一行是现有行的副本,但是已注释,第二行是消息,第三行是变量的新定义。

  • 如果变量当前不在文件中,则lineno为空。 在这种情况下,我们希望将新行添加到文件的末尾。 这是通过类似但更简单的sed命令完成的:

    sed -i -r "$ s|$|\n$msg\n$var $new|" "$file"
    

第一个$告诉sed仅在最后一行操作。 第二个$出现在substitute命令中,表示该行的结束。 您的消息和新变量定义将被追加。

以此为输入:

#ssh_param dasfda
ssh_param /path/to/file

上面的代码用以下代码替换文件:

#ssh_param dasfda
#ssh_param /path/to/file
#New path defined
ssh_param /etc/ssh/file

(如果你想要空行来分隔,只需在sed输出表达式中添加一些\n 。)


You wanted to use "variables defined earlier in the script." Here are the variables:

file="path/to/input/file"
var="ssh_param"
msg="#New path defined"
new="/etc/ssh/file"

Here are the commands which use those variables:

lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//')
if [ "$lineno" ]
then
    sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file"
else
    sed -i -r "$ s|$|\n$msg\n$var $new|" "$file"
fi

Notes:

  • It appears from your examples that the variable name may occur multiple times in the script but only the last one is uncommented. We use that here to simplify the code. The line number of the last appearance of the variable in the script is found from:

    lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//')
    

    The grep -n part finds a list of line numbers on which the variable name occurs. tail -n1 returns only the last such line. The sed command removes all but the line number from the output.

  • The substitution is done by this command:

    sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file"`
    

    This uses sed's ability to operate on a particular line number. That line is substituted by three lines: the first is a copy of the existing line but commented, the second is the message, and the third is the new definition of the variable.

  • If the variable is not currently in the file, then lineno is empty. In this case, we want to add the new lines to the end of the file. This is done via a similar but simpler sed command:

    sed -i -r "$ s|$|\n$msg\n$var $new|" "$file"
    

The first $ tells sed to operate only on the last line. The second$ appears in the substitute command where it signifies the end of that line. Your message and new variable definition are appended.

Example

With this as the input:

#ssh_param dasfda
ssh_param /path/to/file

The above code replaces the file with:

#ssh_param dasfda
#ssh_param /path/to/file
#New path defined
ssh_param /etc/ssh/file

(If you want blank lines to space things out, just add some \n to the sed output expression.)

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。