github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/sstable/unsafe.go (about)

     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 "unsafe"
     8  
     9  func getBytes(ptr unsafe.Pointer, length int) []byte {
    10  	return (*[1 << 30]byte)(ptr)[:length:length]
    11  }
    12  
    13  func decodeVarint(ptr unsafe.Pointer) (uint32, unsafe.Pointer) {
    14  	src := (*[5]uint8)(ptr)
    15  	if a := (*src)[0]; a < 128 {
    16  		return uint32(a),
    17  			unsafe.Pointer(uintptr(ptr) + 1)
    18  	} else if a, b := a&0x7f, (*src)[1]; b < 128 {
    19  		return uint32(b)<<7 | uint32(a),
    20  			unsafe.Pointer(uintptr(ptr) + 2)
    21  	} else if b, c := b&0x7f, (*src)[2]; c < 128 {
    22  		return uint32(c)<<14 | uint32(b)<<7 | uint32(a),
    23  			unsafe.Pointer(uintptr(ptr) + 3)
    24  	} else if c, d := c&0x7f, (*src)[3]; d < 128 {
    25  		return uint32(d)<<21 | uint32(c)<<14 | uint32(b)<<7 | uint32(a),
    26  			unsafe.Pointer(uintptr(ptr) + 4)
    27  	} else {
    28  		d, e := d&0x7f, (*src)[4]
    29  		return uint32(e)<<28 | uint32(d)<<21 | uint32(c)<<14 | uint32(b)<<7 | uint32(a),
    30  			unsafe.Pointer(uintptr(ptr) + 5)
    31  	}
    32  }