Various fixes to ChatMsg (#43)

* Add BinaryChoiceCodec

* Proper ChatMsg structuring
This commit is contained in:
tfarley 2016-07-28 19:23:38 -07:00 committed by pschord
parent 4fb13fdc57
commit fc2ef50be6
5 changed files with 61 additions and 22 deletions

View file

@ -164,40 +164,42 @@ class GamePacketTest extends Specification {
ok
}
}
"ChatMsg" should {
val string_local = hex"12 1A C000 83610062006300"
val string_tell = hex"12 20 C180640065006600 83610062006300"
"decode" in {
PacketCoding.DecodePacket(string_local).require match {
case ChatMsg(messagetype, unk1, recipient, contents) =>
case ChatMsg(messagetype, has_wide_contents, recipient, contents, note_contents) =>
messagetype mustEqual ChatMessageType.Local
unk1 mustEqual true
has_wide_contents mustEqual true
recipient mustEqual ""
contents mustEqual "abc"
note_contents mustEqual None
case default =>
ko
}
PacketCoding.DecodePacket(string_tell).require match {
case ChatMsg(messagetype, unk1, recipient, contents) =>
case ChatMsg(messagetype, has_wide_contents, recipient, contents, note_contents) =>
messagetype mustEqual ChatMessageType.Tell
unk1 mustEqual true
has_wide_contents mustEqual true
recipient mustEqual "def"
contents mustEqual "abc"
note_contents mustEqual None
case default =>
ko
}
}
"encode" in {
val msg_local = ChatMsg(ChatMessageType.Local, true, "", "abc")
val msg_local = ChatMsg(ChatMessageType.Local, true, "", "abc", None)
val pkt_local = PacketCoding.EncodePacket(msg_local).require.toByteVector
pkt_local mustEqual string_local
val msg_tell = ChatMsg(ChatMessageType.Tell, true, "def", "abc")
val msg_tell = ChatMsg(ChatMessageType.Tell, true, "def", "abc", None)
val pkt_tell = PacketCoding.EncodePacket(msg_tell).require.toByteVector
pkt_tell mustEqual string_tell