kbin

package
v1.11.5 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: BSD-3-Clause Imports: 6 Imported by: 9

Documentation

Overview

Package kbin contains Kafka primitive reading and writing functions.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotEnoughData = errors.New("response did not contain enough data to be valid")

ErrNotEnoughData is returned when a type could not fully decode from a slice because the slice did not have enough data.

Functions

func AppendArrayLen

func AppendArrayLen(dst []byte, l int) []byte

AppendArrayLen appends the length of an array as an int32 to dst.

func AppendBool

func AppendBool(dst []byte, v bool) []byte

AppendBool appends 1 for true or 0 for false to dst.

func AppendBytes

func AppendBytes(dst, b []byte) []byte

AppendBytes appends bytes to dst prefixed with its int32 length.

func AppendCompactArrayLen

func AppendCompactArrayLen(dst []byte, l int) []byte

AppendCompactArrayLen appends the length of an array as a uvarint to dst as the length + 1.

For KIP-482.

func AppendCompactBytes

func AppendCompactBytes(dst, b []byte) []byte

AppendCompactBytes appends bytes to dst prefixed with a its uvarint length starting at 1; 0 is reserved for null, which compact bytes are not (nullable compact ones are!). Thus, the length is the decoded uvarint - 1.

For KIP-482.

func AppendCompactNullableArrayLen

func AppendCompactNullableArrayLen(dst []byte, l int, isNil bool) []byte

AppendCompactNullableArrayLen appends the length of an array as a uvarint to dst as the length + 1; if isNil is true, this appends 0 as a uvarint.

For KIP-482.

func AppendCompactNullableBytes

func AppendCompactNullableBytes(dst, b []byte) []byte

AppendCompactNullableBytes appends a potentially nil slice to dst with its uvarint length starting at 1, with 0 indicating null. Thus, the length is the decoded uvarint - 1.

For KIP-482.

func AppendCompactNullableString

func AppendCompactNullableString(dst []byte, s *string) []byte

AppendCompactNullableString appends a potentially nil string to dst with its uvarint length starting at 1, with 0 indicating null. Thus, the length is the decoded uvarint - 1.

For KIP-482.

func AppendCompactString

func AppendCompactString(dst []byte, s string) []byte

AppendCompactString appends a string to dst prefixed with its uvarint length starting at 1; 0 is reserved for null, which compact strings are not (nullable compact ones are!). Thus, the length is the decoded uvarint - 1.

For KIP-482.

func AppendFloat64

func AppendFloat64(dst []byte, f float64) []byte

AppendFloat64 appends a big endian float64 to dst.

func AppendInt16

func AppendInt16(dst []byte, i int16) []byte

AppendInt16 appends a big endian int16 to dst.

func AppendInt32

func AppendInt32(dst []byte, i int32) []byte

AppendInt32 appends a big endian int32 to dst.

func AppendInt64

func AppendInt64(dst []byte, i int64) []byte

AppendInt64 appends a big endian int64 to dst.

func AppendInt8

func AppendInt8(dst []byte, i int8) []byte

AppendInt8 appends an int8 to dst.

func AppendNullableArrayLen

func AppendNullableArrayLen(dst []byte, l int, isNil bool) []byte

AppendNullableArrayLen appends the length of an array as an int32 to dst, or -1 if isNil is true.

func AppendNullableBytes

func AppendNullableBytes(dst, b []byte) []byte

AppendNullableBytes appends a potentially nil slice to dst prefixed with its int32 length or int32(-1) if nil.

func AppendNullableString

func AppendNullableString(dst []byte, s *string) []byte

AppendNullableString appends potentially nil string to dst prefixed with its int16 length or int16(-1) if nil.

func AppendString

func AppendString(dst []byte, s string) []byte

AppendString appends a string to dst prefixed with its int16 length.

func AppendUint16 added in v0.6.4

func AppendUint16(dst []byte, u uint16) []byte

AppendUint16 appends a big endian uint16 to dst.

func AppendUint32

func AppendUint32(dst []byte, u uint32) []byte

AppendUint32 appends a big endian uint32 to dst.

func AppendUuid added in v0.6.2

func AppendUuid(dst []byte, uuid [16]byte) []byte

AppendUuid appends the 16 uuid bytes to dst.

func AppendUvarint

func AppendUvarint(dst []byte, u uint32) []byte

AppendUvarint appends a uvarint encoded u to dst.

func AppendVarint

func AppendVarint(dst []byte, i int32) []byte

AppendVarint appends a varint encoded i to dst.

func AppendVarintBytes

func AppendVarintBytes(dst, b []byte) []byte

AppendVarintBytes appends a slice to dst prefixed with its length encoded as a varint.

func AppendVarintString

func AppendVarintString(dst []byte, s string) []byte

AppendVarintString appends a string to dst prefixed with its length encoded as a varint.

func AppendVarlong added in v1.11.4

func AppendVarlong(dst []byte, i int64) []byte

AppendVarlong appends a varint encoded i to dst.

func UnsafeString added in v1.6.0

func UnsafeString(slice []byte) string

UnsafeString returns the slice as a string using unsafe rule (6).

func Uvarint

func Uvarint(in []byte) (uint32, int)

Uvarint is a loop unrolled 32 bit uvarint decoder. The return semantics are the same as binary.Uvarint, with the added benefit that overflows in 5 byte encodings are handled rather than left to the user.

func UvarintLen

func UvarintLen(u uint32) int

UvarintLen returns how long u would be if it were uvarint encoded.

func Varint

func Varint(in []byte) (int32, int)

Varint is a loop unrolled 32 bit varint decoder. The return semantics are the same as binary.Varint, with the added benefit that overflows in 5 byte encodings are handled rather than left to the user.

func VarintLen

