binary
packageThis package is not in the latest version of its module.
Details
Valid go.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package binary implements sintax-sugar functions on top of the standardlibrary binary package
Index¶
- func IsBinary(r io.Reader) (bool, error)
- func Read(r io.Reader, data ...interface{}) error
- func ReadHash(r io.Reader) (plumbing.Hash, error)
- func ReadUint16(r io.Reader) (uint16, error)
- func ReadUint32(r io.Reader) (uint32, error)
- func ReadUint64(r io.Reader) (uint64, error)
- func ReadUntil(r io.Reader, delim byte) ([]byte, error)
- func ReadVariableWidthInt(r io.Reader) (int64, error)
- func Write(w io.Writer, data ...interface{}) error
- func WriteUint16(w io.Writer, value uint16) error
- func WriteUint32(w io.Writer, value uint32) error
- func WriteUint64(w io.Writer, value uint64) error
- func WriteVariableWidthInt(w io.Writer, n int64) error
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcIsBinary¶
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
funcRead¶
Read reads structured binary data from r into data. Bytes are read anddecoded in BigEndian orderhttps://golang.org/pkg/encoding/binary/#Read
funcReadUint16¶
ReadUint16 reads 2 bytes and returns them as a BigEndian uint16
funcReadUint32¶
ReadUint32 reads 4 bytes and returns them as a BigEndian uint32
funcReadUint64¶
ReadUint64 reads 8 bytes and returns them as a BigEndian uint32
funcReadVariableWidthInt¶
ReadVariableWidthInt reads and returns an int in Git VLQ special format:
Ordinary VLQ has some redundancies, example: the number 358 can beencoded as the 2-octet VLQ 0x8166 or the 3-octet VLQ 0x808166 or the4-octet VLQ 0x80808166 and so forth.
To avoid these redundancies, the VLQ format used in Git removes thisprepending redundancy and extends the representable range of shorterVLQs by adding an offset to VLQs of 2 or more octets in such a waythat the lowest possible value for such an (N+1)-octet VLQ becomesexactly 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 of0. Conversely, the maximum value of such a 2-octet VLQ (0xff7f) is16511 instead of just 16383. Similarly, the minimum 3-octet VLQ(0x808000) has a value of 16512 instead of zero, which meansthat the maximum 3-octet VLQ (0xffff7f) is 2113663 instead ofjust 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);
funcWrite¶
Write writes the binary representation of data into w, using BigEndian orderhttps://golang.org/pkg/encoding/binary/#Write
funcWriteUint16¶
WriteUint16 writes the binary representation of a uint16 into w, in BigEndianorder
funcWriteUint32¶
WriteUint32 writes the binary representation of a uint32 into w, in BigEndianorder
funcWriteUint64¶
WriteUint64 writes the binary representation of a uint64 into w, in BigEndianorder
Types¶
This section is empty.