public T decode(DataInput dataIn) throws IOException { return (T)factory.parseUnframed((InputStream) dataIn).freeze(); }
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; }
private void encodeProtobuf(Class<?> type, Object arg, DataByteArrayOutputStream target) throws IOException { if( !PBMessage.class.isAssignableFrom(type) ) { throw new IllegalArgumentException("Invalid "+name()+" serialization method: method argument not a "+PBMessage.class.getName()); } PBMessage msg = (PBMessage) arg; if( msg==null ) { return; } msg.freeze().writeUnframed(target); }
private void encodeProtobuf(Class<?> type, Object arg, DataByteArrayOutputStream target) throws IOException { if( !PBMessage.class.isAssignableFrom(type) ) { throw new IllegalArgumentException("Invalid "+name()+" serialization method: method argument not a "+PBMessage.class.getName()); } PBMessage msg = (PBMessage) arg; if( msg==null ) { return; } msg.freeze().writeUnframed(target); }