
io.datakernel.csp.binary.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datakernel-csp Show documentation
Show all versions of datakernel-csp Show documentation
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