当前位置: 首页>>代码示例>>Java>>正文


Java GeneratedMessageV3类代码示例

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


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


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