Skip to content

Instantly share code, notes, and snippets.

@Ahnfelt
Created October 10, 2012 14:29
Show Gist options
  • Save Ahnfelt/3865983 to your computer and use it in GitHub Desktop.
Save Ahnfelt/3865983 to your computer and use it in GitHub Desktop.
public void writeTag(int tag) throws SerializationException {
try {
if(tag < 128) {
stream.writeByte(tag - 128);
} else {
stream.writeInt(tag);
}
} catch(IOException e) {
throw new SerializationException(e);
}
}
public int readTag() throws SerializationException {
try {
int tag = stream.readByte();
if(tag > 0) {
buffer.rewind();
buffer.put((byte) tag);
buffer.put(stream.readByte());
buffer.put(stream.readByte());
buffer.put(stream.readByte());
buffer.rewind();
return buffer.getInt();
} else {
return tag + 128;
}
} catch(IOException e) {
throw new SerializationException(e);
}
}
@Test
public void testService() {
final UppercaseServiceServerModule module = new UppercaseServiceServerModule(new UppercaseService() {
public String uppercase(String text) {
return text.toUpperCase();
}
});
new Thread(new Runnable() {
public void run() {
new ServiceServer(1337, module);
}
}, "Server").start();
UppercaseService service = new UppercaseServiceClient("localhost", 1337);
assertEquals("FOO", service.uppercase("foo"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment