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

Java GeneratedMessageV3类代码示例

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

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



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

示例1: PROTOBUF_MARSHALLER

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
/**
 * A metadata marshaller that encodes objects as protobuf according to their proto IDL specification.
 *
 * @param clazz the type to serialize
 * @param <T>
 */
public static <T extends GeneratedMessageV3> Metadata.BinaryMarshaller<T> PROTOBUF_MARSHALLER(Class<T> clazz) {
    try {
        Method defaultInstance = clazz.getMethod("getDefaultInstance");
        GeneratedMessageV3 instance = (GeneratedMessageV3) defaultInstance.invoke(null);

        return new Metadata.BinaryMarshaller<T>() {
            @Override
            public byte[] toBytes(T value) {
                return value.toByteArray();
            }

            @SuppressWarnings("unchecked")
            @Override
            public T parseBytes(byte[] serialized) {
                try {
                    return (T) instance.getParserForType().parseFrom(serialized);
                } catch (InvalidProtocolBufferException ipbe) {
                    throw new IllegalArgumentException(ipbe);
                }
            }
        };
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:32,代码来源:MoreMetadata.java


示例2: generateEvents

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
private static ImmutableList<GeneratedMessageV3> generateEvents() {
    final ProjectId ALPHA = projectId("alpha");
    final Task task1 = newTask(ALPHA, "Annotate internal API", "Use @Internal annotation.");
    final TaskId taskId1 = task1.getId();

    return ImmutableList.of(
            ProjectCreated.newBuilder().setProject(newProject(ALPHA.getCode(), "Alpha", "Initial public release.")).build(),
            TaskCreated.newBuilder().setTask(task1).build(),
            TaskAssigned.newBuilder()
                    .setTaskId(taskId1)
                    .setAssignee(randomSelectUser()).build(),
            TaskCreated.newBuilder().setTask(newTask(ALPHA, "Check code coverage", "")).build(),
            TaskCreated.newBuilder().setTask(newTask(ALPHA, "Verify JavaDocs", "")).build(),
            TaskDone.newBuilder().setTaskId(taskId1).build(),
            TaskCreated.newBuilder().setTask(newTask(ALPHA, "Blog post", "Announce the release at the blog.")).build()
    );
}
 
开发者ID:SpineEventEngine,项目名称:examples-java,代码行数:18,代码来源:SampleData.java


示例3: main

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, IOException {
    final EventPublisher publisher = new EventPublisher(PORT);

    try {
        for (GeneratedMessageV3 message : events) {
            // Simulate event id generation.
            final EventId eventId = Events.generateId();

            // Simulate `EventContext` creation. Normally version, and aggregate ID will be set by
            // the framework code when new instance of `EventContext` is generated.
            final EventContext context = EventContext.newBuilder()
                                                     .setEventId(eventId)
                                                     .build();

            final Event record = Events.createEvent(message, context);
            publisher.publish(record);
        }
    } finally {
        publisher.awaitTermination();
    }
}
 
开发者ID:SpineEventEngine,项目名称:examples-java,代码行数:22,代码来源:EventPublisher.java


示例4: sendMessage

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public DiozeroProtos.Response sendMessage(String topic, String correlationId, GeneratedMessageV3 message)
		throws MqttException {
	Condition condition = lock.newCondition();
	conditions.put(correlationId, condition);

	lock.lock();
	try {
		mqttClient.publish(topic, message.toByteArray(), MqttProviderConstants.DEFAULT_QOS,
				MqttProviderConstants.DEFAULT_RETAINED);

		Logger.info("Waiting for response...");
		condition.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
	} catch (InterruptedException e) {
		Logger.error(e, "Interrupted: {}", e);
	} finally {
		lock.unlock();
	}

	DiozeroProtos.Response response = responses.remove(correlationId);
	if (response == null) {
		throw new RuntimeIOException("Cannot find response message for " + correlationId);
	}

	return response;
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:26,代码来源:MqttTestClient.java


示例5: getGeneratedProtoClasses

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public List<String> getGeneratedProtoClasses(String serviceName) {
    FastClasspathScanner cpScanner = new FastClasspathScanner();
    ScanResult scanResult = cpScanner.scan();
    List<String> oldProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessage.class);
    List<String> newProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessageV3.class);
    List<String> retval = Stream.concat(oldProtobuf.stream(),
            newProtobuf.stream()).collect(Collectors.toList());
    String[] packageTokens = serviceName.split("\\.");
    return retval.stream().filter(s -> protoFilePackageMatches(s, packageTokens)).collect(Collectors.toList());
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:11,代码来源:RpcMethodScanner.java


示例6: getProtobufClassFromPojoAnno

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public static final Class<? extends GeneratedMessageV3> getProtobufClassFromPojoAnno(
    Class<?> clazz) {
  final ProtobufEntity annotation = getProtobufEntity(clazz);
  final Class<? extends GeneratedMessageV3> gpbClazz =
      (Class<? extends GeneratedMessageV3>) annotation.value();
  if (gpbClazz == null) {
    return null;
  }
  return gpbClazz;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:11,代码来源:ProtobufSerializerUtils.java


示例7: write

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public static void write(GeneratedMessageV3 msg, OutputStream out, byte[] hlen)
        throws IOException {
    final int tam = msg.getSerializedSize();
    hlen[0] = (byte)((tam & 0xff00) >> 8);
    hlen[1] = (byte)(tam & 0xff);
    out.write(hlen);
    msg.writeTo(out);
    out.flush();
}
 
开发者ID:chochos,项目名称:protobuf-demo,代码行数:10,代码来源:Utils.java


示例8: sendMessage

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
@Override
protected void sendMessage(String url, GeneratedMessageV3 message) throws IOException {
	DiozeroProtos.MessageWrapper message_wrapper = DiozeroProtos.MessageWrapper.newBuilder()
			.setType(message.getClass().getSimpleName()).setMessage(ByteString.copyFrom(message.toByteArray()))
			.build();

	session.getRemote().sendBytes(ByteBuffer.wrap(message_wrapper.toByteArray()));
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:9,代码来源:ProtobufWebSocketProtocolHandler.java


示例9: InvalidEntityStateException

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
private InvalidEntityStateException(String messageText, Message entityState, Error error) {
    super(messageText);
    this.entityState = entityState instanceof GeneratedMessageV3
                       ? (GeneratedMessageV3) entityState
                       : AnyPacker.pack(entityState);
    this.error = error;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:8,代码来源:InvalidEntityStateException.java


示例10: UnsupportedExternalMessageException

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public UnsupportedExternalMessageException(Message externalMessage) {
    super();
    if (externalMessage instanceof GeneratedMessageV3) {
        this.externalMessage = (GeneratedMessageV3) externalMessage;
    } else {
        // This is strange. However, let's preserve the value by packing it.
        this.externalMessage = AnyPacker.pack(externalMessage);
    }
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:10,代码来源:UnsupportedExternalMessageException.java


示例11: HandlerMethodFailedException

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
/**
 * Creates new instance.
 *
 * @param target             the object which method failed
 * @param dispatchedMessage  the message passed to the method which failed
 * @param messageContext     the context of the message
 * @param cause              the exception thrown by the method
 */
public HandlerMethodFailedException(Object  target,
                                    Message dispatchedMessage,
                                    Message messageContext,
                                    Exception cause) {
    super(checkNotNull(cause));
    this.target = target.toString();
    /**
       All messages we handle are generated, so the cast below is safe.
       We do not want to accept `GeneratedMessageV3` to avoid the cast in the calling code
       which uses `Message` as {@linkplain GeneratedMessageV3 advised} by Protobuf authors.
     */
    this.dispatchedMessage = (GeneratedMessageV3) checkNotNull(dispatchedMessage);
    this.messageContext = (GeneratedMessageV3) checkNotNull(messageContext);
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:23,代码来源:HandlerMethodFailedException.java


示例12: EventException

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
/**
 * Creates a new instance.
 *
 * @param messageText  an error message text
 * @param eventMessage a related event message
 * @param error        an error occurred
 */
protected EventException(String messageText, Message eventMessage, Error error) {
    super(messageText);
    if (eventMessage instanceof GeneratedMessageV3) {
        this.eventMessage = (GeneratedMessageV3) eventMessage;
    } else {
        // In an unlikely case on encountering a message, which is not `GeneratedMessageV3`,
        // wrap it into `Any`.
        this.eventMessage = AnyPacker.pack(eventMessage);
    }
    this.error = error;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:19,代码来源:EventException.java


示例13: find_closest_superclass_column_type

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
@Test
public void find_closest_superclass_column_type() {
    final ColumnTypeRegistry<?> registry =
            ColumnTypeRegistry.newBuilder()
                              .put(GeneratedMessageV3.class, new GeneratedMessageType())
                              .put(AbstractMessage.class, new AbstractMessageType())
                              .build();
    final EntityColumn column = mockProperty(Any.class);
    final ColumnType type = registry.get(column);
    assertNotNull(type);
    assertThat(type, instanceOf(GeneratedMessageType.class));
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:13,代码来源:ColumnTypeRegistryShould.java


示例14: convertToProtoMessage

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
@Override
public byte[] convertToProtoMessage(Event<?, ?> event) {

    LinkEvent linkEvent = (LinkEvent) event;

    if (!linkEventTypeSupported(linkEvent)) {
        log.error("Unsupported Onos Event {}. There is no matching "
                          + "proto Event type", linkEvent.type().toString());
        return null;
    }

    return ((GeneratedMessageV3) buildDeviceProtoMessage(linkEvent)).toByteArray();
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:14,代码来源:LinkEventConverter.java


示例15: convertToProtoMessage

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
@Override
public byte[] convertToProtoMessage(Event<?, ?> event) {

    DeviceEvent deviceEvent = (DeviceEvent) event;

    if (!deviceEventTypeSupported(deviceEvent)) {
        log.error("Unsupported Onos Device Event {}. There is no matching"
                          + "proto Device Event type", deviceEvent.type().toString());
        return null;
    }

    return ((GeneratedMessageV3) buildDeviceProtoMessage(deviceEvent)).toByteArray();
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:14,代码来源:DeviceEventConverter.java


示例16: toProtobuf

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
/**
 * @see com.quancheng.saluki.serializer.IProtobufSerializer#toProtobuf(java.lang.Object)
 */
@Override
@SuppressWarnings({"unchecked", "rawtypes", "unused"})
public Message toProtobuf(Object pojo) throws ProtobufException {
  try {
    final Class<?> fromClazz = (Class<?>) pojo.getClass();
    final Class<? extends GeneratedMessageV3> protoClazz =
        ProtobufSerializerUtils.getProtobufClassFromPojoAnno(fromClazz);
    if (protoClazz == null) {
      throw new ProtobufAnnotationException(
          "Doesn't seem like " + fromClazz + " is ProtobufEntity");
    }
    final Map<Field, ProtobufAttribute> protoBufFields =
        ProtobufSerializerUtils.getAllProtbufFields(fromClazz);
    if (protoBufFields.isEmpty()) {
      return null;
    }
    final Method newBuilderMethod = protoClazz.getMethod("newBuilder");
    final Builder protoObjBuilder = (Builder) newBuilderMethod.invoke(null);
    for (Entry<Field, ProtobufAttribute> entry : protoBufFields.entrySet()) {
      final Field field = entry.getKey();
      final ProtobufAttribute gpbAnnotation = entry.getValue();
      final String fieldName = field.getName();
      // 1. Determine validity of value
      Object value = Pojo2ProtobufHelp.getPojoFieldValue(pojo, gpbAnnotation, field);
      // If value is null and it is not required, skip, as the default for Protobuf values is null
      if (value == null) {
        continue;
      }
      // 2. Call recursively if this is a ProtobufEntity
      value = Pojo2ProtobufHelp.serializeToProtobufEntity(value);
      // 3. Special recursively if this is a ProtobufEntity
      if (value instanceof Collection) {
        value = Pojo2ProtobufHelp.convertCollectionToProtobufs((Collection<Object>) value);
        if (((Collection) value).isEmpty()) {
          continue;
        }
      }
      if (value instanceof Map) {
        value = Pojo2ProtobufHelp.convertMapToProtobufs((Map) value);
        if (((Map) value).isEmpty()) {
          continue;
        }
      }
      String setter = ProtobufSerializerUtils.getProtobufSetter(gpbAnnotation, field, value);
      if (value instanceof Enum) {
        value = JReflectionUtils.runMethod(value, "getNumber");
        setter = setter + "Value";
      }
      Pojo2ProtobufHelp.setProtobufFieldValue(gpbAnnotation, protoObjBuilder, setter, value);
    }
    return protoObjBuilder.build();
  } catch (Exception e) {
    throw new ProtobufException(
        "Could not generate Protobuf object for " + pojo.getClass() + ": " + e, e);
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:60,代码来源:ProtobufSerializer.java


示例17: sendMessage

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
@Override
protected void sendMessage(String topic, GeneratedMessageV3 message) throws MqttException {
	mqttClient.publish(topic, message.toByteArray(), MqttProviderConstants.DEFAULT_QOS,
			MqttProviderConstants.DEFAULT_RETAINED);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:6,代码来源:ProtobufMqttProtocolHandler.java


示例18: CassandraMutationError

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
public CassandraMutationError(GeneratedMessageV3 request, Throwable throwable) {
    this.request = request;
    this.throwable = throwable;
}
 
开发者ID:doanduyhai,项目名称:killrvideo-java,代码行数:5,代码来源:CassandraMutationError.java


示例19: checkClass

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
private static void checkClass(Class<? extends Message> clazz) {
    checkNotNull(clazz);
    // Support only generated protobuf messages
    checkArgument(GeneratedMessageV3.class.isAssignableFrom(clazz),
                  "Only generated protobuf messages are allowed.");
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:7,代码来源:Sample.java


示例20: convertColumnValue

import com.google.protobuf.GeneratedMessageV3; //导入依赖的package包/类
@Override
public String convertColumnValue(GeneratedMessageV3 fieldValue) {
    return fieldValue.toString();
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:5,代码来源:ColumnTypeRegistryShould.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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