Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit a48aa65

Browse files
committed
Bring back ping request/response
1 parent 7b44a6a commit a48aa65

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

proto/semantic.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ package github.semantic;
77
option (haskell.haskell_package) = "Semantic.Proto";
88
option ruby_package = "Semantic::Proto";
99

10+
message PingRequest {
11+
string service = 1;
12+
}
13+
14+
message PingResponse {
15+
string status = 1;
16+
string hostname = 2;
17+
string timestamp = 3;
18+
string sha = 4;
19+
}
20+
1021
message ParseTreeRequest {
1122
repeated Blob blobs = 1;
1223
}

src/Semantic/Proto/SemanticPB.hs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,94 @@ import qualified Proto3.Suite as Proto3
1919
import Proto3.Suite.JSONPB as JSONPB
2020
import Proto3.Wire (at, oneof)
2121

22+
data PingRequest = PingRequest
23+
{ service :: Text
24+
} deriving stock (Eq, Ord, Show, Generic)
25+
deriving anyclass (Proto3.Named, NFData)
26+
27+
instance FromJSONPB PingRequest where
28+
parseJSONPB = A.withObject "PingRequest" $ \obj -> PingRequest
29+
<$> obj .: "service"
30+
31+
instance ToJSONPB PingRequest where
32+
toJSONPB PingRequest{..} = object
33+
[
34+
"service" .= service
35+
]
36+
toEncodingPB PingRequest{..} = pairs
37+
[
38+
"service" .= service
39+
]
40+
41+
instance FromJSON PingRequest where
42+
parseJSON = parseJSONPB
43+
44+
instance ToJSON PingRequest where
45+
toJSON = toAesonValue
46+
toEncoding = toAesonEncoding
47+
48+
instance Proto3.Message PingRequest where
49+
encodeMessage _ PingRequest{..} = mconcat
50+
[
51+
encodeMessageField 1 service
52+
]
53+
decodeMessage _ = PingRequest
54+
<$> at decodeMessageField 1
55+
dotProto = undefined
56+
57+
data PingResponse = PingResponse
58+
{ status :: Text
59+
, hostname :: Text
60+
, timestamp :: Text
61+
, sha :: Text
62+
} deriving stock (Eq, Ord, Show, Generic)
63+
deriving anyclass (Proto3.Named, NFData)
64+
65+
instance FromJSONPB PingResponse where
66+
parseJSONPB = A.withObject "PingResponse" $ \obj -> PingResponse
67+
<$> obj .: "status"
68+
<*> obj .: "hostname"
69+
<*> obj .: "timestamp"
70+
<*> obj .: "sha"
71+
72+
instance ToJSONPB PingResponse where
73+
toJSONPB PingResponse{..} = object
74+
[
75+
"status" .= status
76+
, "hostname" .= hostname
77+
, "timestamp" .= timestamp
78+
, "sha" .= sha
79+
]
80+
toEncodingPB PingResponse{..} = pairs
81+
[
82+
"status" .= status
83+
, "hostname" .= hostname
84+
, "timestamp" .= timestamp
85+
, "sha" .= sha
86+
]
87+
88+
instance FromJSON PingResponse where
89+
parseJSON = parseJSONPB
90+
91+
instance ToJSON PingResponse where
92+
toJSON = toAesonValue
93+
toEncoding = toAesonEncoding
94+
95+
instance Proto3.Message PingResponse where
96+
encodeMessage _ PingResponse{..} = mconcat
97+
[
98+
encodeMessageField 1 status
99+
, encodeMessageField 2 hostname
100+
, encodeMessageField 3 timestamp
101+
, encodeMessageField 4 sha
102+
]
103+
decodeMessage _ = PingResponse
104+
<$> at decodeMessageField 1
105+
<*> at decodeMessageField 2
106+
<*> at decodeMessageField 3
107+
<*> at decodeMessageField 4
108+
dotProto = undefined
109+
22110
data ParseTreeRequest = ParseTreeRequest
23111
{ blobs :: Vector Blob
24112
} deriving stock (Eq, Ord, Show, Generic)

0 commit comments

Comments
 (0)