类io.grpc.MethodDescriptor.Marshaller源码实例Demo

下面列出了怎么用io.grpc.MethodDescriptor.Marshaller的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: grpc-nebula-java   文件: BinlogHelper.java
@Override
<T> void logRpcMessage(
    long seq,
    EventType eventType,
    Marshaller<T> marshaller,
    T message,
    GrpcLogEntry.Logger logger,
    long callId) {
  Preconditions.checkArgument(
      eventType == EventType.EVENT_TYPE_CLIENT_MESSAGE
          || eventType == EventType.EVENT_TYPE_SERVER_MESSAGE,
      "event type must correspond to client message or server message");
  if (marshaller != BYTEARRAY_MARSHALLER) {
    throw new IllegalStateException("Expected the BinaryLog's ByteArrayMarshaller");
  }
  MaybeTruncated<Message.Builder> pair = createMessageProto((byte[]) message, maxMessageBytes);
  GrpcLogEntry.Builder entryBuilder = newTimestampedBuilder()
      .setSequenceIdWithinCall(seq)
      .setType(eventType)
      .setMessage(pair.proto)
      .setPayloadTruncated(pair.truncated)
      .setLogger(logger)
      .setCallId(callId);
  sink.write(entryBuilder.build());
}
 
源代码2 项目: grpc-java   文件: BinlogHelper.java
@Override
<T> void logRpcMessage(
    long seq,
    EventType eventType,
    Marshaller<T> marshaller,
    T message,
    GrpcLogEntry.Logger logger,
    long callId) {
  Preconditions.checkArgument(
      eventType == EventType.EVENT_TYPE_CLIENT_MESSAGE
          || eventType == EventType.EVENT_TYPE_SERVER_MESSAGE,
      "event type must correspond to client message or server message");
  if (marshaller != BYTEARRAY_MARSHALLER) {
    throw new IllegalStateException("Expected the BinaryLog's ByteArrayMarshaller");
  }
  MaybeTruncated<Message.Builder> pair = createMessageProto((byte[]) message, maxMessageBytes);
  GrpcLogEntry.Builder entryBuilder = newTimestampedBuilder()
      .setSequenceIdWithinCall(seq)
      .setType(eventType)
      .setMessage(pair.proto)
      .setPayloadTruncated(pair.truncated)
      .setLogger(logger)
      .setCallId(callId);
  sink.write(entryBuilder.build());
}
 
源代码3 项目: grpc-nebula-java   文件: ProtoLiteUtilsTest.java
@Test
public void testMismatch() throws Exception {
  Marshaller<Enum> enumMarshaller = ProtoLiteUtils.marshaller(Enum.getDefaultInstance());
  // Enum's name and Type's name are both strings with tag 1.
  Enum altProto = Enum.newBuilder().setName(proto.getName()).build();
  assertEquals(proto, marshaller.parse(enumMarshaller.stream(altProto)));
}
 
源代码4 项目: grpc-nebula-java   文件: ProtoLiteUtilsTest.java
@Test
public void introspection() throws Exception {
  Marshaller<Enum> enumMarshaller = ProtoLiteUtils.marshaller(Enum.getDefaultInstance());
  PrototypeMarshaller<Enum> prototypeMarshaller = (PrototypeMarshaller<Enum>) enumMarshaller;
  assertSame(Enum.getDefaultInstance(), prototypeMarshaller.getMessagePrototype());
  assertSame(Enum.class, prototypeMarshaller.getMessageClass());
}
 
源代码5 项目: grpc-nebula-java   文件: ProtoLiteUtilsTest.java
@Test
public void testEmpty() throws IOException {
  Marshaller<Empty> marshaller = ProtoLiteUtils.marshaller(Empty.getDefaultInstance());
  InputStream is = marshaller.stream(Empty.getDefaultInstance());
  assertEquals(0, is.available());
  byte[] b = new byte[10];
  assertEquals(-1, is.read(b));
  assertArrayEquals(new byte[10], b);
  // Do the same thing again, because the internal state may be different
  assertEquals(-1, is.read(b));
  assertArrayEquals(new byte[10], b);
  assertEquals(-1, is.read());
  assertEquals(0, is.available());
}
 
源代码6 项目: grpc-nebula-java   文件: ProtoLiteUtilsTest.java
@Test
public void parseFromKnowLengthInputStream() throws Exception {
  Marshaller<Type> marshaller = ProtoLiteUtils.marshaller(Type.getDefaultInstance());
  Type expect = Type.newBuilder().setName("expected name").build();

  Type result = marshaller.parse(new CustomKnownLengthInputStream(expect.toByteArray()));
  assertEquals(expect, result);
}
 
