coders

package
v0.0.0-...-498d591 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: Unlicense Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeWindowedValueHeader

func EncodeWindowedValueHeader[W window](e *Encoder, eventTime time.Time, windows []W, pane PaneInfo)

EncodeWindowedValueHeader encodes the WindowedValue but not the value

Encodes an element, the windows it is in, the timestamp of the element,

and the pane of the element. The encoding is represented as: timestamp windows pane element

timestamp - A big endian 8 byte integer representing millis-since-epoch.
  The encoded representation is shifted so that the byte representation
  of negative values are lexicographically ordered before the byte
  representation of positive values. This is typically done by
  subtracting -9223372036854775808 from the value and encoding it as a
  signed big endian integer. Example values:

  -9223372036854775808: 00 00 00 00 00 00 00 00
                  -255: 7F FF FF FF FF FF FF 01
                    -1: 7F FF FF FF FF FF FF FF
                     0: 80 00 00 00 00 00 00 00
                     1: 80 00 00 00 00 00 00 01
                   256: 80 00 00 00 00 00 01 00
   9223372036854775807: FF FF FF FF FF FF FF FF

windows - The windows are encoded using the beam:coder:iterable:v1
  format, where the windows are encoded using the supplied window
  coder.

pane - The first byte of the pane info determines which type of
  encoding is used, as well as the is_first, is_last, and timing
  fields. If this byte is bits [0 1 2 3 4 5 6 7], then:
  * bits [0 1 2 3] determine the encoding as follows:
      0000 - The entire pane info is encoded as a single byte.
             The is_first, is_last, and timing fields are encoded
             as below, and the index and non-speculative index are
             both zero (and hence are not encoded here).
      0001 - The pane info is encoded as this byte plus a single
             VarInt encoed integer representing the pane index. The
             non-speculative index can be derived as follows:
               -1 if the pane is early, otherwise equal to index.
      0010 - The pane info is encoded as this byte plus two VarInt
             encoded integers representing the pane index and
             non-speculative index respectively.
  * bits [4 5] encode the timing as follows:
      00 - early
      01 - on time
      10 - late
      11 - unknown
  * bit 6 is 1 if this is the first pane, 0 otherwise.
  * bit 7 is 1 if this is the last pane, 0 otherwise.

element - The element incoded using the supplied element coder.

Components: The element coder and the window coder, in that order. WINDOWED_VALUE = 8 [(beam_urn) = "beam:coder:windowed_value:v1"];

Types

type Codable

type Codable interface {
	Encode(enc *Encoder)
	Decode(dec *Decoder)
}

Codable represents types that know how to code themselves.

type Coder

type Coder[E any] interface {
	Encode(enc *Encoder, v E)
	Decode(dec *Decoder) E
}

Coder represents a coder for a specific type.

func MakeCoder

func MakeCoder[E any]() Coder[E]

MakeCoder is a convenience function for primitive coders access.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder deserializes data from a byte slice data in the expected results.

func NewDecoder

func NewDecoder(data []byte) *Decoder

NewDecoder instantiates a new Decoder for a given byte slice.

func (*Decoder) Bool

func (d *Decoder) Bool() bool

Bool decodes a value of type bool.

func (*Decoder) Byte

func (d *Decoder) Byte() byte

Byte decodes a value of type byte.

func (*Decoder) Bytes

func (d *Decoder) Bytes() []byte

Bytes decodes a value of type []byte.

func (*Decoder) Complex128

func (d *Decoder) Complex128() complex128

Complex128 decodes a value of type complex128.

func (*Decoder) Complex64

func (d *Decoder) Complex64() complex64

Complex64 decodes a value of type complex64.

func (*Decoder) DecodeBinaryUnmarshaler

func (d *Decoder) DecodeBinaryUnmarshaler(value encoding.BinaryUnmarshaler)

DecodeBinaryUnmarshaler deserializes the value from a byte slice using UnmarshalBinary.

func (*Decoder) DecodeProto

func (d *Decoder) DecodeProto(value proto.Message)

DecodeProto deserializes the value from a byte slice using proto serialization.

func (*Decoder) Double

func (d *Decoder) Double() float64

Double decodes a value of type float64.

func (*Decoder) Empty

func (d *Decoder) Empty() bool

Empty returns true iff all bytes in d have been consumed.

