Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tapasco
tapasco
Commits
10730b41
Commit
10730b41
authored
Jan 02, 2018
by
Jens Korinth
Browse files
Structure JSON SerDes code
parent
cc738039
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/scala/json.scala
View file @
10730b41
...
...
@@ -6,6 +6,7 @@ import play.api.libs.json.Reads._
import
play.api.libs.functional.syntax._
package
object
json
{
/** @{ Id formats */
implicit
object
SlotIdFormats
extends
Format
[
SlotId
]
{
def
reads
(
json
:
JsValue
)
:
JsResult
[
SlotId
]
=
json
match
{
case
JsNumber
(
n
)
=>
JsSuccess
(
SlotId
(
n
.
toInt
))
...
...
@@ -29,7 +30,9 @@ package object json {
}
def
writes
(
sz
:
Size
)
:
JsValue
=
Json
.
toJson
(
sz
:
Int
)
}
/** Id formats @} */
/** @{ Slot.Kernel */
implicit
val
kernelWrites
:
Writes
[
Kernel
]
=
(
(
JsPath
\
"Type"
).
write
[
String
]
~
(
JsPath
\
"SlotId"
).
write
[
SlotId
]
~
...
...
@@ -41,7 +44,9 @@ package object json {
(
JsPath
\
"SlotId"
).
read
[
SlotId
]
~
(
JsPath
\
"Kernel"
).
read
[
KernelId
]
)
(
Kernel
.
apply
_
)
/** Slot.Kernel @} */
/** @{ Slot.Memory */
implicit
val
memoryWrites
:
Writes
[
Memory
]
=
(
(
JsPath
\
"Type"
).
write
[
String
]
~
(
JsPath
\
"SlotId"
).
write
[
SlotId
]
~
...
...
@@ -53,7 +58,9 @@ package object json {
(
JsPath
\
"SlotId"
).
read
[
SlotId
]
~
(
JsPath
\
"Bytes"
).
read
[
Size
]
)
(
Memory
.
apply
_
)
/** Slot.Memory @} */
/** @{ Slot */
implicit
val
slotReads
:
Reads
[
Slot
]
=
kernelReads
|
memoryReads
implicit
object
SlotWrites
extends
Writes
[
Slot
]
{
...
...
@@ -62,7 +69,9 @@ package object json {
case
m
:
Memory
=>
memoryWrites
.
writes
(
m
)
}
}
/** Slot @} */
/** @{ Versions */
implicit
val
versionWrites
:
Writes
[
Versions.Version
]
=
(
(
JsPath
\
"Software"
).
write
[
String
]
~
(
JsPath
\
"Year"
).
write
[
Int
]
~
...
...
@@ -106,7 +115,9 @@ package object json {
}
def
writes
(
v
:
Versions
)
:
JsValue
=
Json
.
toJson
(
Seq
(
v
.
vivado
,
v
.
tapasco
))
}
/** Versions @} */
/** @{ Clocks */
implicit
val
freqWrites
:
Writes
[
Clocks.Frequency
]
=
(
(
JsPath
\
"Domain"
).
write
[
String
]
~
(
JsPath
\
"Frequency"
).
write
[
Double
]
...
...
@@ -140,7 +151,9 @@ package object json {
}
def
writes
(
c
:
Clocks
)
:
JsValue
=
Json
.
toJson
(
Seq
(
c
.
host
,
c
.
design
,
c
.
memory
))
}
/** Clocks @} */
/** @{ Status */
implicit
val
statusFormat
:
Format
[
Status
]
=
(
(
JsPath
\
"Composition"
).
format
[
Seq
[
Slot
]]
~
(
JsPath
\
"Timestamp"
).
format
[
Int
]
~
...
...
@@ -148,4 +161,6 @@ package object json {
(
JsPath
\
"Versions"
).
format
[
Versions
]
~
(
JsPath
\
"Clocks"
).
format
[
Clocks
]
)
(
Status
.
apply
_
,
unlift
(
Status
.
unapply
_
))
/** Status @} */
}
// vim: foldmethod=marker foldmarker=@{,@} foldlevel=0
Jens Korinth
@jk
mentioned in commit
17f0d672
·
Mar 05, 2018
mentioned in commit
17f0d672
mentioned in commit 17f0d67240ebf5d7e1d0be9162d272b04256c47d
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment