/**
 * Copyright (c) 2018-present, heineiuo.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import { Buffer } from "./Buffer" ; import { varint , assert } from "./DBHelper" ; import Slice from "./Slice" ; const kFixed64MaxValue = ( 1n << 56n ) - 1n ; export function encodeFixed64 ( value ) { const buf = Buffer . alloc ( 8 ) ; const bigIntValue = BigInt ( value ) ; buf . writeBigUInt64LE ( bigIntValue < kFixed64MaxValue ? bigIntValue : kFixed64MaxValue ) ; return buf ; } export function decodeFixed64 ( buf ) { return buf . readBigUInt64LE ( ) ; } export function encodeFixed32 ( value ) { const buf = Buffer . alloc ( 4 ) ; buf . writeUInt32LE ( value , 0 ) ; return buf ; } export function decodeFixed32 ( buf ) { assert ( buf . length >= 4 ) ; return buf . readUInt32LE ( 0 ) ; } export function getLengthPrefixedSlice ( key ) { const internalKeySize = varint . decode ( key . buffer ) ; const internalKeyBuffer = key . buffer . slice ( varint . decode . bytes , varint . decode . bytes + internalKeySize ) ; return new Slice ( internalKeyBuffer ) ; }