源代码7 项目: grpc-nebula-java   文件: BinlogHelper.java
/**
 * Logs the message message. The number of bytes logged is determined by the binary
 * logging configuration.
 */
abstract <T> void logRpcMessage(
    long seq,
    EventType eventType,
    Marshaller<T> marshaller,
    T message,
    GrpcLogEntry.Logger logger,
    long callId);
 
源代码8 项目: armeria   文件: DefaultJsonMarshaller.java
@Override
public <T> T deserializeMessage(Marshaller<T> marshaller, InputStream is) throws IOException {
    final PrototypeMarshaller<T> prototypeMarshaller = (PrototypeMarshaller<T>) marshaller;
    final Message prototype = (Message) prototypeMarshaller.getMessagePrototype();
    final Message.Builder builder = prototype.newBuilderForType();
    delegate.mergeValue(is, builder);
    @SuppressWarnings("unchecked")
    final T cast = (T) builder.build();
    return cast;
}
 
源代码9 项目: armeria   文件: GrpcJsonUtil.java
@Nullable
private static Message marshallerPrototype(Marshaller<?> marshaller) {
    if (marshaller instanceof PrototypeMarshaller) {
        final Object prototype = ((PrototypeMarshaller<?>) marshaller).getMessagePrototype();
        if (prototype instanceof Message) {
            return (Message) prototype;
        }
    }
    return null;
}
 
源代码10 项目: grpc-java   文件: MethodDescriptorTest.java
@Test
public void getServiceName_extractsService() {
  Marshaller<Void> marshaller = TestMethodDescriptors.voidMarshaller();
  MethodDescriptor<?, ?> md = MethodDescriptor.newBuilder(marshaller, marshaller)
      .setType(MethodType.UNARY)
      .setFullMethodName("foo/bar")
      .build();

  assertEquals("foo", md.getServiceName());
}
 
源代码11 项目: grpc-java   文件: MethodDescriptorTest.java
@Test
public void getServiceName_returnsNull() {
  Marshaller<Void> marshaller = TestMethodDescriptors.voidMarshaller();
  MethodDescriptor<?, ?> md = MethodDescriptor.newBuilder(marshaller, marshaller)
      .setType(MethodType.UNARY)
      .setFullMethodName("foo-bar")
      .build();

  assertNull(md.getServiceName());
}
 
源代码12 项目: grpc-java   文件: ProtoLiteUtilsTest.java
@Test
public void testMismatch() throws Exception {
  Marshaller<Enum> enumMarshaller = ProtoLiteUtils.marshaller(Enum.getDefaultInstance());
  // Enum's name and Type's name are both strings with tag 1.
  Enum altProto = Enum.newBuilder().setName(proto.getName()).build();
  assertEquals(proto, marshaller.parse(enumMarshaller.stream(altProto)));
}
 
源代码13 项目: grpc-java   文件: ProtoLiteUtilsTest.java
@Test
public void introspection() throws Exception {
  Marshaller<Enum> enumMarshaller = ProtoLiteUtils.marshaller(Enum.getDefaultInstance());
  PrototypeMarshaller<Enum> prototypeMarshaller = (PrototypeMarshaller<Enum>) enumMarshaller;
  assertSame(Enum.getDefaultInstance(), prototypeMarshaller.getMessagePrototype());
  assertSame(Enum.class, prototypeMarshaller.getMessageClass());
}
 
源代码14 项目: grpc-java   文件: ProtoLiteUtilsTest.java
@Test
public void testEmpty() throws IOException {
  Marshaller<Empty> marshaller = ProtoLiteUtils.marshaller(Empty.getDefaultInstance());
  InputStream is = marshaller.stream(Empty.getDefaultInstance());
  assertEquals(0, is.available());
  byte[] b = new byte[10];
  assertEquals(-1, is.read(b));
  assertArrayEquals(new byte[10], b);
  // Do the same thing again, because the internal state may be different
  assertEquals(-1, is.read(b));
  assertArrayEquals(new byte[10], b);
  assertEquals(-1, is.read());
  assertEquals(0, is.available());
}
 
源代码15 项目: grpc-java   文件: ProtoLiteUtilsTest.java
@Test
public void parseFromKnowLengthInputStream() throws Exception {
  Marshaller<Type> marshaller = ProtoLiteUtils.marshaller(Type.getDefaultInstance());
  Type expect = Type.newBuilder().setName("expected name").build();

  Type result = marshaller.parse(new CustomKnownLengthInputStream(expect.toByteArray()));
  assertEquals(expect, result);
}
 
源代码16 项目: grpc-java   文件: BinlogHelper.java
/**
 * Logs the message message. The number of bytes logged is determined by the binary
 * logging configuration.
 */
