Skip to content

Commit b86daf5

Browse files
committed
Add convenience PlaytakCodec.encode and PlaytakCodec.decode
So people don't have to read the garble in Incoming/Outgoing objects
1 parent f11d9ac commit b86daf5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

opentak/src/main/scala/com/github/daenyth/opentak/protocol/PlaytakCodec.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ import com.github.daenyth.taklib._
66

77
import scala.util.parsing.combinator.RegexParsers
88

9+
/**
10+
* Playtak protocol encoding/decoding between the wire
11+
* representation (string) and in-library representation (case classes)
12+
*
13+
* See PlaytakCodec#encode and PlaytakCodec#decode
14+
*/
915
object PlaytakCodec {
16+
def encode(outgoing: Playtak.Outgoing): String =
17+
Outgoing.encode(outgoing)
18+
def decode(input: String): Either[String, Playtak.Incoming] =
19+
Incoming.parseEither(Incoming.incoming, input).toEither
20+
21+
/* Abandon hope all ye who scroll below here */
1022

1123
object Incoming extends RegexParsers with RichParsing {
1224
def decode(input: String): Either[String, Playtak.Incoming] =

0 commit comments

Comments
 (0)