• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Marshaller类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.grpc.MethodDescriptor.Marshaller的典型用法代码示例。如果您正苦于以下问题:Java Marshaller类的具体用法?Java Marshaller怎么用?Java Marshaller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Marshaller类属于io.grpc.MethodDescriptor包,在下文中一共展示了Marshaller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testJsonIoException

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@Test
public void testJsonIoException() throws Exception {
  Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
  final IOException ioe = new IOException();
  try {
    marshaller.parse(new ByteArrayInputStream("{}".getBytes("UTF-8")) {
      @Override
      public void close() throws IOException {
        throw ioe;
      }
    });
    fail("Exception expected");
  } catch (StatusRuntimeException ex) {
    assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
    assertEquals(ioe, ex.getCause());
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:ProtoUtilsTest.java


示例2: marshallerPrototype

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
private static Optional<Message> marshallerPrototype(Marshaller<?> marshaller) {
    if (marshaller instanceof PrototypeMarshaller) {
        Object prototype = ((PrototypeMarshaller) marshaller).getMessagePrototype();
        if (prototype instanceof Message) {
            return Optional.of((Message) prototype);
        }
    }
    return Optional.empty();
}
 
开发者ID:line,项目名称:armeria,代码行数:10,代码来源:GrpcJsonUtil.java


示例3: jsonMarshaller

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
/**
 * 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.
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1786")
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);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:12,代码来源:ProtoUtils.java


示例4: testRoundtrip

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@Test
public void testRoundtrip() throws Exception {
  Marshaller<Type> marshaller = ProtoUtils.marshaller(Type.getDefaultInstance());
  InputStream is = marshaller.stream(proto);
  is = new ByteArrayInputStream(ByteStreams.toByteArray(is));
  assertEquals(proto, marshaller.parse(is));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:ProtoUtilsTest.java


示例5: testJsonRoundtrip

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@Test
public void testJsonRoundtrip() throws Exception {
  Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
  InputStream is = marshaller.stream(proto);
  is = new ByteArrayInputStream(ByteStreams.toByteArray(is));
  assertEquals(proto, marshaller.parse(is));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:ProtoUtilsTest.java


示例6: testJsonRepresentation

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@Test
public void testJsonRepresentation() throws Exception {
  Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
  InputStream is = marshaller.stream(proto);
  String s = new String(ByteStreams.toByteArray(is), "UTF-8");
  assertEquals("{\"name\":\"value\"}", s.replaceAll("\\s", ""));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:ProtoUtilsTest.java


示例7: testJsonInvalid

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@Ignore("https://github.com/google/protobuf/issues/1470")
@Test
public void testJsonInvalid() throws Exception {
  Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
  try {
    marshaller.parse(new ByteArrayInputStream("{]".getBytes("UTF-8")));
    fail("Expected exception");
  } catch (StatusRuntimeException ex) {
    assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
    assertNotNull(ex.getCause());
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:13,代码来源:ProtoUtilsTest.java


示例8: testJsonInvalidProto

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@Test
public void testJsonInvalidProto() throws Exception {
  Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
  try {
    marshaller.parse(new ByteArrayInputStream("{\"\":3}".getBytes("UTF-8")));
    fail("Expected exception");
  } catch (StatusRuntimeException ex) {
    assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
    assertNotNull(ex.getCause());
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:12,代码来源:ProtoUtilsTest.java


示例9: testMismatch

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@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)));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:ProtoLiteUtilsTest.java


示例10: introspection

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@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());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:ProtoLiteUtilsTest.java


示例11: testEmpty

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@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());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:15,代码来源:ProtoLiteUtilsTest.java


示例12: parseFromKnowLengthInputStream

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
@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);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:9,代码来源:ProtoLiteUtilsTest.java


示例13: wrapClientInterceptor

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
public static <WReqT, WRespT> ClientInterceptor wrapClientInterceptor(
    final ClientInterceptor wrappedInterceptor,
    final Marshaller<WReqT> reqMarshaller,
    final Marshaller<WRespT> respMarshaller) {
  return ClientInterceptors.wrapClientInterceptor(
      wrappedInterceptor, reqMarshaller, respMarshaller);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:InternalClientInterceptors.java


示例14: marshallerType

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
private static MessageType marshallerType(Marshaller<?> marshaller) {
    return marshaller instanceof PrototypeMarshaller ? MessageType.PROTOBUF : MessageType.UNKNOWN;
}
 
开发者ID:line,项目名称:armeria,代码行数:4,代码来源:GrpcMessageMarshaller.java


示例15: marshaller

import io.grpc.MethodDescriptor.Marshaller; //导入依赖的package包/类
/** Create a {@code Marshaller} for protos of the same type as {@code defaultInstance}. */
public static <T extends Message> Marshaller<T> marshaller(final T defaultInstance) {
  return ProtoLiteUtils.marshaller(defaultInstance);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:5,代码来源:ProtoUtils.java



注:本文中的io.grpc.MethodDescriptor.Marshaller类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CacheDirectiveInfoExpirationProto类代码示例发布时间:2022-05-23
下一篇:
Java ScannerFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap