changeset 10:78129eaf8770

update chapter MessagePack java
author riono <e165729@ie.u-ryukyu.ac.jp>
date Tue, 04 May 2021 17:22:43 +0900
parents c5abec609e35
children 2f6e767c3da6
files Paper/riono-sigos.pdf Paper/riono-sigos.tex Paper/src/MessagePackEx.java Paper/src/StartHelloWorld.cs
diffstat 4 files changed, 54 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
Binary file Paper/riono-sigos.pdf has changed
--- a/Paper/riono-sigos.tex	Tue May 04 15:46:58 2021 +0900
+++ b/Paper/riono-sigos.tex	Tue May 04 17:22:43 2021 +0900
@@ -122,7 +122,7 @@
 
 \section{プログラムの例}
 Code \ref{code:javaSHW} はChrisite の機能を使用してhello world を出力する例題である。
-
+CodeGearManager を作り、setup(new CodeGear) を行うことで各CodeGear に記述されたDataGear の待ち合わせを行う。全てのDataGear が揃った場合にCodeGear が実行される。CodeGearaManager の作成方法はStartCodeGear を継承したものから、createCGM(port) を実行することにより、CodeGearManager が作成できる。
 
 
 \lstinputlisting[caption=StartHelloWorld, label=code:javaSHW]{src/StartHelloWorld.java}
@@ -143,12 +143,24 @@
 C\# でattribute を作成する際には、 System.Attributeを継承する必要がある。attribute の適用可能箇所については、Code \ref{code:csTake} の4行目でフィールド変数を指定している。
 
 \section{MessagePackの相違点}
-Christie ではデータを送信する際に、MessagePack を使用してデータを圧縮し、送信している。
+Christie ではデータを送信する際に、MessagePack を使用してデータを圧縮し、送信している。java 版で使用しているMessagePack はバージョンが古く現在はサポートされてない。そのためMessagePack の最新版とは記述方法が異なっている。Code \ref{code:mspackEx} はMessagePack の使用方法を示したものである。
+
+\lstinputlisting[caption=java 版におけるMessagePack の使用方法, label=code:mspackEx]{src/MessagePackEx.java}
+
+MessagePack を使用するには圧縮するクラスに対して @Message annotationをつける必要がある。これにより、クラス内で定義したpublic変数が圧縮される。
+Code \ref{code:mspackEx} の17 - 21行目は圧縮解凍の例であり、MessagePackのインスタンスを作成後、msgpack.write(data) を行うことでbyte[] 型にdataを圧縮できる。
+解凍にはmsgpack.read を使用し、圧縮されたbyte[] 型と圧縮対象のクラスを渡すことで解凍できる。
+
+
+
 
 
 
 \section{C\#への書き換え後のプログラムの例}
 
+\lstinputlisting[caption=C\# StartHelloWorld, label=code:csSHW]{src/StartHelloWorld.cs}
+
+
 \section{Unityでの動作}
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/src/MessagePackEx.java	Tue May 04 17:22:43 2021 +0900
@@ -0,0 +1,23 @@
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+ 
+public class Main1 {
+    @Message // Annotation
+    public static class MyMessage {
+        // public fields are serialized.
+        public String name;
+        public double version;
+    }
+ 
+    public static void main(String[] args) throws Exception {
+        MyMessage src = new MyMessage();
+        src.name = "msgpack";
+        src.version = 0.6;
+ 
+        MessagePack msgpack = new MessagePack();
+        // Serialize
+        byte[] bytes = msgpack.write(src);
+        // Deserialize
+        MyMessage dst = msgpack.read(bytes, MyMessage.class);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paper/src/StartHelloWorld.cs	Tue May 04 17:22:43 2021 +0900
@@ -0,0 +1,17 @@
+using Christie_net.codegear;
+
+namespace Christie_net.Test.Example.HelloWorld {
+public class StartHelloWorld : StartCodeGear {
+    
+    public StartHelloWorld(CodeGearManager cgm) : base(cgm) { }
+
+    public static void Main(string[] args) {
+        CodeGearManager cgm = CreateCgm(10000);
+        cgm.Setup(new HelloWorldCodeGear());
+        cgm.Setup(new FinishHelloWorld());
+        cgm.GetLocalDGM().Put("helloWorld", "hello");
+        cgm.GetLocalDGM().Put("helloWorld", "world");
+        
+    }
+}
+}
\ No newline at end of file