encode

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package encode provides value encoders for go.pact.im/x/phcformat package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Nil

func Nil() option.Of[Appender]

Nil returns a nil Appender option.

Types

type Appender

type Appender interface {
	// Append appends the encoded value to the dst and returns the resulting
	// slice.
	Append(dst []byte) []byte
}

Appender represents an encodable value that uses append-style API.

type Base64

type Base64[T StringOrBytes] struct {
	// Data is the unencoded data.
	Data T
}

Base64 is an Appender that encodes string or byte slice using base64.RawStdEncoding.

func NewBase64

func NewBase64[T StringOrBytes](data T) Base64[T]

NewBase64 returns a new Base64 instance.

func (Base64[T]) Append

func (v Base64[T]) Append(dst []byte) []byte

Append implements the Appender interface.

type Byte

type Byte byte

Byte is an Appender that appends a single byte.

func NewByte

func NewByte(c byte) Byte

NewByte returns a new Byte instance.

func (Byte) Append

func (v Byte) Append(dst []byte) []byte

Append implements the Appender interface.

type Bytes

type Bytes []byte

Bytes is an Appender that appends byte slice.

func NewBytes

func NewBytes(buf []byte) Bytes

NewBytes returns a new Bytes instance.

func (Bytes) Append

func (v Bytes) Append(dst []byte) []byte

Append implements the Appender interface.

type Concat

type Concat[T, U Appender] struct {
	// A is the first value to append.
	A T
	// B is the second value to append.
	B U
}

Concat is an Appender that concatenates two values.

func NewConcat

func NewConcat[T, U Appender](a T, b U) Concat[T, U]

NewConcat returns a new Concat instance.

func (Concat[T, U]) Append

func (v Concat[T, U]) Append(dst []byte) []byte

Append implements the Appender interface.

type Empty

type Empty struct{}

Empty is an Appender that does nothing.

func NewEmpty

func NewEmpty() Empty

NewEmpty returns a new Empty instance.

func (Empty) Append

func (v Empty) Append(dst []byte) []byte

Append implements the Appender interface.

type KV

type KV[KeyAppender, SepAppender, ValAppender Appender] struct {
	// Key is the key in the key-value pair.
	Key KeyAppender
	// Sep is a separator that is appended between key and value.
	Sep SepAppender
	// Val is the value in the key-value pair.
	Val ValAppender
}

KV is an Appender that appends a key-value pair separated with the given separator.

func NewKV

func NewKV[KeyAppender, SepAppender, ValAppender Appender](sep SepAppender, k KeyAppender, v ValAppender) KV[KeyAppender, SepAppender, ValAppender]

NewKV returns a new KV instance.

func (KV[KeyAppender, SepAppender, ValAppender]) Append

func (v KV[KeyAppender, SepAppender, ValAppender]) Append(dst []byte) []byte

Append implements the Appender interface.

type List

type List[SeparatorAppender, ElementAppender Appender] struct {
	// Separator is a separator that is appended between elements.
	Separator SeparatorAppender
	// Elements is a list of elements to append.
	Elements []ElementAppender
}

List is an Appender that appends a list of values separated with the given separator.

func NewList

func NewList[SeparatorAppender, ElementAppender Appender](sep SeparatorAppender, elements ...ElementAppender) List[SeparatorAppender, ElementAppender]

NewList returns a new List instance.

func (List[ElementAppender, SeparatorAppender]) Append

func (v List[ElementAppender, SeparatorAppender]) Append(dst []byte) []byte

Append implements the Appender interface.

type Option

type Option[T Appender] struct {
	Option option.Of[T]
}

Option is an Appender that appends optional value if it is set.

func NewOption

func NewOption[T Appender](opt option.Of[T]) Option[T]

NewOption returns a new Option instance.

func (Option[T]) Append

func (v Option[T]) Append(dst []byte) []byte

Append implements the Appender interface.

type String

type String string

String is an Appender that appends string.

func NewString

func NewString(s string) String

NewString returns a new String instance.

func (String) Append

func (v String) Append(dst []byte) []byte

Append implements the Appender interface.

type StringOrBytes

type StringOrBytes interface {
	~string | ~[]byte
}

StringOrBytes is a union of string and byte slice types.

type Uint

type Uint uint

Uint is an Appender that encodes uint as a decimal number.

func NewUint

func NewUint(n uint) Uint

NewUint returns a new Uint instance.

func (Uint) Append

func (v Uint) Append(dst []byte) []byte

Append implements the Appender interface.

Jump to

Keyboard shortcuts

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