public static SyncPDU fromBuffer(ByteBuffer buf) throws Exception {        
        SyncPeer from;
        SyncPeer to;
        byte[]   setID;
        byte     type;
        int      setsize;
        long     begin;
        long     end;
        long[]   recVector;
        
        int i         = buf.getInt();
        byte[] magic  = new byte[i]; 
        buf.get(magic, 0, i);     
        if (!Arrays.equals(MAGIC, magic)) {System.out.println("Magic failure"); return null;}
        if (version != buf.get()) {System.out.println("Wrong version"); return null;}        
        i             = buf.getInt();
        byte[] faddr  = new byte[i];
        buf.get(faddr, 0, i);
        InetAddress f = InetAddress.getByAddress(faddr);
        int fport     = buf.getInt();       
        from          = new SyncPeer(f, fport);
        i             = buf.getInt();
        byte[] taddr  = new byte[i];
        buf.get(taddr, 0, i);
        InetAddress t = InetAddress.getByAddress(taddr);
        int tport     = buf.getInt(); 
        to            = new SyncPeer(t, tport);
        i             = buf.getInt();
        setID         = new byte[i];
        buf.get(setID, 0, i);
        type          = buf.get();
        setsize       = buf.getInt();
        begin         = buf.getLong();
        end           = buf.getLong();
        i             = buf.getInt();        
        recVector     = new long[i];
        buf.asLongBuffer().get(recVector, 0, i);

        return new SyncPDU(from, to, setID, type, setsize, begin, end, recVector);
    }