text

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnmarshalHex

func UnmarshalHex(b B) (h B, rem B, err error)

UnmarshalHex takes a byte string that should contain a quoted hexadecimal encoded value, decodes it in-place using a SIMD hex codec and returns the decoded truncated bytes (the other half will be as it was but no allocation is required).

func UnmarshalHexArray

func UnmarshalHexArray(b B, size int) (t []B, rem B, err error)

UnmarshalHexArray unpacks a JSON array containing strings with hexadecimal, and checks all values have the specified byte size..

func UnmarshalStringArray

func UnmarshalStringArray(b B) (t []B, rem B, err error)

UnmarshalStringArray unpacks a JSON array containing strings.

Types

type AppendBytesClosure

type AppendBytesClosure func(dst, src B) B

type AppendClosure

type AppendClosure func(dst B) B

type B

type B = []byte

func AppendBackticks

func AppendBackticks(dst, src B, ac AppendBytesClosure) B

func AppendBinary

func AppendBinary(dst, src B) (b B)

AppendBinary is a straight append with length prefix.

func AppendBinaryFromHex

func AppendBinaryFromHex(dst, src B, unquote bool) (b B,
	err error)

func AppendBrace

func AppendBrace(dst, src B, ac AppendBytesClosure) B

func AppendBracket

func AppendBracket(dst, src B, ac AppendBytesClosure) B

func AppendHexFromBinary

func AppendHexFromBinary(dst, src B, quote bool) (b B)

func AppendList

func AppendList(dst B, src []B, separator byte,
	ac AppendBytesClosure) B

func AppendParenthesis

func AppendParenthesis(dst, src B, ac AppendBytesClosure) B

func AppendQuote

func AppendQuote(dst, src B, ac AppendBytesClosure) B

func AppendSingleQuote

func AppendSingleQuote(dst, src B, ac AppendBytesClosure) B

func Comma

func Comma(b B) (rem B, err error)

func ExtractBinary

func ExtractBinary(b B) (str, rem B, err error)

ExtractBinary decodes the data based on the length prefix and returns a the the remaining data from the provided slice.

func False

func False() B

func JSONKey

func JSONKey(dst, k B) (b B)

JSONKey generates the JSON format for an object key and terminates with the semicolon.

func MarshalBool

func MarshalBool(src B, truth bool) B

func MarshalHexArray

func MarshalHexArray(dst B, ha []B) (b B)

func MarshalKindsArray

func MarshalKindsArray(dst B, ka *kinds.T) (b B)

func Noop

func Noop(dst, src B) B

func NostrEscape

func NostrEscape(dst, src B) B

NostrEscape for JSON encoding according to RFC8259.

This is the efficient implementation based on the NIP-01 specification:

To prevent implementation differences from creating a different event ID for the same event, the following rules MUST be followed while serializing:

No whitespace, line breaks or other unnecessary formatting should be included
in the output JSON. No characters except the following should be escaped, and
instead should be included verbatim:

- A line break, 0x0A, as \n
- A double quote, 0x22, as \"
- A backslash, 0x5C, as \\
- A carriage return, 0x0D, as \r
- A tab character, 0x09, as \t
- A backspace, 0x08, as \b
- A form feed, 0x0C, as \f

UTF-8 should be used for encoding.

func NostrUnescape

func NostrUnescape(dst B) (b B)

NostrUnescape reverses the operation of NostrEscape except instead of appending it to the provided slice, it rewrites it, eliminating a memory copy. Keep in mind that the original JSON will be mangled by this operation, but the resultant slices will cost zero allocations.

func Quote

func Quote(dst, src B) B

func True

func True() B

func UnmarshalBool

func UnmarshalBool(src B) (rem B, truth bool, err error)

func UnmarshalKindsArray

func UnmarshalKindsArray(b B) (k *kinds.T, rem B, err error)

func UnmarshalQuoted

func UnmarshalQuoted(b B) (content, rem B, err error)

UnmarshalQuoted performs an in-place unquoting of NIP-01 quoted byte string.

func Unquote

func Unquote(b B) B

type Ctx

type Ctx = context.T

type E

type E = error

type N

type N = int

type S

type S = string

Jump to

Keyboard shortcuts

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