ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Registry.Json.Packed

Description

The packed form: one table per document holding the bytes aeson writes for each shared string, and one opcode blob per retained value. A render copies those bytes into a buffer of the output's exact length, so no string is escaped again. A value holds at most one hole: a URL string that a render may rebase onto a per-request prefix, keeping the URL's file name.

Synopsis

Encoded strings

encodeString :: Text -> ByteString Source #

The bytes aeson writes for a string, quotes included: encodedLength of them.

encodedLength :: Text -> Int Source #

The length of encodeString, from the escape writeEncoded writes for each byte.

writeEncoded :: Text -> MutableByteArray st -> Int -> ST st Int Source #

Write encodeString at an offset, and return the offset after it.

plain :: Text -> Bool Source #

Whether aeson writes the string's bytes as they are: no backslash, quote or byte below a space.

quote :: Word8 Source #

The quote byte that opens and closes a string's encoding.

The format

opNull :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

opFalse :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

opTrue :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

opShared :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

opObject :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

opArray :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

opInline :: Word8 Source #

Each value's first byte. A table index, a count, or an inline length and aeson's bytes follow. A member key is twice its table index, or twice its inline length plus one followed by its bytes.

varintSize :: Int -> Int Source #

The bytes a varint of the integer takes.

readVarint :: ByteArray -> Int -> (# Int, Int #) Source #

The varint at a position, and the position after it.

writeVarint :: Int -> MutableByteArray st -> Int -> ST st Int Source #

Write the integer's varint at an offset, and return the offset after it.

valueEnd :: ByteArray -> Int -> Int Source #

The position after the value that starts at a position.

The document table

data DocTable Source #

One document's shared strings, back to back as aeson writes them, and where each begins.

Instances

Instances details
Show DocTable Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Eq DocTable Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

docTable :: SmallArray Text -> DocTable Source #

Lay out the table from its strings in index order.

tableResident :: DocTable -> Int Source #

The heap bytes the table holds: its record, and its two arrays with their headers.

Packed values

data Packed Source #

One retained value: its opcodes, and where its hole's string starts, or -1.

Instances

Instances details
Show Packed Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Eq Packed Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Methods

(==) :: Packed -> Packed -> Bool #

(/=) :: Packed -> Packed -> Bool #

packed :: ByteArray -> Int -> Packed Source #

A value from its opcodes and the position of its hole, or -1 for none.

packedBlob :: Packed -> ByteArray Source #

The value's opcodes.

packedBytes :: Packed -> Int Source #

The bytes the value holds itself, outside its table.

packedResident :: Packed -> Int Source #

The heap bytes the value holds itself: its record, and its blob with the array's header.

withoutHole :: Packed -> Packed Source #

The value with no hole, so every render writes it as read.

Rendering

data UrlPrefix Source #

A URL prefix a render writes in place of a hole's URL, before the URL's file name: the bytes aeson writes for its characters, quotes excluded.

Instances

Instances details
Show UrlPrefix Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Eq UrlPrefix Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

urlPrefix :: Text -> UrlPrefix Source #

Encode a prefix once for every hole a render rebases.

data Piece Source #

One packed value in a render, and the index of the plan's table its own document's read sealed.

Constructors

Piece !Int !Packed 

Instances

Instances details
Show Piece Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Methods

showsPrec :: Int -> Piece -> ShowS #

show :: Piece -> String #

showList :: [Piece] -> ShowS #

Eq Piece Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Methods

(==) :: Piece -> Piece -> Bool #

(/=) :: Piece -> Piece -> Bool #

data Pieces Source #

The packed member of a rendered document: an object's members, sorted by key with no key twice, or an array's items. A render writes them in list order.

Constructors

ObjectPieces ![(Text, Piece)] 
ArrayPieces ![Piece] 

Instances

Instances details
Show Pieces Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Eq Pieces Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Methods

(==) :: Pieces -> Pieces -> Bool #

(/=) :: Pieces -> Pieces -> Bool #

data RenderPlan Source #

An assembled document: small members aeson encodes, and one member that renders from pieces over its sources' tables, each hole rebased onto the prefix when the document rebases.

Instances

Instances details
Show RenderPlan Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

Eq RenderPlan Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Packed

renderPlan :: RenderPlan -> Maybe ByteString Source #

Render an assembled document into one buffer of its exact length, or nothing when a piece names a table or string the plan lacks, or the render does not fill the buffer exactly.

planValue :: RenderPlan -> Maybe Value Source #

The assembled document as aeson's tree, as its render writes it, or nothing when a piece names a table or string the plan lacks.

planResident :: RenderPlan -> Int Source #

The heap bytes the plan's tables and pieces hold, each piece with its list cell, record and key.

Reading back

class TableStrings (t :: Type -> Type) where Source #

Where a decode finds the string and the key a table index names.

Methods

tableValue :: t st -> Int -> ST st Value Source #

tableKey :: t st -> Int -> ST st Key Source #

Instances

Instances details
TableStrings Writer Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Writer

Methods

tableValue :: Writer st -> Int -> ST st Value Source #

tableKey :: Writer st -> Int -> ST st Key Source #

decodeWith :: TableStrings t => t st -> ByteArray -> PrimVar st Int -> ST st Value Source #

Read the value at the position the variable holds back as aeson's tree, and move the variable past it. The strings resolve a table index to its string and to its key.

decodeKeyWith :: TableStrings t => t st -> ByteArray -> PrimVar st Int -> ST st Key Source #

The member key at the position the variable holds, moving the variable to its value.

decodeScalar :: ByteArray -> Int -> Int -> Value Source #

A string or number as aeson reads the bytes aeson wrote for it. A number written in exponent or fraction form reads back with an exponent aeson writes in that form again.

packedValue :: DocTable -> Packed -> Maybe Value Source #

The value back as aeson's tree, or nothing when it names a string its table lacks.