func (*Decoder) Float

func (d *Decoder) Float() float32

Float decodes a value of type float32.

func (*Decoder) GlobalWindow

func (d *Decoder) GlobalWindow()

GlobalWindow encodes as no bytes, making this a no-op.

This matches with "beam:coder:global_window:v1" of the beam_runner_api.proto coders.

func (*Decoder) Int

func (d *Decoder) Int() int

Int decodes a value of type int. Int values are encoded as 64 bits.

func (*Decoder) Int16

func (d *Decoder) Int16() int16

Int16 decodes a value of type int16.

func (*Decoder) Int32

func (d *Decoder) Int32() int32

Int32 decodes a value of type int32.

func (*Decoder) Int64

func (d *Decoder) Int64() int64

Int64 decodes a value of type int64.

func (*Decoder) Int8

func (d *Decoder) Int8() int8

Int8 decodes a value of type int8.

func (*Decoder) Pane

func (d *Decoder) Pane() PaneInfo

func (*Decoder) Read

func (d *Decoder) Read(n int) []byte

Read reads and returns n bytes from the decoder and advances the decode past the read bytes.

func (*Decoder) Rune

func (d *Decoder) Rune() rune

Rune decodes a value of type rune.

func (*Decoder) StringUtf8

func (d *Decoder) StringUtf8() string

String decodes a value of type string.

func (*Decoder) Timestamp

func (d *Decoder) Timestamp() time.Time

func (*Decoder) Uint

func (d *Decoder) Uint() uint

Uint decodes a value of type uint. Uint values are encoded as 64 bits.

func (*Decoder) Uint16

func (d *Decoder) Uint16() uint16

Uint16 decodes a value of type uint16.

func (*Decoder) Uint32

func (d *Decoder) Uint32() uint32

Uint32 decodes a value of type uint32.

func (*Decoder) Uint64

func (d *Decoder) Uint64() uint64

Uint64 decodes a value of type uint64.

func (*Decoder) Uint8

func (d *Decoder) Uint8() uint8

Uint8 decodes a value of type uint8.

func (*Decoder) Varint

func (d *Decoder) Varint() uint64

Varint encodes a variable length integer.

This matches with "beam:coder:varint:v1" of the beam_runner_api.proto coders.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Bool

func (e *Encoder) Bool(arg bool)

Bool encodes an arg of type bool. Serialize boolean values as an uint8 that encodes either 0 (false) or 1 (true).

This matches with "beam:coder:bool:v1" of the beam_runner_api.proto coders.

func (*Encoder) Byte

func (e *Encoder) Byte(arg byte)

Byte encodes an arg of type byte.

func (*Encoder) Bytes

func (e *Encoder) Bytes(arg []byte)

Bytes encodes an arg of type []byte. For a byte slice, we encode its length as a varint, followed by the serialized content. Nil slices are encoded identically to 0 length slices.

This matches with "beam:coder:bytes:v1" of the beam_runner_api.proto coders.

func (*Encoder) Complex128

func (e *Encoder) Complex128(arg complex128)

Complex128 encodes an arg of type complex128.

func (*Encoder) Complex64

func (e *Encoder) Complex64(arg complex64)

Complex64 encodes an arg of type complex64. We encode the real and the imaginary parts one after the other.

func (*Encoder) Data

func (e *Encoder) Data() []byte

Data returns the byte slice that contains the serialized arguments.

func (*Encoder) Double

func (e *Encoder) Double(arg float64)

Double encodes the floating point value as a big-endian 64-bit integer according to the IEEE 754 double format bit layout. Components: None This matches with "beam:coder:double:v1" of the beam_runner_api.proto coders.

func (*Encoder) Float

func (e *Encoder) Float(arg float32)

Float32 encodes an arg of type float32.

func (*Encoder) GlobalWindow

func (e *Encoder) GlobalWindow()

GlobalWindow encodes as no bytes, making this a no-op.

This matches with "beam:coder:global_window:v1" of the beam_runner_api.proto coders.

func (*Encoder) Grow

func (e *Encoder) Grow(bytesNeeded int) []byte

Grow increases the size of the encoder's data if needed. Only appends a new slice if there is not enough capacity to satisfy bytesNeeded. Returns the slice fragment that contains bytesNeeded.

