binary

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package binary implements sintax-sugar functions on top of the standard library binary package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBinary

func IsBinary(r io.Reader) (bool, error)

IsBinary detects if data is a binary value based on: http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198

func Read

func Read(r io.Reader, data ...any) error

Read reads structured binary data from r into data. Bytes are read and decoded in BigEndian order https://golang.org/pkg/encoding/binary/#Read

func ReadHash

func ReadHash(r io.Reader) (plumbing.Hash, error)

ReadHash reads a plumbing.Hash from r

func ReadUint16

func ReadUint16(r io.Reader) (uint16, error)

ReadUint16 reads 2 bytes and returns them as a BigEndian uint16

func ReadUint32

func ReadUint32(r io.Reader) (uint32, error)

ReadUint32 reads 4 bytes and returns them as a BigEndian uint32

func ReadUint64

func ReadUint64(r io.Reader) (uint64, error)

ReadUint64 reads 8 bytes and returns them as a BigEndian uint32

func ReadUntil

func ReadUntil(r io.Reader, delim byte) ([]byte, error)

ReadUntil reads from r untin delim is found

func ReadUntilFromBufioReader

func ReadUntilFromBufioReader(r *bufio.Reader, delim byte) ([]byte, error)

ReadUntilFromBufioReader is like bufio.ReadBytes but drops the delimiter from the result.

func ReadVariableWidthInt

func ReadVariableWidthInt(r io.Reader) (int64, error)

ReadVariableWidthInt reads and returns an int in Git VLQ special format:

Ordinary VLQ has some redundancies, example: the number 358 can be encoded as the 2-octet VLQ 0x8166 or the 3-octet VLQ 0x808166 or the 4-octet VLQ 0x80808166 and so forth.

To avoid these redundancies, the VLQ format used in Git removes this prepending redundancy and extends the representable range of shorter VLQs by adding an offset to VLQs of 2 or more octets in such a way that the lowest possible value for such an (N+1)-octet VLQ becomes exactly one more than the maximum possible value for an N-octet VLQ. In particular, since a 1-octet VLQ can store a maximum value of 127, the minimum 2-octet VLQ (0x8000) is assigned the value 128 instead of 0. Conversely, the maximum value of such a 2-octet VLQ (0xff7f) is 16511 instead of just 16383. Similarly, the minimum 3-octet VLQ (0x808000) has a value of 16512 instead of zero, which means that the maximum 3-octet VLQ (0xffff7f) is 2113663 instead of just 2097151. And so forth.

This is how the offset is saved in C:

dheader[pos] = ofs & 127;
while (ofs >>= 7)
    dheader[--pos] = 128 | (--ofs & 127);

func Swap16

func Swap16(v uint16) []byte

func Swap32

func Swap32(v uint32) []byte

func Swap64

func Swap64(v uint64) []byte

func Write

func Write(w io.Writer, data ...any) error

Write writes the binary representation of data into w, using BigEndian order https://golang.org/pkg/encoding/binary/#Write

func WriteUint16

func WriteUint16(w io.Writer, value uint16) error

WriteUint16 writes the binary representation of a uint16 into w, in BigEndian order

func WriteUint32

func WriteUint32(w io.Writer, value uint32) error

WriteUint32 writes the binary representation of a uint32 into w, in BigEndian order

func WriteUint64

func WriteUint64(w io.Writer, value uint64) error

WriteUint64 writes the binary representation of a uint64 into w, in BigEndian order

func WriteVariableWidthInt

func WriteVariableWidthInt(w io.Writer, n int64) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL