1// Copyright (c) 2017 Couchbase, Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package vellum 16 17func deltaAddr(base, trans uint64) uint64 { 18 // transition dest of 0 is special case 19 if trans == 0 { 20 return 0 21 } 22 return base - trans 23} 24 25const packOutMask = 1<<4 - 1 26 27func encodePackSize(transSize, outSize int) byte { 28 var rv byte 29 rv = byte(transSize << 4) 30 rv |= byte(outSize) 31 return rv 32} 33 34func decodePackSize(pack byte) (transSize int, packSize int) { 35 transSize = int(pack >> 4) 36 packSize = int(pack & packOutMask) 37 return 38} 39 40const maxNumTrans = 1<<6 - 1 41 42func encodeNumTrans(n int) byte { 43 if n <= maxNumTrans { 44 return byte(n) 45 } 46 return 0 47} 48 49func readPackedUint(data []byte) (rv uint64) { 50 for i := range data { 51 shifted := uint64(data[i]) << uint(i*8) 52 rv |= shifted 53 } 54 return 55} 56