Created
October 10, 2012 14:29
-
-
Save Ahnfelt/3865983 to your computer and use it in GitHub Desktop.
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
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