Search in sources :

Example 1 with Metadata

use of com.alibaba.nacos.api.grpc.auto.Metadata in project nacos by alibaba.

the class GrpcUtils method convert.

/**
 * convert request to payload.
 *
 * @param request request.
 * @return payload.
 */
public static Payload convert(Request request) {
    Metadata newMeta = Metadata.newBuilder().setType(request.getClass().getSimpleName()).setClientIp(NetUtils.localIP()).putAllHeaders(request.getHeaders()).build();
    request.clearHeaders();
    String jsonString = toJson(request);
    Payload.Builder builder = Payload.newBuilder();
    return builder.setBody(Any.newBuilder().setValue(ByteString.copyFrom(jsonString, StandardCharsets.UTF_8))).setMetadata(newMeta).build();
}
Also used : Metadata(com.alibaba.nacos.api.grpc.auto.Metadata) Payload(com.alibaba.nacos.api.grpc.auto.Payload) ByteString(com.google.protobuf.ByteString)

Aggregations

Metadata (com.alibaba.nacos.api.grpc.auto.Metadata)1 Payload (com.alibaba.nacos.api.grpc.auto.Payload)1 ByteString (com.google.protobuf.ByteString)1