This file contains hidden or 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
| def decode(buf: ByteBuffer): List[Any] = { | |
| val msgs = List.newBuilder[Any] | |
| var input = charset.decode(buf).toString | |
| breakable { | |
| while (true) { | |
| val index = input.indexOf(inputDelimiter) | |
| if (index < 0) break | |
| msgs += input.substring(0, index) | |
| input = input.substring(index + inputDelimiter.length) |
This file contains hidden or 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
| package org.elves | |
| import java.nio.charset.Charset | |
| import java.nio.{CharBuffer, ByteBuffer} | |
| import scala.annotation.tailrec | |
| class DelimitedTextProtocol(inputDelimiter: String, outputDelimiter: String, charset: Charset) extends Protocol { | |
| def encode(session: Session, o: Any): ByteBuffer = ByteBuffer wrap (o.toString + outputDelimiter).getBytes(charset) | |
| def decode(session: Session, buf: ByteBuffer): List[Any] = { |
This file contains hidden or 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
| val dataBuilder = StringBuilder.newBuilder | |
| session.bufferOption match { | |
| case Some(buffer) => | |
| dataBuilder ++= buffer.result().mkString | |
| buffer.clear() | |
| case _ => | |
| } | |
| o match { |
This file contains hidden or 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
| trait Context // todo | |
| trait DofusMessage // todo | |
| object DofusProtocol extends DelimitedTextProtocol("\u0000", "\n\u0000") { | |
| def encode(o: Any): Any = o match { | |
| case msg: DofusMessage => super.encode(msg.serialize()) | |
| case msg: String => super.encode(msg) | |
| } | |
| def decode(o: Any): Any = super.decode(o) match { |
This file contains hidden or 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
| implicit class Times(val end: Int) extends AnyVal { | |
| def times[T, Result](f: => T)(implicit cbf: CanBuildFrom[_, T, Result]): Result = { | |
| val builder = cbf() | |
| var i = 0 | |
| while (i > end) { | |
| builder += f | |
| i += 1 | |
| } | |
| builder.result() |
This file contains hidden or 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
| MS4wMzZ8fDEzODAxODQyMzY0OTB8MTExMTExfDYxNzk1ODUyOzIwNTE5NTc5NzsyMDAwOzI7NDcwNzQ7OTstMTstMTswOzA7MDswOzA7MHwzOSwzOSwxMjI2ODk0LDA7NDUsNDUsMTQxMzUwNywwOzE5LDE5LDUyNjg2OCwwOzE1LDE1LDE4NTYxMDMsMDsxMiwxMiw0NTA3Mzk4LDA7MTIsMTIsNjU1MjMwMCwwOzEyLDEyLDE4NTMyNDI2LDA7MTQsMTQsMTYyMzUzOTYwLDA7MCwwLDAsMDswLDAsMCwwO3wzMzYwMTA3NTM0NDUxMTk5OzIyNTE4MDIxNDAxMzk1Njc7MjI1MTc5OTgxNDE3Njc2OTsyMjUxNzk5ODEzNjg1MjU1OzUyNDI4OXwzNTM4MzMzNjUzMTM5OTY3Ozg3OTYxMzUyMjc5Nzc%3D%21END%21 |
This file contains hidden or 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
| package org.photon.login | |
| import com.twitter.util.Future | |
| trait NetClient { | |
| type NetService | |
| def service: NetService | |
| def closeFuture: Future[this.type] |
This file contains hidden or 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
| trait ConfigComponent { | |
| trait Config { | |
| def get[T](key: String): T | |
| } | |
| val config: Config | |
| } | |
| trait ConfigComponentImpl extends ConfigComponent { | |
| class ConfigImpl extends Config { |
This file contains hidden or 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
| package org.photon.login | |
| import com.twitter.util.Future | |
| trait NetworkSession { | |
| type TFut = Future[this.type] | |
| type NetworkService <: org.photon.login.NetworkService | |
| def service: NetworkService |
This file contains hidden or 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
| /** | |
| * should speed up Map implementations | |
| */ | |
| sealed class Opcode(value: String) { | |
| if (value.length != 2) | |
| throw new IllegalArgumentException("an opcode must be a 2 fixed length string") | |
| def toString = value | |
| val hashCode = value(0).toByte << 8 + value(1).toByte // must be unique |