simplified protocol
authorKetmar Dark <[email protected]>
Tue, 9 Aug 2016 15:57:15 +0000 (9 18:57 +0300)
committerKetmar Dark <[email protected]>
Tue, 9 Aug 2016 15:57:15 +0000 (9 18:57 +0300)
mono/injed.d
ncproto.d
nya.d

index c7e0e27..8e6dfc9 100644 (file)
@@ -28,10 +28,9 @@ void gcCollect () {
 // ////////////////////////////////////////////////////////////////////////// //
 void mxGetAssemblies () {
   if (isMonoAPILoaded) {
-    ReplyAsmInfo rep;
-    rep.list = enumAssemblies();
-    scope(exit) rep.list = null;
-    nyaSock.ncSendReply(rep);
+    auto list = enumAssemblies();
+    scope(exit) list = null;
+    nyaSock.ncSendReply(list);
   } else {
     nyaSock.ncSendReplyError("it is colorful here");
   }
@@ -41,10 +40,9 @@ void mxGetAssemblies () {
 // ////////////////////////////////////////////////////////////////////////// //
 void mxGetClasses (uint asmid) {
   if (isMonoAPILoaded) {
-    ReplyClassInfo rep;
-    rep.list = getClassList(asmid);
-    scope(exit) rep.list = null;
-    nyaSock.ncSendReply(rep);
+    auto list = getClassList(asmid);
+    scope(exit) list = null;
+    nyaSock.ncSendReply(list);
   } else {
     nyaSock.ncSendReplyError("it is colorful here");
   }
@@ -54,10 +52,9 @@ void mxGetClasses (uint asmid) {
 // ////////////////////////////////////////////////////////////////////////// //
 void mxGetFields (uint classid) {
   if (isMonoAPILoaded) {
-    ReplyFieldInfo rep;
-    rep.list = getClassFields(cast(void*)classid);
-    scope(exit) rep.list = null;
-    nyaSock.ncSendReply(rep);
+    auto list = getClassFields(cast(void*)classid);
+    scope(exit) list = null;
+    nyaSock.ncSendReply(list);
   } else {
     nyaSock.ncSendReplyError("it is colorful here");
   }
@@ -94,14 +91,14 @@ void commThread () {
           mxGetClasses(0);
           break;
         case ReqCommand.MonoGetClassInfo:
-          ReqGetClassInfo rq;
-          nyaSock.ncunser(rq);
-          mxGetClasses(rq.asmid);
+          uint asmid;
+          nyaSock.ncunser(asmid);
+          mxGetClasses(asmid);
           break;
         case ReqCommand.MonoGetClassFields:
-          ReqGetFields rq;
-          nyaSock.ncunser(rq);
-          mxGetFields(rq.clsid);
+          uint clsid;
+          nyaSock.ncunser(clsid);
+          mxGetFields(clsid);
           break;
         default: nyaSock.ncSendReplyError("unknown command");
       }
index bece85f..c169f63 100644 (file)
--- a/ncproto.d
+++ b/ncproto.d
@@ -59,16 +59,8 @@ struct AssemblyInfo {
   string name;
 }
 
-struct ReplyAsmInfo {
-  AssemblyInfo[] list;
-}
-
 
 // ////////////////////////////////////////////////////////////////////////// //
-struct ReqGetClassInfo {
-  uint asmid;
-}
-
 struct NCClassInfo {
   uint id;
   uint asmid;
@@ -88,16 +80,8 @@ struct NCClassInfo {
   }
 }
 
-struct ReplyClassInfo {
-  NCClassInfo[] list;
-}
-
 
 // ////////////////////////////////////////////////////////////////////////// //
-struct ReqGetFields {
-  uint clsid;
-}
-
 struct FieldInfo {
   uint type;
   uint ofs;
@@ -106,10 +90,6 @@ struct FieldInfo {
   string typename;
 }
 
-struct ReplyFieldInfo {
-  FieldInfo[] list;
-}
-
 
 // ////////////////////////////////////////////////////////////////////////// //
 void ncSendCommand (UDSocket sk, ReqCommand cmd) {
@@ -117,14 +97,14 @@ void ncSendCommand (UDSocket sk, ReqCommand cmd) {
 }
 
 
-void ncSendCommand(T) (UDSocket sk, ReqCommand cmd, in auto ref T st) if (is(T == struct)) {
+void ncSendCommand(T) (UDSocket sk, ReqCommand cmd, in auto ref T st) if (!is(T == class)) {
   sk.writeNum!ubyte(cmd);
   sk.ncser(st);
 }
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-void ncSendReply(T) (UDSocket sk, in ref T st) if (is(T == struct)) {
+void ncSendReply(T) (UDSocket sk, in ref T st) if (!is(T == class)) {
   sk.writeNum!ubyte(0); // no error
   sk.ncser(st);
 }
@@ -139,12 +119,11 @@ void ncSendReplyError (UDSocket sk, const(char)[] msg) {
 
 // ////////////////////////////////////////////////////////////////////////// //
 // throws on error
-void ncReceiveReply(T) (UDSocket sk, ref T st) if (is(T == struct)) {
+void ncReceiveReply(T) (UDSocket sk, ref T st) if (!is(T == class)) {
   if (sk.readNum!ubyte) {
-    static struct ER { string msg; }
-    ER er;
-    sk.ncunser(er);
-    throw new Exception(er.msg);
+    string msg;
+    sk.ncunser(msg);
+    throw new Exception(msg);
   }
   sk.ncunser(st);
 }
diff --git a/nya.d b/nya.d
index 89268ee..2cfd6cc 100644 (file)
--- a/nya.d
+++ b/nya.d
@@ -170,16 +170,12 @@ int findClassByName (const(char)[] name) {
 void monoScan () {
   {
     injSock.ncSendCommand(ReqCommand.MonoGetAssemblies);
-    ReplyAsmInfo rep;
-    injSock.ncReceiveReply(rep);
-    monoAsms = rep.list;
+    injSock.ncReceiveReply(monoAsms);
     writeln(monoAsms.length, " mono assemblies found");
   }
   {
     injSock.ncSendCommand(ReqCommand.MonoGetClasses);
-    ReplyClassInfo rep;
-    injSock.ncReceiveReply(rep);
-    monoClasses = rep.list;
+    injSock.ncReceiveReply(monoClasses);
     foreach (ref cls; monoClasses) {
       // build full name
       cls.fullname = cls.asmname;
@@ -627,14 +623,13 @@ void main (string[] args) {
             if (cl.length != 2) { writeln("class id only"); continue; }
             int cid = findClassByName(cl[1]);
             if (cid < 0) { writeln("class '", cl[1], "' not found"); continue; }
-            ReqGetFields req;
-            injSock.ncSendCommand(ReqCommand.MonoGetClassFields, ReqGetFields(monoClasses[cid].id));
-            ReplyFieldInfo rep;
-            scope(exit) rep.list = null;
+            injSock.ncSendCommand(ReqCommand.MonoGetClassFields, monoClasses[cid].id);
+            FieldInfo[] list;
+            scope(exit) list = null;
             try {
-              injSock.ncReceiveReply(rep);
-              writeln("=== ", rep.list, " fields ===");
-              foreach (const ref fld; rep.list) {
+              injSock.ncReceiveReply(list);
+              writeln("=== ", list, " fields ===");
+              foreach (const ref fld; list) {
                 writefln("%s %s at 0x%08x (flags=0x%08x)", fld.typename, fld.name, fld.ofs, fld.flags);
               }
             } catch (Exception e) {