Skip to content

Commit

Permalink
tweak ResponseFor json stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sullyj3 committed Aug 3, 2024
1 parent 0beb5aa commit ed1eb70
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Sand/Message.lean
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,23 @@ abbrev ResponseFor : Command → Type
| .pauseTimer _ => PauseTimerResponse
| .resumeTimer _ => ResumeTimerResponse

def toJsonResponse {cmd : Command} (resp : ResponseFor cmd) : Lean.Json := by
cases cmd <;> exact toJson resp
def responseForToJson {cmd : Command} : ToJson (ResponseFor cmd) := by
cases cmd <;> exact inferInstance

def responseForFromJson {cmd : Command} : FromJson (ResponseFor cmd) := by
cases cmd <;> exact inferInstance

def toJsonResponse {cmd : Command} (resp : ResponseFor cmd) : Lean.Json :=
have : ToJson (ResponseFor cmd) := responseForToJson
toJson resp

def serializeResponse {cmd : Command} (resp : ResponseFor cmd) : ByteArray :=
String.toUTF8 <| toString <| toJsonResponse resp

def fromJsonResponse? {cmd : Command}
(resp : Json) : Except String (ResponseFor cmd) := by
cases cmd <;> exact fromJson? resp
(resp : Json) : Except String (ResponseFor cmd) :=
have : FromJson (ResponseFor cmd) := responseForFromJson
fromJson? resp


end Sand

0 comments on commit ed1eb70

Please sign in to comment.