@Override
    protected T readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException {
        final String predicateName = context.readValue(buffer, String.class, false);
        final int length = context.readValue(buffer, Integer.class, false);
        final Object[] args = new Object[length];
        final Class<?>[] argumentClasses = new Class[length];
        for (int i = 0; i < length; i++) {
            args[i] = context.read(buffer);
            argumentClasses[i] = null == args[i] ? Object.class : args[i].getClass();
        }
                    
        if ("and".equals(predicateName))
            return (T) ((P) args[0]).and((P) args[1]);
        else if ("or".equals(predicateName))
            return (T) ((P) args[0]).or((P) args[1]);
        else if ("not".equals(predicateName))
            return (T) P.not((P) args[0]);

        final CheckedFunction<Object[], T> f = getMethod(predicateName, argumentClasses);

        try {
            return f.apply(args);
        } catch (Exception ex) {
            throw new IOException(String.format("Can't deserialize value into the predicate: '%s'", predicateName), ex);
        }
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java