我正在实现一个探查器,它收集数据并通过以 XML 序列化的套接字将数据发送到给定主机。探查器是用 C++ 实现的,主机(GUI)是用 Java 实现的。
我想到了,将属于一起的数据放入 C++ 类中,例如类 ThreadInfo,包含字符串 ThreadName、字符串 ThreadGroup 等。
此外,该类将被序列化为 XML,通过套接字发送,Java GUI 将可视化数据。
对于我的问题:我不确定是否应该使用其他解决方案。例如,只需使用 CORBA 来交换类。然而,这些类并不是很大,而且构建起来很容易。
使用可用的解决方案是否很常见?
I am implementing a profiler which collects data and sends the data via socket serialized in XML to a given host. The profiler is implemented in C++, the host (GUI) is implemented in Java.
It arises for me, putting data which belongs together into C++ classes, for instance a class ThreadInfo, containing string ThreadName, string ThreadGroup, etc.
Further this class would be serialized to XML, send via socket and the Java GUI would visualize the data.
To my question: I'm not sure, if I should use another solution. For instance just use CORBA for exchanging the classes. However the classes are not really big, and are constructed quite easily.
Would it be common to use an available solution?
发布评论
评论(1)
如果您的类很简单,只需使用纯 XML 结构来序列化数据,代码编写起来就会很容易且高效。但是,请记住,如果数据中有特殊字符、二进制数据等,那么使用 CORBA 之类的东西会更容易,因为它们可以处理所有特殊字符,并且编码起来很容易。否则,只需在 Java 代码中使用简单的 XML 解析器来解析传递过来的纯 XML。
从我个人的经验来看,对于简单的结构,我自己的 XML 结构是干净整洁的。
If your classes are simple, just use a plain XML structure to serialize the data and it will be easy to write your code and efficient. However, keep in mind that if you have things like special characters, binary data etc. in your data it would be easier to use something like CORBA as they will handle all special characters and will be a breeze to code. Otherwise, just use a simple XML parser in your Java code to parse the plain XML that is passed over.
From my personal experience, for simple structures, doing my own XML structure is clean and neat.