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

com.scalar.db.storage.dynamo.bytes.BooleanBytesEncoder Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

The newest version!
package com.scalar.db.storage.dynamo.bytes;

import static com.scalar.db.storage.dynamo.bytes.BytesUtils.mask;

import com.scalar.db.api.Scan.Ordering.Order;
import com.scalar.db.io.BooleanColumn;
import java.nio.ByteBuffer;
import javax.annotation.concurrent.ThreadSafe;

@ThreadSafe
public class BooleanBytesEncoder implements BytesEncoder {
  private static final byte FALSE = 0x00;
  private static final byte TRUE = 0x01;

  BooleanBytesEncoder() {}

  @Override
  public int encodedLength(BooleanColumn column, Order order) {
    return 1;
  }

  @Override
  public void encode(BooleanColumn column, Order order, ByteBuffer dst) {
    assert !column.hasNullValue();

    boolean b = column.getBooleanValue();
    dst.put(mask(b ? TRUE : FALSE, order));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy