All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datakernel.csp.binary.Utils Maven / Gradle / Ivy

Go to download

Communicating sequential process via channels, similar to Golang's channels. A channel could be imagine as a pipe which connects some processes.

The newest version!
package io.datakernel.csp.binary;

import io.datakernel.bytebuf.ByteBuf;
import io.datakernel.common.parse.ParseException;

class Utils {

	static ByteBufsParser parseUntilTerminatorByte(byte terminator, int maxSize) {
		return bufs -> {
			for (int i = 0; i < Math.min(bufs.remainingBytes(), maxSize); i++) {
				if (bufs.peekByte(i) == terminator) {
					ByteBuf buf = bufs.takeExactSize(i);
					bufs.skip(1);
					return buf;
				}
			}
			if (bufs.remainingBytes() >= maxSize) {
				throw new ParseException(ByteBufsParser.class, "No terminator byte is found in " + maxSize + " bytes");
			}
			return null;
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy