use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class Events method getMessage.
/**
* Extracts the event message from the passed event.
*
* @param event an event to get message from
*/
public static <M extends Message> M getMessage(Event event) {
checkNotNull(event);
final Any any = event.getMessage();
final M result = unpack(any);
return result;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class Failures method createFailure.
/**
* Creates a new {@code Failure} instance.
*
* @param messageOrAny the failure message or {@code Any} containing the message
* @param command the {@code Command}, which triggered the failure.
* @return created failure instance
*/
public static Failure createFailure(Message messageOrAny, Command command) {
checkNotNull(messageOrAny);
checkNotNull(command);
final Any packedFailureMessage = toAny(messageOrAny);
final FailureContext context = FailureContext.newBuilder().setCommand(command).build();
final Failure result = Failure.newBuilder().setMessage(packedFailureMessage).setContext(context).build();
return result;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class IntegerFieldValidatorShould method wrap_to_any.
@Test
public void wrap_to_any() {
final Any any = validator.wrap(VALUE);
final Int32Value msg = AnyPacker.unpack(any);
assertEquals(VALUE, (Integer) msg.getValue());
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class LongFieldValidatorShould method wrap_to_any.
@Test
public void wrap_to_any() {
final Any any = validator.wrap(VALUE);
final Int64Value msg = AnyPacker.unpack(any);
assertEquals(VALUE, (Long) msg.getValue());
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class PackingIterator method next.
/**
* Takes the message from the source iterator, wraps it into {@code Any}
* and returns.
*
* <p>If the source iterator returns {@code null} message, the default instance
* of {@code Any} will be returned.
*
* @return the packed message or default {@code Any}
*/
@Override
public Any next() {
final Message next = source.next();
final Any result = next != null ? AnyPacker.pack(next) : Any.getDefaultInstance();
return result;
}
Aggregations