Documentation ¶
Index ¶
- func EscapeByteString(dst []byte, s []byte) []byte
- func UnescapeByteString(dst, src []byte) []byte
- type Buffer
- func (b *Buffer) Bytes() (bb []byte)
- func (b *Buffer) Copy(length, src, dest int) (err error)
- func (b *Buffer) Head() []byte
- func (b *Buffer) Read() (bb byte, err error)
- func (b *Buffer) ReadBytes(count int) (bb []byte, err error)
- func (b *Buffer) ReadEnclosed() (bb []byte, err error)
- func (b *Buffer) ReadThrough(c byte) (bb []byte, err error)
- func (b *Buffer) ReadUntil(c byte) (bb []byte, err error)
- func (b *Buffer) Scan(c byte, through, slice bool) (subSlice []byte, err error)
- func (b *Buffer) ScanForOneOf(through bool, c ...byte) (which byte, err error)
- func (b *Buffer) ScanThrough(c byte) (err error)
- func (b *Buffer) ScanUntil(c byte) (err error)
- func (b *Buffer) String() (s string)
- func (b *Buffer) Tail() []byte
- func (b *Buffer) Write(bb byte) (err error)
- func (b *Buffer) WriteBytes(bb []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeByteString ¶ added in v0.0.6
EscapeByteString 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 UnescapeByteString ¶
Types ¶
type Buffer ¶
func NewBuffer ¶
NewBuffer returns a new buffer containing the provided slice. This slice can/will be mutated.
func (*Buffer) Copy ¶
Copy a given length of bytes starting at src position to dest position, and move the cursor to the end of the written segment.
func (*Buffer) ReadBytes ¶
ReadBytes returns the specified number of byte, and advances the cursor, or io.EOF if there isn't this much remaining after the cursor.
func (*Buffer) ReadEnclosed ¶
ReadEnclosed scans quickly while keeping count of open and close brackets [] or braces {} and returns the byte sub-slice starting with a bracket and ending with the same depth bracket. Selects the counted characters based on the first.
Ignores anything within quotes.
Useful for quickly finding a potentially valid array or object in JSON.
func (*Buffer) ReadThrough ¶
ReadThrough is the same as ReadUntil except it returns a slice *including* the character being sought.
func (*Buffer) ReadUntil ¶
ReadUntil returns all of the buffer from the Pos at invocation, until the index immediately before the match of the requested character.
The next Read or Write after this will return the found character or mutate it. If the first character at the index of the Pos is the one being sought, it returns a zero length slice.
Note that the implementation does not increment the Pos position until either the end of the buffer or when the requested character is found, because there is no need to write the value twice for no reason.
When this function returns an error, the state of the buffer is unchanged from prior to the invocation.
If the character is not `"` then any match within a pair of unescaped `"` is ignored. The closing `"` is not counted if it is escaped with a \.
If the character is `"` then any `"` with a `\` before it is ignored (and included in the returned slice).
func (*Buffer) ScanForOneOf ¶
ScanForOneOf provides the ability to scan for two or more different bytes.
For simplicity it does not skip quotes, it was actually written to find quotes or braces but just to make it clear this is very bare.
if through is set to true, the cursor is advanced to the next after the match
func (*Buffer) ScanThrough ¶
ScanThrough does the same as ScanUntil except it returns the next index *after* the found item.
func (*Buffer) ScanUntil ¶
ScanUntil does the same as ReadUntil except it doesn't slice what it passed over.
func (*Buffer) Write ¶
Write a byte into the next index of the buffer or return io.EOF if there is no space left.
func (*Buffer) WriteBytes ¶
WriteBytes copies over top of the current buffer with the bytes given.
Returns io.EOF if the write would exceed the end of the buffer, and does not perform the operation, nor move the cursor.