| Copyright | (c) Matthew Peddie 2014 |
|---|---|
| License | BSD3 |
| Maintainer | mpeddie@gmail.com |
| Stability | experimental |
| Portability | GHC |
| Safe Haskell | None |
| Language | Haskell2010 |
Language.Libconfig.Encode
Description
Converting from Language.Libconfig.Types structures to native
libconfig Configurations.
- encode :: Group -> IO (Either EncodeError Configuration)
- encodeAt :: Configuration -> Group -> IO (Either EncodeError ())
- encodeValue :: Setting -> Value -> IO (Either EncodeError ())
- encodeTo :: Group -> String -> IO (Either EncodeError ())
- data EncodeError
- = EncoderRoot
- | TypeMismatch { }
- | FileOutput { }
- | AddSetting { }
- | RemoveOldValue { }
- | SetValue { }
- | SetIndex { }
- valueType :: Value -> ConfigType
- scalarType :: Scalar -> ConfigType
Documentation
To run these usage examples, you must tell GHC it's allowed to
parse string literals as Text values:
>>>:set -XOverloadedStrings
We also pre-define the test Group to be the example from the
libconfig manual.
>>>let Just [version, application, window, title, size, w, h, pos, x, y, list, books, author, price, qty, misc, pi, columns, bigint, bitmask] = mapM textToName ["version", "application", "window", "title", "size", "w", "h", "pos", "x", "y", "list", "books", "author", "price", "qty", "misc", "pi", "columns", "bigint", "bitmask"]>>>let test = [version := Scalar (String "1.0"),application := Group [window := Group [title := Scalar (String "My Application"),size := Group [w := Scalar (Integer 640),h := Scalar (Integer 480)],pos := Group [x := Scalar (Integer 350),y := Scalar (Integer 250)]],list := List [List [Scalar (String "abc"),Scalar (Integer 123),Scalar (Boolean True)],Scalar (Float 1.234),List []],books := List [Group [title := Scalar (String "Treasure Island"),author := Scalar (String "Robert Louis Stevenson"),price := Scalar (Float 29.95),qty := Scalar (Integer 5)],Group [title := Scalar (String "Snow Crash"),author := Scalar (String "Neal Stephenson"),price := Scalar (Float 9.99),qty := Scalar (Integer 8)]],misc := Group [pi := Scalar (Float 3.141592654),bigint := Scalar (Integer64 9223372036854775807),columns := Array [String "Last Name",String "First Name",String "MI"],bitmask := Scalar (Hex 8131)]]]
Encoding libconfig native data
encode :: Group -> IO (Either EncodeError Configuration) Source
Convert a top-level Group of Settings into a native
Configuration. This allocates a new Configuration.
>>>Right conf <- encode test>>>C.configWriteFile conf "/tmp/encode_output_test.conf"Just ()
>>>Just newconf <- C.configNew "/tmp/encode_output_test.conf"
encodeAt :: Configuration -> Group -> IO (Either EncodeError ()) Source
Encode a top-level Group of Settings and write them to the
specified Configuration.
encodeValue :: Setting -> Value -> IO (Either EncodeError ()) Source
Encoding errors
data EncodeError Source
Any of these problems can occur while encoding a libconfig
Configuration.
Constructors
| EncoderRoot | No root setting was found (possibly this configuration is invalid?) |
| TypeMismatch | |
Fields
| |
| FileOutput | |
Fields
| |
| AddSetting | |
Fields
| |
| RemoveOldValue | |
Fields
| |
| SetValue | |
Fields
| |
| SetIndex | |
Fields
| |
Helpers
valueType :: Value -> ConfigType Source
Compute the ConfigType of a Value
>>>valueType (Scalar (String "butts"))StringType
>>>valueType (Array [String "butts"])ArrayType
scalarType :: Scalar -> ConfigType Source
Compute the ConfigType of a Scalar
>>>scalarType (String "butts")StringType
>>>scalarType (Boolean False)BoolType