jberragan commented on code in PR #294: URL: https://github.com/apache/cassandra-sidecar/pull/294#discussion_r2636891690
########## server/src/main/java/org/apache/cassandra/sidecar/codecs/BigIntegerCodec.java: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.codecs; + +import java.math.BigInteger; + +import org.apache.commons.lang3.mutable.MutableInt; + +import io.vertx.core.buffer.Buffer; +import io.vertx.core.eventbus.MessageCodec; + +/** + * Message codec for encoding and decoding BigInteger values over the Vert.x event bus. + */ +public class BigIntegerCodec implements MessageCodec<BigInteger, BigInteger> +{ + public static final BigIntegerCodec INSTANCE = new BigIntegerCodec(); + + /** + * Encodes a BigInteger to the wire buffer. + */ + public void encodeToWire(Buffer buf, BigInteger bigInteger) + { + CommonCodecs.BYTE_ARRAY.encodeToWire(buf, bigInteger.toByteArray()); + } + + /** + * Decodes a BigInteger from the wire buffer. + */ + public BigInteger decodeFromWire(MutableInt pos, Buffer buf) + { + byte[] ar = CommonCodecs.BYTE_ARRAY.decodeFromWire(pos.intValue(), buf); + pos.add(4 + ar.length); + return new BigInteger(ar); + } + + /** + * Decodes a BigInteger from the wire buffer at the specified position. + */ + public BigInteger decodeFromWire(int pos, Buffer buf) + { + return decodeFromWire(new MutableInt(pos), buf); Review Comment: I think the `MutableInt` is only required if we need to track the change in position in a wrapper serializer, this would be marginally faster as: ```suggestion return new BigInteger(CommonCodecs.BYTE_ARRAY.decodeFromWire(pos, buf)); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

