![JAR search and dependency download from the Maven repository](/logo.png)
org.infinispan.server.resp.serialization.BigNumberSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infinispan-server-resp Show documentation
Show all versions of infinispan-server-resp Show documentation
Infinispan Resp Protocol Server
package org.infinispan.server.resp.serialization;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import org.infinispan.server.resp.ByteBufPool;
/**
* Represent signed integer values outside the 64-bit interval.
*
*
* Similar to {@link PrimitiveSerializer.IntegerSerializer}, but the prefix is the left parenthesis.
*
*
* @since 15.0
* @author José Bolina
*/
final class BigNumberSerializer implements ResponseSerializer {
static final BigNumberSerializer INSTANCE = new BigNumberSerializer();
@Override
public void accept(BigInteger bigInteger, ByteBufPool alloc) {
// FIXME: Find a way to write without string allocation.
String value = bigInteger.toString(10);
int size = 1 + value.length() + RespConstants.CRLF.length;
// RESP: ([+|-]\r\n
alloc.acquire(size).writeByte(RespConstants.BIG_NUMBER)
.writeBytes(value.getBytes(StandardCharsets.US_ASCII))
.writeBytes(RespConstants.CRLF);
}
@Override
public boolean test(Object object) {
// Handle only non-fractional large values.
return object instanceof BigInteger;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy