This repository has been archived by the owner on Dec 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added message confirmations to protocol (ref #22).
- Loading branch information
Showing
16 changed files
with
207 additions
and
75 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
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
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
49 changes: 49 additions & 0 deletions
49
core/src/main/scala/com/nutomic/ensichat/core/body/MessageReceived.scala
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,49 @@ | ||
package com.nutomic.ensichat.core.body | ||
|
||
import java.nio.ByteBuffer | ||
|
||
import com.nutomic.ensichat.core.Message | ||
import com.nutomic.ensichat.core.util.BufferUtils | ||
|
||
import scala.Predef.String | ||
|
||
object MessageReceived { | ||
|
||
val Type = 8 | ||
|
||
/** | ||
* Constructs [[Text]] instance from byte array. | ||
*/ | ||
def read(array: Array[Byte]): MessageReceived = { | ||
val b = ByteBuffer.wrap(array) | ||
val messageId = BufferUtils.getUnsignedInt(b) | ||
new MessageReceived(messageId) | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Holds a plain text message. | ||
*/ | ||
final case class MessageReceived(messageId: Long) extends MessageBody { | ||
|
||
override def protocolType = -1 | ||
|
||
override def contentType = MessageReceived.Type | ||
|
||
override def write: Array[Byte] = { | ||
val b = ByteBuffer.allocate(length) | ||
// TODO: This should be putUnsignedLong, but doesn't seem possible in the JVM. | ||
// Alternatively, we could use signed ints instead. | ||
BufferUtils.putUnsignedInt(b, messageId) | ||
b.array() | ||
} | ||
|
||
override def length = 4 | ||
|
||
override def equals(a: Any): Boolean = a match { | ||
case o: MessageReceived => messageId == o.messageId | ||
case _ => false | ||
} | ||
|
||
} |
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
Oops, something went wrong.