CN103176803A - 一种代码序列化的方法 - Google Patents
一种代码序列化的方法 Download PDFInfo
- Publication number
- CN103176803A CN103176803A CN2013101346483A CN201310134648A CN103176803A CN 103176803 A CN103176803 A CN 103176803A CN 2013101346483 A CN2013101346483 A CN 2013101346483A CN 201310134648 A CN201310134648 A CN 201310134648A CN 103176803 A CN103176803 A CN 103176803A
- Authority
- CN
- China
- Prior art keywords
- code
- data
- software
- character string
- serializing
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Information Transfer Between Computers (AREA)
Abstract
本发明是一种代码序列化的方法,属于软件开发领域,计算机软件有代码和数据组成,软件的功能也由代码和数据来体现。其包括步骤1、将代码付值给一个字符串code,实现代码序列化;把序列化以后的代码,编译成虚拟机能识别的机器码,得到字符串P-Code;步骤2、将字符串P-Code和宿主软件结合在一起。代码包含应用逻辑,数据在软件运行是可以存储也可以传输,而代码在运行过程中相对稳定,不可改变。软件的功能的增加和变化通常只能由数据来实现。本发明把代码序列化为数据以后,作为数据可以传输和改变,然后还原成代码,来增加软件的柔性;此方法适合于商业软件的开发。
Description
技术领域
本发明涉及计算机程序技术领域,提供了一种代码序列化的方法。
背景技术
目前各种产品中越来越多的应用微处理芯片,用软件去控制产品的行为,提高产品的可靠性和扩展功能.这类产品的特点是, 软件以固件的方式体现, 一旦安装上去,不通过厂家和和专业维修站就基本上不可能对软件进行升级. 为了解决已发现的问题,譬如汽车行业,通过召回大量同型号产品来解决.费时费力.也让潜在的问题解决得不到及时处理. 譬如有些汽车的刹车问题,就是软件控制算法或者逻辑的问题.修复软件,必然会导致重新固化软件.其他的桌面软件***也存在着类似的问题,譬如一个控制生产流程的软件,由于用户流程的改变,导致软件的变化.任何软件的变化更新,都需要重新发布,假如是自开发软件,需要更新每一台计算机软件而不影响目前的生产.难度和成本都比较大. 假如是购买的商用软件,那么很难及时得到更新以后的软件.上面提到的那些问题,其实都是软件生命周期里,由于软件需求的变化,导致代码的变化,从而导致软件的重新发布和安装。
这里使用一个简单的例子来介绍本方法的原理.以汽车的充电部件为例,下面是一个完全简化了的软件模型:
充电部件对象(Charger)
{
属性:
当前蓄电池电压(V)
电压最小值 (Min)
电压最大值 (Max)
检测电压时间间隔(Interval)
方法:
检测当前电压(Detect)
充电(Charge)
{
如果 当前电压 < 电压最小值 就充电
如果 当前电压 > 电压最大值 就停止充电
}
}
上述的对象就是有数据(Data)和代码(组成), 数据用属性来体现,譬如当前电压,代码就是用应用逻辑的方法来体现,譬如充电方法. 代码部分在软件发布以后和下一个版本发布之前是不会改变的,数据是可以存储,改变,传递到汽车的其他***. 除了修正已有的***导致软件变化,还有其他因素也导致软件的升级变化,例如:***需要增加新的功能,修改增强已有功能,删除不需要的功能, 上述行为也会导致数据结构的变化,以关系数据库为例,导致增减数据表的列,列的类型和宽度的变化。
发明内容
本发明旨在于提供一种通过序列化将代码数据化,且数据化以后的代码本质上还是数据,只要是数据就很方便的修改,修改程序通过修改序列化以后的数据流的即可,这样方便后期程序的修改的代码序列化的方法。
本发明为了实现上述目的采用以下技术方案:
一种代码序列化的方法,其特征在于包括以下步骤:
步骤1、将代码付值给一个字符串code,实现代码序列化;把序列化以后的代码,编译成虚拟机能识别的机器码,得到字符串P-Code;
步骤2、将字符串P-Code和宿主软件结合在一起。
上述方案中,所述字符串code存储在数据库里,然后从数据库里读出,以字符串形式链接(***)到原来序列化的位置。
上述方案中,采用script.Execute(code, this)进行反序列化动作,将序列化以后的数据字符串code和当前的宿主软件运行时环境this传给script.Execute(code, this),执行数据化后的代码。
上述方案中,宿主软件结合在一起可采用以下2种方法:
第一种:把P-Code,转换为宿主软件的机器码,譬如Java语言,那么就转换为bytecode;
第二种:动态嵌入运行。
代码序列化到字符串流是常见的一种序列化方法,还可以序列化到二进制数据,XML等,为了便于简化问题,和说明问题,系列化以后的数据格式直接以代码源程序的格式,这个就是文中例子展示的字符串code, 因为使用源程序格式,使用序列化就是一个简单的工作,在文章中基本上没有提.技术关键就是如何把序列化以后的字符串流反序列化,让它以真正的代码一样去运行.
1、定义一个字符串code(这个其实就是序列化以后的数据),通常这个字符串是存储在数据库里,然后从数据库里读出,以字符串形式链接(***)到原来序列化的位置;
2、采用script.Execute(code, this)进行反序列化动作,将code(序列化以后的数据)和this(当前的宿主软件运行时环境)传给script.Execute(code, this),执行数据化后的代码。
采用以上技术方案的优点就是通过序列化将代码数据化,且数据化以后的代码本质上还是数据,只要是数据就很方便的修改,修改程序通过修改序列化以后的数据流的即可,这样方便后期程序的修改。
本发明具有以下有益效果:
本方法让已经存在的代码有了一个序列化的简单方法,从而提高软件的柔性。通过对代码序列化以后的数据的修改,来增加新减功能,从而让代码序列化后数据的消费者,在不重新安装/固化软件的情况下,有了更新功能.可以大量的节约资金和时间.有广阔的市场前景。
具体实施方式
一个计算机***,通常有数十个甚至上百个微处理器(或者计算机)组成, 这些计算机协同参与完成工作。 计算机之间传递的基本上都是数据(消息,命令,数据)。 计算机收到数据以后,执行相应的预定的动作, 但是无法产生一个新的动作(预定动作之外的动作)。***合作完成一个任务根据一定的流程(workflow)。 流程是预设的。 在计算机领域里,就是把对象(object)序列化(Serialization)传递到另外的计算机还原为对象(Deserialization),执行预定的动作(operation)。 序列化以后的得到的数据除了传递,还可以存储。对象的序列化本质上就是对软件对象属性的序列化。常见序列化数据的格式有2类,一类是私有的二进制格式数据,还有一类是使用XML格式,或者是XML的变种,广泛使用的有JSON,譬如Web Service中使用的SOAP格式。以充电对象为例,下面是XML的数据格式:
<Charger>
<Voltage>10</Voltage>
<Max>14</Max>
<Min>7</Min>
<Interval>5</Interval>
</Charger>
JSON格式:
{"Charger":
{"Voltage": 10,
"Max": 14,
"Min": 7
"Interval": 5
}
}
所谓动作就是执行一些计算机代码,也就是计算机软件中的方法,通常情况下我们不能对代码序列化。代码用来表示逻辑知识。如果代码也能序列化, 那么表示软件具有:
1、知识的传递能力:如果我们能把一些代码序列化从计算机A传递到另外的计算机B里,让计算机B执行相应的新的动作。
2、知识的自学习能力:在计算机失去和其他计算机联系的情况下,计算机自己具有学习能力。执行创造出新的动作。
传统的做法,用知识***,本质上还是数据传递和产生,这些知识能产生新的动作,但是这些动作还是预设的,它不能解决产生新动作的问题。
1、做智能***,譬如知识用规则来表示(实质还是传统意义上的数据)
2、知识还可以用模型来表示,譬如神经网络的模型(是一个数据结构)
上面充电对象的代码序列化的例子为:
{"Charger":
{"Voltage": 10,
"Max": 14,
"Min": 7
"Interval": 5
"Charge": if(voltage > Max) StopCharge(); if(Voltage<Min) StartCharge();
}
}
代码序列化为数据以后,除了作为代码本身知识表达的属性以外,作为数据属性,序列化以后的代码可以象数据那样检索,修改,增减。如何序列化代码成了关键问题。
如果是全新软件的设计开发,那么可以选择上述的设计.对于已经存在的软件,上面的设计显得费工费力。
下面用C#语言设计Windows Form窗口为例来说明代码的序列化的过程和等级。这个简单的Form就是显示一个Label和一个Button。
点击Button后,Button的显示内容为”OK”,Label的内容显示为”Good bye (n)”
点击Label后, Button的显示内容为”Cancel (n)”,Label的内容显示为”Hello World”, 其中(n)为整数表示第n次点击. 下面为标准的C#程序,可以编程运行
1 class LabelButtonForm0 : Form
2 {
3 private System.Windows.Forms.Button button1;
4 private System.Windows.Forms.Label label1;
5 int count = 0;
6 public LabelButtonForm0()
7 {
8 button1 = new System.Windows.Forms.Button();
9 label1 = new System.Windows.Forms.Label();
10 button1.Location = new System.Drawing.Point(50, 140);
11 button1.Size = new System.Drawing.Size(120, 24);
12 button1.Text = "Cancel";
13 label1.Location = new System.Drawing.Point(50, 40);
14 label1.AutoSize = true;
15 label1.Size = new System.Drawing.Size(120, 24);
16 label1.Text = "Good Morning!";
17 Controls.Add(this.label1);
18 Controls.Add(this.button1);
19 button1.Click += delegate(object sender, EventArgs e)
20 {
21 ((Button)sender).Text="OK";
22 label1.Text = "Good bye "+ count++;
23 };
24 label1.Click += delegate(object sender, EventArgs e)
25 {
26 ((Label)sender).Text="Hello World";
27 button1.Text = "Cancel " + count++;
28 };
29 this.Show();
30 }
31 }
现在我们演示把Button和Label的事件触发序列化,button1.Click和label1.Click序列化为字符串格式的信息流,下面是实例:
1 class LabelButtonForm1 : Form
2 {
3 private System.Windows.Forms.Button button1;
4 private System.Windows.Forms.Label label1;
5 int count = 0;
6 Script script = new Script();
7 public LabelButtonForm1()
8 {
9 button1 = new System.Windows.Forms.Button();
10 label1 = new System.Windows.Forms.Label();
11 button1.Location = new System.Drawing.Point(50, 140);
12 button1.Size = new System.Drawing.Size(120, 24);
13 button1.Text = "Cancel";
14 label1.Location = new System.Drawing.Point(50, 40);
15 label1.AutoSize = true;
16 label1.Size = new System.Drawing.Size(120, 24);
17 label1.Text = "Good Morning!";
18 Controls.Add(this.label1);
Controls.Add(this.button1);
19 this.Text = "Event Handler";
20 string code = " //序列化以后的代码
21 button1.Click += delegate(sender,e)
22 {
23 sender.Text='OK';
24 label1.Text = 'Good bye '+ count++;
25 };
26 label1.Click += delegate(sender,e)
27 {
28 sender.Text='Hello World';
29 button1.Text = 'Cancel ' + count++;
30 };
31 ";
32 script.Execute(code, this);
33 this.Show();
34 }
35 }
比较上面二个程序,我们可以发现,序列化以后的代码部分(20-32段)和原始的代码基本上是一致的。唯一差异就是使用动态变量.不需要声明变量类型。序列化模块(Script)能自动侦测变量的类型。
我们也可以对Button和Label的属性语句进行序列化.参看代码的15-21段。
1 class LabelButtonForm2 : Form
2 {
3 private System.Windows.Forms.Button button1;
4 private System.Windows.Forms.Label label1;
5 int count = 0;
6 Script script;
7 public LabelButtonForm2()
8 {
9 button1 = new System.Windows.Forms.Button();
10 label1 = new System.Windows.Forms.Label();
11 Controls.Add(this.label1);
12 Controls.Add(this.button1);
13 script = new Script();
14 string code = " //序列化以后的代码
15 button1.Location = new System.Drawing.Point(50, 140);
16 button1.Size = new System.Drawing.Size(120, 24);
17 button1.Text = 'Cancel';
18 label1.Location = new System.Drawing.Point(50, 40);
19 label1.AutoSize = true;
20 label1.Size = new System.Drawing.Size(120, 24);
21 label1.Text = 'Good Morning!';
22 button1.Click += delegate(sender,e)
23 {
24 sender.Text='OK';
25 label1.Text = 'Good bye '+ count++;
26 };
27 label1.Click += delegate(sender,e)
28 {
29 sender.Text='Hello World';
30 button1.Text = 'Cancel ' + count++;
31 };
32 ";
33 script.Execute(code, this);
34 this.Show();
35 }
36 }
Claims (4)
1.一种代码序列化方法,其特征在于包括以下步骤:
步骤1、将代码付值给一个字符串code,实现代码序列化;把序列化以后的代码,编译成虚拟机能识别的机器码,得到字符串P-Code;
步骤2、将字符串P-Code和宿主软件结合在一起。
2.根据权利要求1所述的一种代码序列化方法,其特征在于:所述字符串code存储在数据库里,然后从数据库里读出,以字符串形式链接(***)到原来序列化的位置。
3.根据权利要求1所述的一种代码序列化方法,其特征在于:采用script.Execute(code, this)进行反序列化动作,将序列化以后的数据字符串code和当前的宿主软件运行时环境this传给script.Execute(code, this),执行数据化后的代码。
4.根据权利要求1所述的一种代码序列化方法,其特征在于:宿主软件结合在一起可采用以下2种方法:
第一种:把P-Code,转换为宿主软件的机器码,譬如Java语言,那么就转换为bytecode;
第二种:动态嵌入运行。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2013101346483A CN103176803A (zh) | 2013-04-18 | 2013-04-18 | 一种代码序列化的方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2013101346483A CN103176803A (zh) | 2013-04-18 | 2013-04-18 | 一种代码序列化的方法 |
Publications (1)
Publication Number | Publication Date |
---|---|
CN103176803A true CN103176803A (zh) | 2013-06-26 |
Family
ID=48636708
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2013101346483A Pending CN103176803A (zh) | 2013-04-18 | 2013-04-18 | 一种代码序列化的方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103176803A (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111290777A (zh) * | 2020-01-23 | 2020-06-16 | 复旦大学 | 一种面向软件代码单元和代码度量的演化历史切片方法 |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101719902A (zh) * | 2009-12-04 | 2010-06-02 | 深圳创维数字技术股份有限公司 | 一种远程过程调用方法和*** |
CN102393857A (zh) * | 2011-11-01 | 2012-03-28 | 中兴通讯股份有限公司 | 一种用网页进行本地调用的方法和*** |
CN102662984A (zh) * | 2012-03-14 | 2012-09-12 | 南京新与力文化传播有限公司 | 基于html的多平台消息处理方法 |
-
2013
- 2013-04-18 CN CN2013101346483A patent/CN103176803A/zh active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101719902A (zh) * | 2009-12-04 | 2010-06-02 | 深圳创维数字技术股份有限公司 | 一种远程过程调用方法和*** |
CN102393857A (zh) * | 2011-11-01 | 2012-03-28 | 中兴通讯股份有限公司 | 一种用网页进行本地调用的方法和*** |
CN102662984A (zh) * | 2012-03-14 | 2012-09-12 | 南京新与力文化传播有限公司 | 基于html的多平台消息处理方法 |
Non-Patent Citations (2)
Title |
---|
王静: ""软件智能嵌入技术的研究及其安全应用"", 《中国优秀硕士学位论文全文数据库》, 15 November 2007 (2007-11-15) * |
高静: ""JSON序列化机制与传输效率研究"", 《中国优秀硕士学位论文全文数据库》, 15 August 2011 (2011-08-15) * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111290777A (zh) * | 2020-01-23 | 2020-06-16 | 复旦大学 | 一种面向软件代码单元和代码度量的演化历史切片方法 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Rumpe | Agile Modeling with the UML | |
US8448132B2 (en) | Systems and methods for modifying code generation templates | |
Osis et al. | Model-driven domain analysis and software development: Architectures and functions: Architectures and functions | |
Macik et al. | Context-sensitive, cross-platform user interface generation | |
Bonino et al. | Exploiting semantic technologies in smart environments and grids: Emerging roles and case studies | |
Yellin | The premature obituary of programming | |
Atkinson et al. | Symbiotic general-purpose and domain-specific languages | |
CN103176803A (zh) | 一种代码序列化的方法 | |
White et al. | The generic eclipse modeling system | |
Palviainen et al. | A semi-automatic end-user programming approach for smart space application development | |
Krogstie | Perspectives to Process Modeling–A historical overview | |
CN111399829A (zh) | 一种基于模型驱动的波形建模方法及终端 | |
Li et al. | A Web application framework for end-user-initiative development with a visual tool | |
Huang et al. | Interaction Proxy Manager: Semantic Model Generation and Run-time Support for Reconstructing Ubiquitous User Interfaces of Mobile Services | |
Masuda et al. | Direction of digital it and enterprise architecture | |
Wendler et al. | Theoretical and practical implications of user interface patterns applied for the development of graphical user interfaces | |
Swan et al. | Polytypic Genetic Programming | |
Saeki et al. | Model metrics and metrics of model transformations | |
Rao et al. | Fault tolerant web services composition as planning | |
Kolski et al. | Agent-based architecture for interactive system design: Current approaches, perspectives and evaluation | |
Mohan et al. | Temporal analysis for adapting concurrent applications to embedded systems | |
Bresniker et al. | What Gets You Hired Now Will Not Get You Hired Then | |
Bernaschina | Tools, semantics and work-flows for web and mobile model driven development | |
Zahra Yamani et al. | A Model-Driven Architecture Approach for Developing Healthcare ERP: Case study in Morocco | |
Kotsalis | Model-based UI Engineering of Advanced and Creativity-based UIs. |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20130626 |