<commit_before>package permoize;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerializingRequestPusherPullerFactory<P> implements PusherPullerFactory<byte[], P> {
	private Class<P> protocol;
	private P implementer;
	
	private SerializingRequestPusherPullerFactory(Class<P> protocol, P implementer) {
		this.protocol = protocol;
		this.implementer = implementer;
	}
	
	public static <P> SerializingRequestPusherPullerFactory<P> create(Class<P> protocol, P implementer) {
		return new SerializingRequestPusherPullerFactory<P>(protocol, implementer);
	}

	@Override
	public Puller<byte[]> createPuller(Memoizer memoizer) {
		ServiceProvider<byte[]> serviceProvider = new ReflectiveServiceProvider<P, byte[]>(
				implementer,
			(target, request) -> {
				try {
					ByteArrayInputStream bytesIn = new ByteArrayInputStream(request);
		            ObjectInputStream objectsIn = new ObjectInputStream(bytesIn);
		            
		            String methodName = objectsIn.readUTF();
					Class<?>[] parameterTypes = (Class<?>[])objectsIn.readObject();
					
					return target.getClass().getMethod(methodName, parameterTypes);
				} catch (Exception e1) {
					e1.printStackTrace();
					return null;
				}
			},
			request -> {
				try {
					ByteArrayInputStream bytesIn = new ByteArrayInputStream(request);
		            ObjectInputStream objectsIn = new ObjectInputStream(bytesIn);
		            Object[] arguments = (Object[])objectsIn.readObject();

					return arguments;
				} catch (Exception e1) {
					e1.printStackTrace();
					return null;
				}
			}
		);
		
		return new Puller<byte[]>(memoizer, serviceProvider);
	}

	@Override
	public P createPusher(Puller<byte[]> server) {
		Pusher<byte[]> client = server.newClient();
		return ReflectivePusher.create(protocol, client, (method, arguments) -> {
			try {
				ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
	            ObjectOutputStream objectsOut = new ObjectOutputStream(bytesOut);
	            
	            objectsOut.writeUTF(method.getName());
	            objectsOut.writeObject(method.getParameterTypes());
	            objectsOut.writeObject(arguments);
	            
	            return bytesOut.toByteArray();
			} catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
			
//			StringBuilder requestBuilder = new StringBuilder();
//			requestBuilder.append(method.getName());
//			for(Object arg: arguments) {
//				requestBuilder.append(";");
//				requestBuilder.append((String)arg);
//			}
//			return requestBuilder.toString();
		});
	}
}<commit_msg>Added Util class for converting invocations into byte[] based requests. Fixed issue in argument extraction where method name and parameter types weren't consumed; they are now.<commit_after>package permoize;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerializingRequestPusherPullerFactory<P> implements PusherPullerFactory<byte[], P> {
	public static class Util {
		public static byte[] invocationToRequest(String methodName, Class<?>[] parameterTypes, Object[] arguments) throws IOException {
			ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            ObjectOutputStream objectsOut = new ObjectOutputStream(bytesOut);
            
            objectsOut.writeUTF(methodName);
            objectsOut.writeObject(parameterTypes);
            objectsOut.writeObject(arguments);
            
            return bytesOut.toByteArray();
		}
	}
	
	private Class<P> protocol;
	private P implementer;
	
	private SerializingRequestPusherPullerFactory(Class<P> protocol, P implementer) {
		this.protocol = protocol;
		this.implementer = implementer;
	}
	
	public static <P> SerializingRequestPusherPullerFactory<P> create(Class<P> protocol, P implementer) {
		return new SerializingRequestPusherPullerFactory<P>(protocol, implementer);
	}

	@Override
	public Puller<byte[]> createPuller(Memoizer memoizer) {
		ServiceProvider<byte[]> serviceProvider = new ReflectiveServiceProvider<P, byte[]>(
				implementer,
			(target, request) -> {
				try {
					ByteArrayInputStream bytesIn = new ByteArrayInputStream(request);
		            ObjectInputStream objectsIn = new ObjectInputStream(bytesIn);
		            
		            String methodName = objectsIn.readUTF();
					Class<?>[] parameterTypes = (Class<?>[])objectsIn.readObject();
					
					return target.getClass().getMethod(methodName, parameterTypes);
				} catch (Exception e1) {
					e1.printStackTrace();
					return null;
				}
			},
			request -> {
				try {
					ByteArrayInputStream bytesIn = new ByteArrayInputStream(request);
		            ObjectInputStream objectsIn = new ObjectInputStream(bytesIn);
		            objectsIn.readUTF(); // Consume method name
					objectsIn.readObject(); // Consume parameter types
		            Object[] arguments = (Object[])objectsIn.readObject();

					return arguments;
				} catch (Exception e1) {
					e1.printStackTrace();
					return null;
				}
			}
		);
		
		return new Puller<byte[]>(memoizer, serviceProvider);
	}

	@Override
	public P createPusher(Puller<byte[]> server) {
		Pusher<byte[]> client = server.newClient();
		return ReflectivePusher.create(protocol, client, (method, arguments) -> {
			try {
				return Util.invocationToRequest(method.getName(), method.getParameterTypes(), arguments);
			} catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		});
	}
}
{'fraction_non_alphanumeric': 0.10656466820850383, 'fraction_numerical': 0.002134851449919943, 'mean_word_length': 3.6309719934102143, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692805', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1517, 'n_words': 342}