Initial commit after restructure

This commit is contained in:
Daniel 2018-08-13 14:05:58 +02:00
commit 96ec15b39b
70 changed files with 6945 additions and 0 deletions

22
formats/varint/helpers.go Normal file
View file

@ -0,0 +1,22 @@
package varint
import "errors"
// PrependLength prepends the varint encoded length of the byte slice to itself.
func PrependLength(data []byte) []byte {
return append(Pack64(uint64(len(data))), data...)
}
// GetNextBlock extract the integer from the beginning of the given byte slice and returns the remaining bytes, the extracted integer, and whether there was an error.
func GetNextBlock(data []byte) ([]byte, int, error) {
l, n, err := Unpack64(data)
if err != nil {
return nil, 0, err
}
length := int(l)
totalLength := length + n
if totalLength > len(data) {
return nil, 0, errors.New("varint: not enough data for given block length")
}
return data[n:totalLength], totalLength, nil
}