Source File
slicereader.go
Belonging Package
internal/coverage/slicereader
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package slicereader
import (
)
// This file contains the helper "SliceReader", a utility for
// reading values from a byte slice that may or may not be backed
// by a read-only mmap'd region.
type Reader struct {
b []byte
readonly bool
off int64
}
func ( []byte, bool) *Reader {
:= Reader{
b: ,
readonly: ,
}
return &
}
func ( *Reader) ( []byte) (int, error) {
:= len()
:= .b[.off:]
if len() < {
= len()
}
copy(, )
.off += int64()
return , nil
}
func ( *Reader) ( int64) {
.off =
}
func ( *Reader) () int64 {
return .off
}
func ( *Reader) () uint8 {
:= uint8(.b[int(.off)])
.off += 1
return
}
func ( *Reader) () uint32 {
:= int(.off) + 4
:= binary.LittleEndian.Uint32(.b[int(.off)::])
.off += 4
return
}
func ( *Reader) () uint64 {
:= int(.off) + 8
:= binary.LittleEndian.Uint64(.b[int(.off)::])
.off += 8
return
}
func ( *Reader) () ( uint64) {
var uint
for {
:= .b[.off]
.off++
|= (uint64(&0x7F) << )
if &0x80 == 0 {
break
}
+= 7
}
return
}
func ( *Reader) ( int64) string {
:= .b[.off : .off+]
.off +=
if .readonly {
return toString() // backed by RO memory, ok to make unsafe string
}
return string()
}
func toString( []byte) string {
if len() == 0 {
return ""
}
return unsafe.String(&[0], len())
}
![]() |
The pages are generated with Golds v0.6.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |