NegativeIntegerEncoder.java
package co.nstant.in.cbor.encoder;
import java.io.OutputStream;
import java.math.BigInteger;
import co.nstant.in.cbor.CborEncoder;
import co.nstant.in.cbor.CborException;
import co.nstant.in.cbor.model.MajorType;
import co.nstant.in.cbor.model.NegativeInteger;
public class NegativeIntegerEncoder extends AbstractEncoder<NegativeInteger> {
private static final BigInteger MINUS_ONE = BigInteger.valueOf(-1);
public NegativeIntegerEncoder(CborEncoder encoder, OutputStream outputStream) {
super(encoder, outputStream);
}
@Override
public void encode(NegativeInteger dataItem) throws CborException {
encodeTypeAndLength(MajorType.NEGATIVE_INTEGER, MINUS_ONE.subtract(dataItem.getValue()).abs());
}
}