ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Registry.Json.Scratch

Description

A growable byte buffer that one read writes front to back, rewinds in place, and copies each finished value out of. It writes the bytes aeson writes for strings and integers without building them first.

Synopsis

Documentation

data Scratch st Source #

The buffer and the offset of its next byte.

newScratch :: Int -> ST st (Scratch st) Source #

An empty buffer with room for the given bytes.

scratchCursor :: Scratch st -> ST st Int Source #

Where the next byte goes.

rewindTo :: Scratch st -> Int -> ST st () Source #

Forget every byte from the offset on.

scratchBuffer :: Scratch st -> ST st (MutableByteArray st) Source #

The buffer as it stands. Any later write that needs room may replace it.

reserve :: Scratch st -> Int -> (MutableByteArray st -> Int -> ST st a) -> ST st a Source #

The buffer with room for the given bytes past the cursor, and the cursor.

putByte :: Scratch st -> Word8 -> ST st () Source #

Write one byte.

putVarint :: Scratch st -> Int -> ST st () Source #

Write a non-negative integer seven bits at a time, low bits first.

putEncodedText :: Scratch st -> (Int -> Int) -> Text -> ST st () Source #

Write the varint a header makes of a string's encoded length, then the bytes aeson writes for the string, quotes included.

putPlainBytes :: Scratch st -> ByteString -> ST st () Source #

Write a string whose bytes need no escape, between quotes.

putRawBytes :: Scratch st -> ByteString -> ST st () Source #

Write bytes as they are.

putDecimal :: Scratch st -> Int -> ST st () Source #

Write an integer in decimal, as aeson writes one.

putAt :: Scratch st -> Int -> (MutableByteArray st -> Int -> ST st Int) -> ST st () Source #

Write bytes at the cursor with the given writer, which returns the offset after them.

copyOut :: Scratch st -> Int -> Int -> ST st ByteArray Source #

A copy of the bytes between two offsets, in an array of their exact size.

decimalLength :: Int -> Int Source #

The bytes putDecimal writes.