func (*Encoder) Int

func (e *Encoder) Int(arg int)

Int encodes an arg of type int. Int can have 32 bits or 64 bits based on the machine type. To simplify our reasoning, we encode the highest possible value.

func (*Encoder) Int16

func (e *Encoder) Int16(arg int16)

Int16 encodes an arg of type int16.

func (*Encoder) Int32

func (e *Encoder) Int32(arg int32)

Int32 encodes an arg of type int32.

func (*Encoder) Int64

func (e *Encoder) Int64(arg int64)

Int64 encodes an arg of type int64.

func (*Encoder) Int8

func (e *Encoder) Int8(arg int8)

Int8 encodes an arg of type int8.

func (*Encoder) IntervalWindow

func (e *Encoder) IntervalWindow(end time.Time, dur time.Duration)

IntervalWindow encodes a single interval window, which is the end time as a beam timestamp, and a varint of the duration in milliseconds.

This matches with "beam:coder:interval_window:v1" of the beam_runner_api.proto coders.

func (*Encoder) Nullable

func (e *Encoder) Nullable(isNil bool)

Nullable handles the nil bit of a value. Wraps a coder of a potentially null value A Nullable Type is encoded by:

  • A one byte null indicator, 0x00 for null values, or 0x01 for present values.
  • For present values the null indicator is followed by the value encoded with it's corresponding coder.

Components: single coder for the value NULLABLE = 17 [(beam_urn) = "beam:coder:nullable:v1"];

func (*Encoder) Pane

func (e *Encoder) Pane(pane PaneInfo)

func (*Encoder) Reset

func (e *Encoder) Reset(n int)

Reset resets the Encoder to use a buffer with a capacity of at least the provided size. All encoded data is lost.

func (*Encoder) Rune

func (e *Encoder) Rune(arg rune)

Rune encodes an arg of type rune.

func (*Encoder) StringUtf8

func (e *Encoder) StringUtf8(arg string)

String encodes an arg of type string. For a string, we encode its length as a varint, followed by the serialized content.

This matches with "beam:coder:string_utf8:v1" of the beam_runner_api.proto coders.

func (*Encoder) Timestamp

func (e *Encoder) Timestamp(ts time.Time)

Timestamp encodes event times in the following fashion.

timestamp - A big endian 8 byte integer representing millis-since-epoch.
  The encoded representation is shifted so that the byte representation
  of negative values are lexicographically ordered before the byte
  representation of positive values. This is typically done by
  subtracting -9223372036854775808 from the value and encoding it as a
  signed big endian integer. Example values:

  -9223372036854775808: 00 00 00 00 00 00 00 00
                  -255: 7F FF FF FF FF FF FF 01
                    -1: 7F FF FF FF FF FF FF FF
                     0: 80 00 00 00 00 00 00 00
                     1: 80 00 00 00 00 00 00 01
                   256: 80 00 00 00 00 00 01 00
   9223372036854775807: FF FF FF FF FF FF FF FF

func (*Encoder) Uint

func (e *Encoder) Uint(arg uint)

Uint encodes an arg of type uint. Uint can have 32 bits or 64 bits based on the machine type. To simplify our reasoning, we encode the highest possible value.

func (*Encoder) Uint16

func (e *Encoder) Uint16(arg uint16)

Uint16 encodes an arg of type uint16.

func (*Encoder) Uint32

func (e *Encoder) Uint32(arg uint32)

Uint32 encodes an arg of type uint32.

func (*Encoder) Uint64

func (e *Encoder) Uint64(arg uint64)

Uint64 encodes an arg of type uint64.

func (*Encoder) Uint8

func (e *Encoder) Uint8(arg uint8)

Uint8 encodes an arg of type uint8.

func (*Encoder) Varint

func (e *Encoder) Varint(i uint64)

Varint encodes a variable length integer.

This matches with "beam:coder:varint:v1" of the beam_runner_api.proto coders.

type GWC

type GWC struct{}

func (GWC) Encode

func (GWC) Encode(enc *Encoder)

Encode encodes this window.

type PaneInfo

type PaneInfo struct{}

func DecodeWindowedValueHeader

func DecodeWindowedValueHeader[W window](d *Decoder) (time.Time, []W, PaneInfo)

Jump to

Keyboard shortcuts

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