// Package encode provides value encoders for [go.pact.im/x/phcformat] package.
package encodeimport ()// Appender represents an encodable value that uses append-style API.typeAppenderinterface {// Append appends the encoded value to the dst and returns the resulting // slice.Append(dst []byte) []byte}// Nil returns a nil Appender option.func () option.Of[Appender] {returnoption.Nil[Appender]()}// StringOrBytes is a union of string and byte slice types.typeStringOrBytesinterface { ~string | ~[]byte}// Empty is an Appender that does nothing.typeEmptystruct{}// NewEmpty returns a new Empty instance.func () Empty {returnEmpty{}}// Append implements the Appender interface.func ( Empty) ( []byte) []byte {return}// Option is an Appender that appends optional value if it is set.typeOption[ Appender] struct {Optionoption.Of[]}// NewOption returns a new Option instance.func [ Appender]( option.Of[]) Option[] {returnOption[]{Option: , }}// Append implements the Appender interface.func ( Option[]) ( []byte) []byte { , := .Option.Unwrap()if ! {return }return .Append()}// Concat is an Appender that concatenates two values.typeConcat[, Appender] struct {// A is the first value to append.A// B is the second value to append.B}// NewConcat returns a new Concat instance.func [, Appender]( , ) Concat[, ] {returnConcat[, ]{A: ,B: , }}// Append implements the Appender interface.func ( Concat[, ]) ( []byte) []byte { = .A.Append() = .B.Append()return}// List is an Appender that appends a list of values separated with the given// separator.typeList[, Appender] struct {// Separator is a separator that is appended between elements.Separator// Elements is a list of elements to append.Elements []}// NewList returns a new List instance.func [, Appender]( , ...) List[, ] {returnList[, ]{Separator: ,Elements: , }}// Append implements the Appender interface.func ( List[, ]) ( []byte) []byte {iflen(.Elements) == 0 {return } = .Elements[0].Append()for , := range .Elements[1:] { = .Separator.Append() = .Append() }return}// KV is an Appender that appends a key-value pair separated with the given// separator.typeKV[, , Appender] struct {// Key is the key in the key-value pair.Key// Sep is a separator that is appended between key and value.Sep// Val is the value in the key-value pair.Val}// NewKV returns a new KV instance.func [, , Appender]( , , ) KV[, , ] {returnKV[, , ]{Key: ,Sep: ,Val: , }}// Append implements the Appender interface.func ( KV[, , ]) ( []byte) []byte { = .Key.Append() = .Sep.Append() = .Val.Append()return}// Byte is an Appender that appends a single byte.typeBytebyte// NewByte returns a new Byte instance.func ( byte) Byte {returnByte()}// Append implements the Appender interface.func ( Byte) ( []byte) []byte {returnappend(, byte())}// String is an Appender that appends string.typeStringstring// NewString returns a new String instance.func ( string) String {returnString()}// Append implements the Appender interface.func ( String) ( []byte) []byte {returnappend(, ...)}// Bytes is an Appender that appends byte slice.typeBytes []byte// NewBytes returns a new Bytes instance.func ( []byte) Bytes {returnBytes()}// Append implements the Appender interface.func ( Bytes) ( []byte) []byte {returnappend(, ...)}// Uint is an Appender that encodes uint as a decimal number.typeUintuint// NewUint returns a new Uint instance.func ( uint) Uint {returnUint()}// Append implements the Appender interface.func ( Uint) ( []byte) []byte {returnstrconv.AppendUint(, uint64(), 10)}// Base64 is an Appender that encodes string or byte slice using// base64.RawStdEncoding.typeBase64[ StringOrBytes] struct {// Data is the unencoded data.Data}// NewBase64 returns a new Base64 instance.func [ StringOrBytes]( ) Base64[] {returnBase64[]{Data: , }}// Append implements the Appender interface.func ( Base64[]) ( []byte) []byte {returnbase64Append(base64.RawStdEncoding, , []byte(.Data))}// base64Append is an append-style function for base64 encoding.//// See also https://go.dev/issue/19366func ( *base64.Encoding, , []byte) []byte { := len() := .EncodedLen(len())ifcap()- < { = append(, make([]byte, )...) } else { = [:+] } .Encode([:], )return}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)