func VarintLen(i int32) int

VarintLen returns how long i would be if it were varint encoded.

func Varlong added in v1.11.4

func Varlong(in []byte) (int64, int)

Varlong is a loop unrolled 64 bit varint decoder. The return semantics are the same as binary.Varint, with the added benefit that overflows in 10 byte encodings are handled rather than left to the user.

func VarlongLen added in v1.11.5

func VarlongLen(i int64) int

VarlongLen returns how long i would be if it were varlong encoded.

Types

type Reader

type Reader struct {
	Src []byte
	// contains filtered or unexported fields
}

Reader is used to decode Kafka messages.

For all functions on Reader, if the reader has been invalidated, functions return defaults (false, 0, nil, ""). Use Complete to detect if the reader was invalidated or if the reader has remaining data.

func (*Reader) ArrayLen

func (b *Reader) ArrayLen() int32

ArrayLen returns a Kafka array length from the reader.

func (*Reader) Bool

func (b *Reader) Bool() bool

Bool returns a bool from the reader.

func (*Reader) Bytes

func (b *Reader) Bytes() []byte

Bytes returns a Kafka byte array from the reader.

This never returns nil.

func (*Reader) CompactArrayLen

func (b *Reader) CompactArrayLen() int32

CompactArrayLen returns a Kafka compact array length from the reader.

func (*Reader) CompactBytes

func (b *Reader) CompactBytes() []byte

CompactBytes returns a Kafka compact byte array from the reader.

This never returns nil.

func (*Reader) CompactNullableBytes

func (b *Reader) CompactNullableBytes() []byte

CompactNullableBytes returns a Kafka compact nullable byte array from the reader, returning nil as appropriate.

func (*Reader) CompactNullableString

func (b *Reader) CompactNullableString() *string

CompactNullableString returns a Kafka compact nullable string from the reader.

func (*Reader) CompactString

func (b *Reader) CompactString() string

CompactString returns a Kafka compact string from the reader.

func (*Reader) Complete

func (b *Reader) Complete() error

Complete returns ErrNotEnoughData if the source ran out while decoding.

func (*Reader) Float64

func (b *Reader) Float64() float64

Float64 returns a float64 from the reader.

func (*Reader) Int16

func (b *Reader) Int16() int16

Int16 returns an int16 from the reader.

func (*Reader) Int32

func (b *Reader) Int32() int32

Int32 returns an int32 from the reader.

func (*Reader) Int64

func (b *Reader) Int64() int64

Int64 returns an int64 from the reader.

func (*Reader) Int8

func (b *Reader) Int8() int8

Int8 returns an int8 from the reader.

func (*Reader) NullableBytes

func (b *Reader) NullableBytes() []byte

NullableBytes returns a Kafka nullable byte array from the reader, returning nil as appropriate.

func (*Reader) NullableString

func (b *Reader) NullableString() *string

NullableString returns a Kafka nullable string from the reader.

func (*Reader) Ok

func (b *Reader) Ok() bool

Ok returns true if the reader is still ok.

func (*Reader) Span

func (b *Reader) Span(l int) []byte

Span returns l bytes from the reader.

func (*Reader) String

func (b *Reader) String() string

String returns a Kafka string from the reader.

func (*Reader) Uint16 added in v0.6.4

func (b *Reader) Uint16() uint16

Uint16 returns an uint16 from the reader.

func (*Reader) Uint32

func (b *Reader) Uint32() uint32

Uint32 returns a uint32 from the reader.

func (*Reader) UnsafeCompactNullableString added in v1.6.0

func (b *Reader) UnsafeCompactNullableString() *string

UnsafeCompactNullableString returns a Kafka compact nullable string from the reader without allocating using the unsafe package. This must be used with care; note the string holds a reference to the original slice.

func (*Reader) UnsafeCompactString added in v1.6.0

func (b *Reader) UnsafeCompactString() string

UnsafeCompactString returns a Kafka compact string from the reader without allocating using the unsafe package. This must be used with care; note the string holds a reference to the original slice.

func (*Reader) UnsafeNullableString added in v1.6.0

func (b *Reader) UnsafeNullableString() *string

UnsafeNullableString returns a Kafka nullable string from the reader without allocating using the unsafe package. This must be used with care; note the string holds a reference to the original slice.

func (*Reader) UnsafeString added in v1.6.0

func (b *Reader) UnsafeString() string

UnsafeString returns a Kafka string from the reader without allocating using the unsafe package. This must be used with care; note the string holds a reference to the original slice.

func (*Reader) UnsafeVarintString added in v1.6.0

func (b *Reader) UnsafeVarintString() string

UnsafeVarintString returns a Kafka encoded varint string from the reader without allocating using the unsafe package. This must be used with care; note the string holds a reference to the original slice.

func (*Reader) Uuid added in v0.6.2

func (b *Reader) Uuid() [16]byte

Uuid returns a uuid from the reader.

func (*Reader) Uvarint

func (b *Reader) Uvarint() uint32

Uvarint returns a uvarint encoded uint32 from the reader.

func (*Reader) Varint

func (b *Reader) Varint() int32

Varint returns a varint int32 from the reader.

func (*Reader) VarintArrayLen

func (b *Reader) VarintArrayLen() int32

VarintArrayLen returns a Kafka array length from the reader.

func (*Reader) VarintBytes

func (b *Reader) VarintBytes() []byte

VarintBytes returns a Kafka encoded varint array from the reader, returning nil as appropriate.

func (*Reader) VarintString

func (b *Reader) VarintString() string

VarintString returns a Kafka encoded varint string from the reader.

func (*Reader) Varlong added in v1.11.4

func (b *Reader) Varlong() int64

Varlong returns a varlong int64 from the reader.

Jump to

Keyboard shortcuts

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