use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class EventFactory method createEvent.
/**
* Creates a new {@code Event} instance.
*
* @param id the ID of the event
* @param messageOrAny the event message or {@code Any} containing the message
* @param context the event context
* @return created event instance
*/
private static Event createEvent(EventId id, Message messageOrAny, EventContext context) {
checkNotNull(messageOrAny);
checkNotNull(context);
final Any packed = toAny(messageOrAny);
final Event result = Event.newBuilder().setId(id).setMessage(packed).setContext(context).build();
return result;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class Identifiers method idToAny.
/**
* Wraps the passed ID value into an instance of {@link Any}.
*
* <p>The passed value must be of one of the supported types listed below.
* The type of the value wrapped into the returned instance is defined by the type
* of the passed value:
* <ul>
* <li>For classes implementing {@link com.google.protobuf.Message Message} — the value
* of the message itself
* <li>For {@code String} — {@link com.google.protobuf.StringValue StringValue}
* <li>For {@code Long} — {@link com.google.protobuf.UInt64Value UInt64Value}
* <li>For {@code Integer} — {@link com.google.protobuf.UInt32Value UInt32Value}
* </ul>
*
* @param id the value to wrap
* @param <I> the type of the value
* @return instance of {@link Any} with the passed value
* @throws IllegalArgumentException if the passed value is not of the supported type
*/
public static <I> Any idToAny(I id) {
checkNotNull(id);
final Identifier<I> identifier = Identifier.from(id);
final Any anyId = identifier.pack();
return anyId;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class FailureThrowable method toFailure.
/**
* Converts this {@code FailureThrowable} into {@link Failure}.
*
* @param command the command which caused the failure
*/
@Internal
public Failure toFailure(Command command) {
final Any packedMessage = pack(failureMessage);
final FailureContext context = createContext(command);
final FailureId id = Failures.generateId(command.getId());
return Failure.newBuilder().setId(id).setMessage(packedMessage).setContext(context).build();
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class PackingIteratorShould method implement_next.
@Test
public void implement_next() throws Exception {
while (packer.hasNext()) {
final Any packed = packer.next();
assertNotNull(packed);
assertFalse(isDefault(unpack(packed)));
}
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class AnyPackerShould method return_Any_if_it_is_passed_to_pack.
@Test
public void return_Any_if_it_is_passed_to_pack() {
final Any any = Any.pack(googleMsg);
assertSame(any, AnyPacker.pack(any));
}
Aggregations