yajl-0.3.0.4: Bindings for YAJL, an event-based JSON implementation

Text.JSON.YAJL

Contents

Synopsis

Parser

data Parser m Source

data ParseStatus Source

Constructors

ParseFinished 
ParseContinue

More input is required before parsing can complete.

ParseCancelled

A callback returned False.

ParseError Text

An error occured while parsing. The included message contains details about the error.

Parser callbacks

data Callback m a Source

A callback should return True to continue parsing, or False to cancel.

setCallback :: Parser m -> Callback m a -> a -> m ()Source

Containers

Basic values

Numeric callbacks

parsedNumber :: Callback m (ByteString -> m Bool)Source

If parsedNumber is set, it overrides parsedInteger and parsedDouble. Registered functions for these callbacks will not receive any input until parsedNumber is unset.

If parsedNumber is not set, but one of parsedInteger or parsedDouble is set, then any values which cannot be represented by CLong or CDouble will cause a parse error.

The ByteString is in UTF-8.

Text callbacks

parsedAttributeText :: Callback m (Text -> m Bool)Source

Only one of parsedAttributeText, parsedAttributeBytes, or parsedAttributeBuffer may be set. If another of these callbacks is set, it will unset the others.

parsedAttributeBytes :: Callback m (ByteString -> m Bool)Source

Only one of parsedAttributeText, parsedAttributeBytes, or parsedAttributeBuffer may be set. If another of these callbacks is set, it will unset the others.

The ByteString is in UTF-8.

parsedAttributeBuffer :: Callback m ((Ptr Word8, Integer) -> m Bool)Source

Only one of parsedAttributeText, parsedAttributeBytes, or parsedAttributeBuffer may be set. If another of these callbacks is set, it will unset the others.

The buffer is in UTF-8.

parsedText :: Callback m (Text -> m Bool)Source

Only one of parsedText, parsedBytes, or parsedBuffer may be set. If another of these callbacks is set, it will unset the others.

parsedBytes :: Callback m (ByteString -> m Bool)Source

Only one of parsedText, parsedBytes, or parsedBuffer may be set. If another of these callbacks is set, it will unset the others.

The ByteString is in UTF-8.

parsedBuffer :: Callback m ((Ptr Word8, Integer) -> m Bool)Source

Only one of parsedText, parsedBytes, or parsedBuffer may be set. If another of these callbacks is set, it will unset the others.

The buffer is in UTF-8.

Parser input

parseBytes :: Parser m -> ByteString -> m ParseStatusSource

The input must be in UTF-8.

parseLazyBytes :: Parser m -> ByteString -> m ParseStatusSource

The input must be in UTF-8.

parseBuffer :: Parser m -> (Ptr Word8, Integer) -> m ParseStatusSource

The input must be in UTF-8.

parseComplete :: Parser m -> m ParseStatusSource

Clients should call this when no more input is available, to indicate EOF.

getBytesConsumed :: Parser m -> m IntegerSource

Get the number of bytes consumed from the last input chunk.

Note that if using parseText or parseLazyText, this corresponds to UTF-8 bytes, not characters.

If the most recent call to parseBytes, parseText, etc, returned ParseFinished, this will indicate whether there are any un-parsed bytes past the end of input.

If the most recent parse returned ParseError, this will indicate where the error occured.

Generator

data GeneratorConfig Source

Constructors

GeneratorConfig 

Fields

generatorBeautify :: Bool

Whether to generate indented, whitespaced output.

generatorIndent :: Text

How much to indent beautified output by. This is only used if generatorBeautify is True.

data GeneratorError Source

If an error is encountered when generating data, a GeneratorError will be thrown.

With the exception of MaximumDepthExceeded, this is usually due to incorrect use of the library.

newGenerator :: GeneratorConfig -> ST s (Generator s)Source

Create a new, empty generator with the given configuration.

getBuffer :: Generator s -> ST s ByteStringSource

Retrieve the NUL-terminated byte buffer.

clearBuffer :: Generator s -> ST s ()Source

Clear the generator's output buffer. This does not change the state of the generator.

Generator events