abstract <T> void logRpcMessage(
    long seq,
    EventType eventType,
    Marshaller<T> marshaller,
    T message,
    GrpcLogEntry.Logger logger,
    long callId);
 
源代码17 项目: grpc-nebula-java   文件: JsonMarshaller.java
/**
 * Create a {@code Marshaller} for json protos of the same type as {@code defaultInstance}.
 *
 * <p>This is an unstable API and has not been optimized yet for performance.
 */
public static <T extends Message> Marshaller<T> jsonMarshaller(final T defaultInstance) {
  final Parser parser = JsonFormat.parser();
  final Printer printer = JsonFormat.printer();
  return jsonMarshaller(defaultInstance, parser, printer);
}
 
源代码18 项目: grpc-nebula-java   文件: BinaryLogProviderTest.java
@Override
Marshaller<String> delegate() {
  return StringMarshaller.INSTANCE;
}
 
源代码19 项目: grpc-nebula-java   文件: BinaryLogProviderTest.java
@Override
Marshaller<Integer> delegate() {
  return IntegerMarshaller.INSTANCE;
}
 
public static <ReqT, RespT> ClientInterceptor wrapClientInterceptor(
    final ClientInterceptor interceptor,
    final Marshaller<ReqT> reqMarshaller,
    final Marshaller<RespT> respMarshaller) {
  return ClientInterceptors.wrapClientInterceptor(interceptor, reqMarshaller, respMarshaller);
}
 
源代码21 项目: armeria   文件: DefaultJsonMarshaller.java
@Override
public <T> void serializeMessage(Marshaller<T> marshaller, T message, OutputStream os) throws IOException {
    delegate.writeValue((Message) message, os);
}
 
源代码22 项目: armeria   文件: GrpcMessageMarshaller.java
private static MessageType marshallerType(Marshaller<?> marshaller) {
    return marshaller instanceof PrototypeMarshaller ? MessageType.PROTOBUF : MessageType.UNKNOWN;
}
 
源代码23 项目: grpc-java   文件: JsonMarshaller.java
/**
 * Create a {@code Marshaller} for json protos of the same type as {@code defaultInstance}.
 *
 * <p>This is an unstable API and has not been optimized yet for performance.
 */
public static <T extends Message> Marshaller<T> jsonMarshaller(final T defaultInstance) {
  final Parser parser = JsonFormat.parser();
  final Printer printer = JsonFormat.printer();
  return jsonMarshaller(defaultInstance, parser, printer);
}
 
源代码24 项目: grpc-java   文件: InternalClientInterceptors.java
public static <ReqT, RespT> ClientInterceptor wrapClientInterceptor(
    final ClientInterceptor interceptor,
    final Marshaller<ReqT> reqMarshaller,
    final Marshaller<RespT> respMarshaller) {
  return ClientInterceptors.wrapClientInterceptor(interceptor, reqMarshaller, respMarshaller);
}
 
源代码25 项目: grpc-java   文件: BinaryLogProviderTest.java
@Override
Marshaller<String> delegate() {
  return StringMarshaller.INSTANCE;
}
 
源代码26 项目: grpc-java   文件: BinaryLogProviderTest.java
@Override
Marshaller<Integer> delegate() {
  return IntegerMarshaller.INSTANCE;
}
 
源代码27 项目: grpc-nebula-java   文件: ProtoUtils.java
/**
 * Create a {@link Marshaller} for protos of the same type as {@code defaultInstance}.
 *
 * @since 1.0.0
 */
public static <T extends Message> Marshaller<T> marshaller(final T defaultInstance) {
  return ProtoLiteUtils.marshaller(defaultInstance);
}
 
源代码28 项目: grpc-nebula-java   文件: ProtoLiteUtils.java
/**
 * Creates a {@link Marshaller} for protos of the same type as {@code defaultInstance}.
 *
 * @since 1.0.0
 */
public static <T extends MessageLite> Marshaller<T> marshaller(T defaultInstance) {
  // TODO(ejona): consider changing return type to PrototypeMarshaller (assuming ABI safe)
  return new MessageMarshaller<T>(defaultInstance);
}
 
源代码29 项目: grpc-nebula-java   文件: NanoUtils.java
/**
 * Adapt {@code parser} to a {@link Marshaller}.
 *
 * @since 1.0.0
 */
public static <T extends MessageNano> Marshaller<T> marshaller(MessageNanoFactory<T> factory) {
  return new MessageMarshaller<T>(factory);
}
 
源代码30 项目: armeria   文件: GrpcJsonMarshaller.java
/**
 * Serializes a gRPC message into JSON.
 */
<T> void serializeMessage(Marshaller<T> marshaller, T message, OutputStream os) throws IOException;
 
 类所在包
 类方法
 同包方法