Package protocols.apps.chat
Class ChatPayload
java.lang.Object
protocols.apps.chat.ChatPayload
The chat's own little "application protocol" that rides inside the
broadcast's opaque
byte[] payload. The broadcast layer doesn't know or
care what these bytes mean — that's the whole point of layering: the broadcast
moves bytes; the application decides what they are.
Two things travel by broadcast (i.e. to everyone):
ChatPayload.Kind.TEXT— a message to the global channel (nick+text);ChatPayload.Kind.LEAVE— "I'm leaving" on a graceful/quit(nick).
ChatDirectMessage.
We hand-roll a tiny encoding with DataOutputStream (1 byte kind, then
two length-prefixed UTF strings) so the wire format is obvious to a reader.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ChatPayload
-
-
Method Details
-
getKind
-
getNick
-
getText
-
encode
public byte[] encode()Serialize to the bytes carried inside a broadcast message. -
decode
Parse the bytes delivered by the broadcast layer back into a payload.
-