packages feed

proto-lens 0.1.0.5 → 0.2.0.0

raw patch · 4 files changed

+19/−80 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.ProtoLens.Field: ProxySym :: ProxySym
- Data.ProtoLens.Field: class HasField (s :: Symbol) a b | a -> b, b -> a
- Data.ProtoLens.Field: data ProxySym (s :: Symbol)
- Data.ProtoLens.Field: field :: HasField s a b => ProxySym s -> Lens a b (Field s a) (Field s b)
- Data.ProtoLens.Field: maybeLens :: b -> Lens' (Maybe b) b
+ Data.ProtoLens.Message: maybeLens :: b -> Lens' (Maybe b) b

Files

proto-lens.cabal view
@@ -1,5 +1,5 @@ name:                proto-lens-version:             0.1.0.5+version:             0.2.0.0 synopsis:            A lens-based implementation of protocol buffers in Haskell. description:   The proto-lens library provides to protocol buffers using modern@@ -15,7 +15,7 @@ license:             BSD3 license-file:        LICENSE author:              Judah Jacobson-maintainer:          judahjacobson+protolens@google.com+maintainer:          proto-lens@googlegroups.com copyright:           Google Inc. category:            Data build-type:          Simple@@ -25,7 +25,6 @@   hs-source-dirs: src   exposed-modules:     Data.ProtoLens                        Data.ProtoLens.Encoding-                       Data.ProtoLens.Field                        Data.ProtoLens.Message                        Data.ProtoLens.Message.Enum                        Data.ProtoLens.TextFormat
src/Data/ProtoLens.hs view
@@ -8,12 +8,10 @@ -- Haskell. module Data.ProtoLens (     module Data.ProtoLens.Encoding,-    module Data.ProtoLens.Field,     module Data.ProtoLens.Message,     module Data.ProtoLens.TextFormat,     ) where  import Data.ProtoLens.Encoding-import Data.ProtoLens.Field import Data.ProtoLens.Message import Data.ProtoLens.TextFormat
− src/Data/ProtoLens/Field.hs
@@ -1,75 +0,0 @@--- Copyright 2016 Google Inc. All Rights Reserved.------ Use of this source code is governed by a BSD-style--- license that can be found in the LICENSE file or at--- https://developers.google.com/open-source/licenses/bsd--{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE TypeFamilies #-}---- | A simple interface supporting overloaded record fields.------ An example instance:------ > data Foo = Foo { _bar :: Bool }--- > type instance Field "bar" Foo = Bool--- >--- > instance HasField "bar" Foo Foo where--- >     field _ = lens _bar (\f x -> f { _bar = x })--- >--- > bar :: HasField "bar" a a => Lens a b Bool Bool--- > bar = field (ProxySym :: ProxySym "bar")------ The proto compiler defines separate instances of 'HasField' for each field--- of each record.  It defines the accessors (e.g., the lens @bar@ above) once--- per unique field name, shared between different message types within the--- same module.-module Data.ProtoLens.Field-    ( -- * Overloaded fields-     Field-    , HasField(..)-    , ProxySym(..)-    -- * Helper lenses-    , maybeLens-    ) where--import Data.Maybe (fromMaybe)-import GHC.TypeLits (Symbol)-import Lens.Family2 (Lens, Lens')-import Lens.Family2.Unchecked (lens)---- | A \"proxy\" value for a type-level string (i.e., a type of kind 'Symbol').-data ProxySym (s :: Symbol) = ProxySym---- | The type of the field 's' in a message of type 'a'.-type family Field (s :: Symbol) a---- | A class for overloaded fields.------ - 's' is a 'Symbol' representing the field name.--- - 'a' is the message type for getting this field--- - 'b' is the message type after setting this field.------ Currently 'a' and 'b' are the same in all generated instances.  In the--- future, when we support type-checking of required fields we'll need--- different 'a' and 'b'; for more details see <go/proto-lens>.-class HasField (s :: Symbol) a b | a -> b, b -> a where-    field :: ProxySym s -> Lens a b (Field s a) (Field s b)---- | A helper lens for accessing optional fields.--- This is used as part of code generation, and should generally not be needed--- explicitly.------ Note that 'maybeLens' does not satisfy the lens laws, which expect that @set--- l (view l x) == x@.  For example,------ > set (maybeLens 'a') (view (maybeLens 'a') Nothing) == Just 'a'------ However, this is the behavior generally expected by users, and only matters--- if we're explicitly checking whether a field is set.-maybeLens :: b -> Lens' (Maybe b) b-maybeLens x = lens (fromMaybe x) $ const Just
src/Data/ProtoLens/Message.hs view
@@ -26,6 +26,8 @@     -- * Building protocol buffers     Default(..),     build,+    -- * Utilities for constructing protocol buffer lenses+    maybeLens,     -- * Internal utilities for parsing protocol buffers     reverseRepeatedFields,     ) where@@ -35,9 +37,11 @@ import Data.Int import qualified Data.Map as Map import Data.Map (Map)+import Data.Maybe (fromMaybe) import qualified Data.Text as T import Data.Word import Lens.Family2 (Lens', over)+import Lens.Family2.Unchecked (lens)  -- | Every protocol buffer is an instance of 'Message'.  This class enables -- serialization by providing reflection of all of the fields that may be used@@ -191,6 +195,19 @@ build :: Default a => (a -> a) -> a build = ($ def) +-- | A helper lens for accessing optional fields.+-- This is used as part of code generation, and should generally not be needed+-- explicitly.+--+-- Note that 'maybeLens' does not satisfy the lens laws, which expect that @set+-- l (view l x) == x@.  For example,+--+-- > set (maybeLens 'a') (view (maybeLens 'a') Nothing) == Just 'a'+--+-- However, this is the behavior generally expected by users, and only matters+-- if we're explicitly checking whether a field is set.+maybeLens :: b -> Lens' (Maybe b) b+maybeLens x = lens (fromMaybe x) $ const Just -- | Reverse every repeated (list) field in the message. -- -- During parsing, we store fields temporarily in reverse order,