private Object decodeProtobuf(Class<?> type, DataByteArrayInputStream source) throws IllegalAccessException, NoSuchFieldException, IOException { if( !PBMessage.class.isAssignableFrom(type) ) { throw new IllegalArgumentException("Invalid "+name()+" serialization method: method argument not a "+PBMessage.class.getName()); } // Get the factory instance... PBMessageFactory factory = (PBMessageFactory) type.getEnclosingClass().getField("FACTORY").get(null); PBMessage msg = factory.parseUnframed(source); String name = type.getName(); Object rc; if( name.endsWith("$Getter") || name.endsWith("$Buffer") ) { // Interface is ok we us giving them a read only impl. rc = msg; } else { // They want a read/write impl. rc = msg.copy(); } return rc; }
private Object decodeProtobuf(Class<?> type, DataByteArrayInputStream source) throws IllegalAccessException, NoSuchFieldException, IOException { if( !PBMessage.class.isAssignableFrom(type) ) { throw new IllegalArgumentException("Invalid "+name()+" serialization method: method argument not a "+PBMessage.class.getName()); } // Get the factory instance... PBMessageFactory factory = (PBMessageFactory) type.getEnclosingClass().getField("FACTORY").get(null); PBMessage msg = factory.parseUnframed(source); String name = type.getName(); Object rc; if( name.endsWith("$Getter") || name.endsWith("$Buffer") ) { // Interface is ok we us giving them a read only impl. rc = msg; } else { // They want a read/write impl. rc = msg.copy(); } return rc; }