module Codec.Candid.EncodeTextual where

import qualified Data.ByteString.Lazy as BS
import qualified Data.ByteString.Builder as B
import Control.Monad

import Codec.Candid.Parse
import Codec.Candid.Encode

-- | Encodes a Candid value given in textual form.
--
-- This may fail if the textual form cannot be parsed or has inconsistent
-- types. It does not use the @reserved@ supertype (unless explicitly told to).
encodeTextual :: String -> Either String BS.ByteString
encodeTextual :: String -> Either String ByteString
encodeTextual = String -> Either String [Value]
parseValues forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> [Value] -> Either String Builder
encodeDynValues forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
B.toLazyByteString