mirror of
https://github.com/LBRYFoundation/lbry-database-java.git
synced 2025-08-23 09:27:22 +00:00
55 lines
1.7 KiB
Java
55 lines
1.7 KiB
Java
package com.lbry.database.rows;
|
|
|
|
import com.lbry.database.Prefix;
|
|
import com.lbry.database.PrefixDB;
|
|
import com.lbry.database.keys.TxCountKey;
|
|
import com.lbry.database.revert.RevertibleOperationStack;
|
|
import com.lbry.database.values.TxCountValue;
|
|
import org.rocksdb.ColumnFamilyHandle;
|
|
import org.rocksdb.RocksDB;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.util.List;
|
|
|
|
public class TxCountPrefixRow extends PrefixRow<TxCountKey, TxCountValue>{
|
|
|
|
public TxCountPrefixRow(RocksDB database, RevertibleOperationStack operationStack, List<ColumnFamilyHandle> columnFamilyHandleList){
|
|
super(database,operationStack,columnFamilyHandleList);
|
|
}
|
|
|
|
@Override
|
|
public Prefix prefix(){
|
|
return Prefix.TX_COUNT;
|
|
}
|
|
|
|
@Override
|
|
public byte[] packKey(TxCountKey key) {
|
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
|
}
|
|
|
|
@Override
|
|
public TxCountKey unpackKey(byte[] key) {
|
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
|
if(bb.get()!=this.prefix().getValue()){
|
|
return null;
|
|
}
|
|
TxCountKey keyObj = new TxCountKey();
|
|
keyObj.height = bb.getInt();
|
|
return keyObj;
|
|
}
|
|
|
|
@Override
|
|
public byte[] packValue(TxCountValue value) {
|
|
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(value.tx_count).array();
|
|
}
|
|
|
|
@Override
|
|
public TxCountValue unpackValue(byte[] value) {
|
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
|
TxCountValue valueObj = new TxCountValue();
|
|
valueObj.tx_count = bb.getInt();
|
|
return valueObj;
|
|
}
|
|
|
|
}
|