cubefs
1// Copyright 2018 Klaus Post. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4// Based on work Copyright (c) 2013, Yann Collet, released under BSD License.
5
6package fse7
8// byteReader provides a byte reader that reads
9// little endian values from a byte stream.
10// The input stream is manually advanced.
11// The reader performs no bounds checks.
12type byteReader struct {13b []byte14off int15}
16
17// init will initialize the reader and set the input.
18func (b *byteReader) init(in []byte) {19b.b = in20b.off = 021}
22
23// advance the stream b n bytes.
24func (b *byteReader) advance(n uint) {25b.off += int(n)26}
27
28// Uint32 returns a little endian uint32 starting at current offset.
29func (b byteReader) Uint32() uint32 {30b2 := b.b[b.off:]31b2 = b2[:4]32v3 := uint32(b2[3])33v2 := uint32(b2[2])34v1 := uint32(b2[1])35v0 := uint32(b2[0])36return v0 | (v1 << 8) | (v2 << 16) | (v3 << 24)37}
38
39// unread returns the unread portion of the input.
40func (b byteReader) unread() []byte {41return b.b[b.off:]42}
43
44// remain will return the number of bytes remaining.
45func (b byteReader) remain() int {46return len(b.b) - b.off47}
48