Line data Source code
1 : // Copyright 2018 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package sstable 6 : 7 : import ( 8 : "unsafe" 9 : 10 : "github.com/cockroachdb/pebble/internal/manual" 11 : ) 12 : 13 1 : func getBytes(ptr unsafe.Pointer, length int) []byte { 14 1 : return (*[manual.MaxArrayLen]byte)(ptr)[:length:length] 15 1 : } 16 : 17 1 : func decodeVarint(ptr unsafe.Pointer) (uint32, unsafe.Pointer) { 18 1 : if a := *((*uint8)(ptr)); a < 128 { 19 1 : return uint32(a), 20 1 : unsafe.Pointer(uintptr(ptr) + 1) 21 1 : } else if a, b := a&0x7f, *((*uint8)(unsafe.Pointer(uintptr(ptr) + 1))); b < 128 { 22 1 : return uint32(b)<<7 | uint32(a), 23 1 : unsafe.Pointer(uintptr(ptr) + 2) 24 1 : } else if b, c := b&0x7f, *((*uint8)(unsafe.Pointer(uintptr(ptr) + 2))); c < 128 { 25 1 : return uint32(c)<<14 | uint32(b)<<7 | uint32(a), 26 1 : unsafe.Pointer(uintptr(ptr) + 3) 27 1 : } else if c, d := c&0x7f, *((*uint8)(unsafe.Pointer(uintptr(ptr) + 3))); d < 128 { 28 1 : return uint32(d)<<21 | uint32(c)<<14 | uint32(b)<<7 | uint32(a), 29 1 : unsafe.Pointer(uintptr(ptr) + 4) 30 1 : } else { 31 1 : d, e := d&0x7f, *((*uint8)(unsafe.Pointer(uintptr(ptr) + 4))) 32 1 : return uint32(e)<<28 | uint32(d)<<21 | uint32(c)<<14 | uint32(b)<<7 | uint32(a), 33 1 : unsafe.Pointer(uintptr(ptr) + 5) 34 1 : } 35 : }