-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectJsonSerializer.java
More file actions
42 lines (39 loc) · 1.55 KB
/
Copy pathConnectJsonSerializer.java
File metadata and controls
42 lines (39 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package io.suboptimal.connectjava.protocol.server;
import io.suboptimal.connectjava.api.ConnectError;
/**
* SPI for serializing Connect protocol JSON bodies to bytes.
*
* <p>Two call sites exist in the Connect implementation:
* <ul>
* <li>Unary error responses — produced by {@link #error(ConnectError)} and written as the
* HTTP response body with an appropriate Connect error HTTP status code.</li>
* <li>Streaming EndStreamResponse envelopes — produced by
* {@link #endStream(ConnectEndStreamResponse)} and written as the final framed envelope
* with flag {@code 0x02}.</li>
* </ul>
*
* <p>The default implementation is {@link ConnectStringBuilderJsonSerializer#INSTANCE}.
* A custom implementation (e.g. Jackson-based) can be supplied via
* {@link ConnectProtocolConfig.Builder#jsonSerializer(ConnectJsonSerializer)}.
*/
public interface ConnectJsonSerializer {
/**
* Serializes a Connect error to a UTF-8 JSON body.
*
* <p>Example output: {@code {"code":"unimplemented","message":"not supported"}}
*
* @param error the Connect error to serialize
* @return UTF-8-encoded JSON bytes
*/
byte[] error(ConnectError error);
/**
* Serializes a Connect EndStreamResponse to a UTF-8 JSON body.
*
* <p>Example output for a successful completion with trailer metadata:
* {@code {"metadata":{"grpc-status":["0"]}}}
*
* @param message the end-stream response to serialize
* @return UTF-8-encoded JSON bytes
*/
byte[] endStream(ConnectEndStreamResponse message);
}