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(); }
@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()); }
private static MessageType marshallerType(Marshaller<?> marshaller) { return marshaller instanceof PrototypeMarshaller ? MessageType.PROTOBUF : MessageType.UNKNOWN; }