forked from RuedigerMoeller/fast-serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to netty2go, initial js generation
- Loading branch information
1 parent
b472013
commit 35953fa
Showing
10 changed files
with
137 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,3 +221,4 @@ target/ | |
.gradle/ | ||
*.iml | ||
*.bin | ||
tempgen/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package minbin.gen; | ||
|
||
import de.ruedigermoeller.serialization.FSTClazzInfo; | ||
|
||
/** | ||
* Created by ruedi on 27.05.2014. | ||
*/ | ||
public class GenContext { | ||
|
||
public FSTClazzInfo clazz; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% | ||
import java.util.*; | ||
import java.io.*; | ||
import de.ruedigermoeller.template.*; | ||
// add imports you need during generation => | ||
import minbin.gen.*; | ||
import de.ruedigermoeller.serialization.*; | ||
// this header is always required to make it work. Cut & Paste this as template | ||
public class CLAZZNAME implements IContextReceiver | ||
{ | ||
public void receiveContext(Object o, PrintStream out) throws Exception | ||
{ | ||
// asign your context | ||
GenContext CTX = (GenContext)o; | ||
FSTClazzInfo CLZ = CTX.clazz; | ||
FSTClazzInfo.FSTFieldInfo fi[] = CLZ.getFieldInfo(); | ||
%> | ||
function J<%+CLZ.getClazz().getSimpleName()%>(map) { | ||
<% for (int i = 0; i < fi.length; i++ ) { | ||
%> this.__<%+fi[i].getField().getName()%> = ; | ||
<% } /*for*/ | ||
%>} | ||
<% | ||
// this footer is always required (to match opening braces in header | ||
} | ||
} | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package de.rm.testserver; | ||
|
||
import de.rm.testserver.protocol.BasicValues; | ||
import de.rm.testserver.protocol.MirrorRequest; | ||
import de.rm.testserver.protocol.Person; | ||
import de.rm.testserver.protocol.TestRequest; | ||
import de.ruedigermoeller.serialization.FSTConfiguration; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import org.nustaq.netty2go.NettyWSHttpServer; | ||
import org.nustaq.webserver.WebSocketHttpServer; | ||
|
||
import java.io.File; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* Created by ruedi on 27.05.14. | ||
*/ | ||
public class TestServer extends WebSocketHttpServer { | ||
|
||
FSTConfiguration conf = FSTConfiguration.createCrossPlatformConfiguration(); | ||
static String ClassMap[][] = new String[][] { | ||
{ "person", Person.class.getName() }, | ||
{ "basicVals", BasicValues.class.getName() }, | ||
{ "mirror", MirrorRequest.class.getName() }, | ||
{ "testReq", TestRequest.class.getName() }, | ||
}; | ||
|
||
|
||
public TestServer(File contentRoot) { | ||
super(contentRoot); | ||
conf.registerCrossPlatformClassMapping(ClassMap); | ||
} | ||
|
||
@Override | ||
public void onOpen(ChannelHandlerContext ctx) { | ||
sendWSBinaryMessage( ctx, conf.asByteArray(new BasicValues()) ); | ||
} | ||
|
||
@Override | ||
public void onBinaryMessage(ChannelHandlerContext ctx, byte[] buffer) { | ||
Object msg = null; | ||
try { | ||
msg = conf.asObject(buffer); | ||
} catch (Throwable ex) { | ||
ex.printStackTrace(); | ||
} | ||
if (msg instanceof MirrorRequest) { | ||
sendWSBinaryMessage(ctx, conf.asByteArray((Serializable) msg)); | ||
} else { | ||
byte error[] = conf.asByteArray("Error"); | ||
sendWSBinaryMessage(ctx,error); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
int port; | ||
if (args.length > 0) { | ||
port = Integer.parseInt(args[0]); | ||
} else { | ||
port = 8887; | ||
} | ||
new NettyWSHttpServer(port, new TestServer(new File(".") )).run(); | ||
} | ||
} |
Oops, something went wrong.