是否可以拦截 matlab save() 字节流

本文介绍了是否可以拦截 matlab save() 字节流的处理方法,对大家解决问题具有一定的参考价值

问题描述

在 matlab 中,可以使用 matlab save() 调用将 matlab 对象甚至整个工作区写入文件.我想拦截字节流并在它进入文件之前对其进行后处理,这可能吗?或者,是否可以指定写入字节流的文件描述符,而不是通常作为参数进入 save() 调用的文件名.

In matlab it is possible to write matlab objects, or even the entire workspace, to a file using the matlab save() call. I would like to intercept the bytestream and postprocess it before it goes to a file, is this possible? Alternatively, is it possible to specify the filedescriptor that the bytestream is written to instead of the filename that usually goes into the save() call as an argument.

请注意,我不是在寻找在 matlab 中编写文件的替代方法,我知道我可以 fopen() 一个文件并编写我想要的任何内容,但重点是我想(重新)使用该对象保存调用内部的序列化,不要再发明我自己的了.

Note that I'm not looking for an alternative way to write a file in matlab, I know I can fopen() a file and write whatever I want, but the point is that I want to (re)use the object serialization that is internal to the save call, not invent my own again.

load() 调用当然会出现一个模拟问题,但在这种情况下,在字节流进入反序列化过程之前拦截它,但我想 save() 是否有可能解决 load()问题自然会出现.

An analog question would of course arise for the load() call, but in that case intercepting the bytestream before it goes into the deserialization process, but I guess if it is possible for save() the solution to the load() problem will follow naturally.

一些澄清:

  1. 我不是在寻找序列化 matlab 数据的新方法,它已经存在,练习的重点是在 save() 调用中使用现有的序列化,以便 1) 我不需要开始更新新版本的matlab中新类型对象的序列化代码,或者天堂禁止人们开始使用自定义OOP对象,2)我仍然可以轻松使用现有代码读取mat文件,例如scipy的支持用于 mat 文件.

  1. I'm not looking at a new way to serialize matlab data, it already exists and the whole point of the exercise is to use the existing serialization in the save() call so that 1) I don't need to start updating the serialization code for new types of objects in newer versions of matlab, or heaven forbid people start using custom OOP objects, and 2) I can still easily use existing code to read in mat files, such as for example scipy's support for mat files.

在后处理之前,流不能输出到文件或任何东西,这个想法是为了安全而加密,将流直接写入文件完全破坏了这个目的.

The stream must not get out to a file or anything before post-processing, the idea is encryption for security, writing the stream out plain to a file completely undermines that purpose.

并发症:

  • 看来matlab中save函数中使用的功能不仅仅是常规的顺序写入.检查库的目标代码,似乎保存函数是使用 matPutVariable(以前称为 matPutArray)实现的,它写入类型为 mxArray* 输出到使用 matOpen 打开的 MATFile* 类型的文件.这里的问题是matPutVariable描述中的如下文字:

  • It seems that the functionality used in the save function in matlab isn't just a regular sequential write. Examining the object code of the libraries it seems that the save function is implemented using matPutVariable (previously called matPutArray) which writes a given variable of type mxArray* out to a file of type MATFile* opened with matOpen. The problem here is the following text in the description of matPutVariable:

如果 mxArray 在 MAT 文件中不存在,该函数会将其附加到末尾.如果文件中存在同名的mxArray,则函数通过重写文件将现有的mxArray替换为新的mxArray.

If the mxArray does not exist in the MAT-file, the function appends it to the end. If an mxArray with the same name exists in the file, the function replaces the existing mxArray with the new mxArray by rewriting the file.

这意味着matPutVariable函数要在文件中查找,显然在使用管道的时候是无法查找的,所以使用管道来实现我们对字节流的处理是不可能的这个现有的序列化功能.

This means that the matPutVariable function will have to seek through the file, obviously seeking will not be possible when pipes are used, so using pipes to implement our processing of the bytestream is not possible when using this existing serialization functionality.

推荐答案

在这个问题上沉思了几个月后,我要说,不,这是不可能的.至少,不是没有核心的非便携式二进制/ELF hacking.

After brooding on this for several months, I'm going to say, no, this is not possible. At least, not without hardcore non-portable binary/ELF hacking.

这篇关于是否可以拦截 matlab save() 字节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1159

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1060

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:800

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:887

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:925

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:873

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:855

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:825

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1692

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1298