protocol-buffers 1.4.0 → 1.5.0
raw patch · 12 files changed
+267/−827 lines, 12 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.ProtocolBuffers.Basic: wireGetPacked :: (Wire b) => FieldType -> Get (Seq b)
+ Text.ProtocolBuffers.Extensions: ExtPacked :: !FieldType -> !GPDynSeq -> ExtFieldValue
+ Text.ProtocolBuffers.Extensions: PackedSeq :: (Seq a) -> PackedSeq a
+ Text.ProtocolBuffers.Extensions: instance ExtKey PackedSeq
+ Text.ProtocolBuffers.Extensions: instance Typeable1 PackedSeq
+ Text.ProtocolBuffers.Extensions: newtype PackedSeq a
+ Text.ProtocolBuffers.Extensions: unPackedSeq :: PackedSeq a -> (Seq a)
+ Text.ProtocolBuffers.Reflections: isPacked :: FieldInfo -> Bool
+ Text.ProtocolBuffers.WireMessage: toPackedWireTag :: FieldId -> WireTag
+ Text.ProtocolBuffers.WireMessage: wireGetPacked :: (Wire b) => FieldType -> Get (Seq b)
+ Text.ProtocolBuffers.WireMessage: wireGetPackedEnum :: (Typeable e, Enum e) => (Int -> Maybe e) -> Get (Seq e)
+ Text.ProtocolBuffers.WireMessage: wirePutPacked :: (Wire v) => WireTag -> FieldType -> Seq v -> Put
+ Text.ProtocolBuffers.WireMessage: wireSizePacked :: (Wire v) => Int64 -> FieldType -> Seq v -> Int64
- Text.ProtocolBuffers.Reflections: FieldInfo :: ProtoFName -> FieldId -> WireTag -> WireSize -> Bool -> Bool -> FieldType -> Maybe ProtoName -> Maybe ByteString -> Maybe HsDefault -> FieldInfo
+ Text.ProtocolBuffers.Reflections: FieldInfo :: ProtoFName -> FieldId -> WireTag -> WireSize -> Bool -> Bool -> Bool -> FieldType -> Maybe ProtoName -> Maybe ByteString -> Maybe HsDefault -> FieldInfo
- Text.ProtocolBuffers.WireMessage: wirePutOpt :: (Wire b) => WireTag -> FieldType -> Maybe b -> Put
+ Text.ProtocolBuffers.WireMessage: wirePutOpt :: (Wire v) => WireTag -> FieldType -> Maybe v -> Put
- Text.ProtocolBuffers.WireMessage: wirePutRep :: (Wire b) => WireTag -> FieldType -> Seq b -> Put
+ Text.ProtocolBuffers.WireMessage: wirePutRep :: (Wire v) => WireTag -> FieldType -> Seq v -> Put
- Text.ProtocolBuffers.WireMessage: wirePutReq :: (Wire b) => WireTag -> FieldType -> b -> Put
+ Text.ProtocolBuffers.WireMessage: wirePutReq :: (Wire v) => WireTag -> FieldType -> v -> Put
- Text.ProtocolBuffers.WireMessage: wireSizeOpt :: (Wire b) => Int64 -> FieldType -> Maybe b -> Int64
+ Text.ProtocolBuffers.WireMessage: wireSizeOpt :: (Wire v) => Int64 -> FieldType -> Maybe v -> Int64
- Text.ProtocolBuffers.WireMessage: wireSizeRep :: (Wire b) => Int64 -> FieldType -> Seq b -> Int64
+ Text.ProtocolBuffers.WireMessage: wireSizeRep :: (Wire v) => Int64 -> FieldType -> Seq v -> Int64
- Text.ProtocolBuffers.WireMessage: wireSizeReq :: (Wire b) => Int64 -> FieldType -> b -> Int64
+ Text.ProtocolBuffers.WireMessage: wireSizeReq :: (Wire v) => Int64 -> FieldType -> v -> Int64
Files
- README +14/−5
- Text/ProtocolBuffers/Basic.hs +8/−1
- Text/ProtocolBuffers/Extensions.hs +120/−12
- Text/ProtocolBuffers/Header.hs +6/−3
- Text/ProtocolBuffers/Identifiers.hs +3/−3
- Text/ProtocolBuffers/Mergeable.hs +4/−3
- Text/ProtocolBuffers/Reflections.hs +1/−0
- Text/ProtocolBuffers/WireMessage.hs +110/−26
- google/protobuf/unittest.proto +0/−452
- google/protobuf/unittest_custom_options.proto +0/−271
- google/protobuf/unittest_import.proto +0/−47
- protocol-buffers.cabal +1/−4
README view
@@ -1,9 +1,18 @@ This the README file for protocol-buffers, protocol-buffers-descriptors, and hprotoc. These are three interdependent Haskell packages by Chris Kuklewicz.-This README was updated most recently to reflect version 1.4.0+This README was updated most recently to reflect version 1.5.0+This code should be compatible with Google protobuf version 2.1.0 Questions and answers: +What is new in 1.5.0 ?++ The "packed" repeated fields should work on the wire, "deprecated" fields are parsed properly but+ not nothing is otherwise done about this flag. The parser should disambiguate references to+ messages/groups/enums by ignoring fields with the same name (for types of normal fields and+ extension fields). The Lexar has had a few fixes courtesy of George van den Driessche (newlines+ after numeric literals in proto files should now be handled).+ What is this for? What does it do? Why? It is a pure Haskell re-implementation of the Google code at@@ -56,11 +65,11 @@ What do I need to compile the code? - I use ghc (version 6.10.1, previously version 6.8.3) and cabal (version 1.6.0.1, previously version 1.2.4.0).+ I use ghc (version 6.10.3) and cabal (version 1.6.0.3). - The dependencies are listed in the .cabal files, and these currently require you to go to hackage.haskell.org and get packages "binary" (I use version 0.4.4, previously version 0.4.2) and "utf8-string" (I use version 0.3.3, previously version 0.3.1.1) and hprotoc needs haskell-src-exts (exactly the "latest" version 4.8.0, upgrades tend to break compilation until (easily) patched).+ The dependencies are listed in the .cabal files, and these currently require you to go to hackage.haskell.org and get packages "binary" (I use version 0.5.0.1) and "utf8-string" (I use version 0.3.5) and hprotoc needs haskell-src-exts (exactly version 0.4.8 at the moment). - The hprotoc Lexer.hs is produced from Lexer.x by the alex program (I use version 2.2) which can be downloaded from http://www.haskell.org/alex/ if you edit Lexer.x and need to regenerate Lexer.hs.+ The hprotoc Lexer.hs is produced from Lexer.x by the alex program (I use version 2.3.1) which can be downloaded from http://www.haskell.org/alex/ if you edit Lexer.x and need to regenerate Lexer.hs. The usual cabal configure/buid/install works for the protocol-buffers library (and haddock for API docs): runhaskell Setup.hs configure @@ -92,7 +101,7 @@ Where is the API documentation? - These file should be able to have cabal run the haddock generation. I am using Haddock version 2.2.2 at the moment. The imports of Text.ProtocolBuffers are the public API. The generated code's API is Text.ProtocolBuffers.Header. The only usage examples are in the examples sub-directory and the tests sub-directory. Since the messages are simply Haskell data types most of the manipulation should be easy.+ These file should be able to have cabal run the haddock generation. I am using Haddock version 2.4.2 at the moment. The imports of Text.ProtocolBuffers are the public API. The generated code's API is Text.ProtocolBuffers.Header. The only usage examples are in the examples sub-directory and the tests sub-directory. Since the messages are simply Haskell data types most of the manipulation should be easy. The main thing that is weird is that messages with extension ranges get an ExtField record field that holds ... an internal data structure. This is currently a Map from field number to a rather complicated existential + GADT combination that should really only be touched by the ExtKey and MessageAPI type class methods. The ExtField data constructor is not hidden, though it could be and probably ought to be.
Text/ProtocolBuffers/Basic.hs view
@@ -12,6 +12,7 @@ , isValidUTF8, toUtf8, utf8 ) where +import Control.Monad.Error.Class(throwError) import Data.Binary.Put(Put) import Data.Bits(Bits) import Data.ByteString.Lazy(ByteString)@@ -167,7 +168,8 @@ mergeAppend _a b = b -- | 'mergeConcat' is @ F.foldl mergeAppend mergeEmpty @ and this- -- default definition is not overrring in any of the code.+ -- default definition is not overridden in any of the code except+ -- for the (Seq a) instance. mergeConcat :: F.Foldable t => t a -> a mergeConcat = F.foldl mergeAppend mergeEmpty @@ -200,6 +202,11 @@ wirePut :: FieldType -> b -> Put {-# INLINE wireGet #-} wireGet :: FieldType -> Get b+ {-# INLINE wireGetPacked #-}+ wireGetPacked :: FieldType -> Get (Seq b)+ wireGetPacked ft = throwError ("Text.ProtocolBuffers.ProtoCompile.Basic: wireGetPacked default:"+ ++ "\n There is no way to get a packed FieldType of "++show ft+ ++ ".\n Either there is a bug in this library or the wire format is has been updated.") -- Returns Nothing if valid, and the position of the error if invalid isValidUTF8 :: ByteString -> Maybe Int
Text/ProtocolBuffers/Extensions.hs view
@@ -21,6 +21,7 @@ getKeyFieldId,getKeyFieldType,getKeyDefaultValue -- * External types and classes , Key(..),ExtKey(..),MessageAPI(..)+ , PackedSeq(..) -- * Internal types, functions, and classes , wireSizeExtField,wirePutExtField,loadExtension,notExtension , GPB,ExtField(..),ExtendMessage(..),ExtFieldValue(..)@@ -33,8 +34,8 @@ import Data.Map(Map) import qualified Data.Map as M import Data.Maybe(fromMaybe,isJust)-import Data.Monoid(mappend)-import Data.Sequence(Seq,(|>))+import Data.Monoid(mappend,mconcat)+import Data.Sequence(Seq,(|>),(><)) import qualified Data.Sequence as Seq import Data.Typeable @@ -122,12 +123,17 @@ data GPDynSeq = forall a . GPDynSeq !(GPWitness a) !(Seq a) deriving (Typeable) +-- | The 'PackedSeq' is needed to distinguish the packed repeated format from the repeated format.+-- This is only used in the phantom type of Key.+newtype PackedSeq a = PackedSeq { unPackedSeq :: (Seq a) }+ deriving (Typeable)+ -- | The WireType is used to ensure the Seq is homogenous. -- The ByteString is the unparsed input after the tag.--- The WireSize includes all tags.-data ExtFieldValue = ExtFromWire !WireType !(Seq ByteString)+data ExtFieldValue = ExtFromWire !WireType !(Seq ByteString) | ExtOptional !FieldType !GPDyn | ExtRepeated !FieldType !GPDynSeq+ | ExtPacked !FieldType !GPDynSeq deriving (Typeable,Ord,Show) data DummyMessageType deriving (Typeable)@@ -149,6 +155,7 @@ (==) (ExtFromWire a b) (ExtFromWire a' b') = a==a' && b==b' (==) (ExtOptional a b) (ExtOptional a' b') = a==a' && b==b' (==) (ExtRepeated a b) (ExtRepeated a' b') = a==a' && b==b'+ (==) (ExtPacked a b) (ExtPacked a' b') = a==a' && b==b' (==) x@(ExtOptional ft (GPDyn w@GPWitness _)) (ExtFromWire wt' s') = let wt = toWireType ft in wt==wt' && (let makeKeyType :: GPWitness a -> Key Maybe DummyMessageType a@@ -167,6 +174,15 @@ Right (_,y) -> x==y _ -> False) (==) y@(ExtFromWire {}) x@(ExtRepeated {}) = x == y+ (==) x@(ExtPacked ft (GPDynSeq w@GPWitness _)) (ExtFromWire wt' s') =+ let wt = 2 -- all packed types have wire type 2, length delimited+ in wt == wt' && (let makeKeyType :: GPWitness a -> Key PackedSeq DummyMessageType a+ makeKeyType = undefined+ key = Key 0 ft Nothing `asTypeOf` makeKeyType w+ in case parseWireExtPackedSeq key wt s' of+ Right (_,y) -> x==y+ _ -> False)+ (==) y@(ExtFromWire {}) x@(ExtPacked {}) = x == y (==) _ _ = False -- | ExtField is a newtype'd map from the numeric FieldId key to the@@ -264,6 +280,13 @@ Nothing -> err $ "mergeExtFieldValue : ExtRepeated cast failed, FieldType "++show (ft2,typeOf s1,typeOf s2) Just s2' -> ExtRepeated ft2 (GPDynSeq GPWitness (mappend s1 s2')) +mergeExtFieldValue (ExtPacked ft1 (GPDynSeq GPWitness s1))+ (ExtPacked ft2 (GPDynSeq GPWitness s2)) =+ if ft1 /= ft2 then err $ "mergeExtFieldValue : ExtPacked FieldType mismatch "++show (ft1,ft2)+ else case cast s2 of+ Nothing -> err $ "mergeExtFieldValue : ExtPacked cast failed, FieldType "++show (ft2,typeOf s1,typeOf s2)+ Just s2' -> ExtPacked ft2 (GPDynSeq GPWitness (mappend s1 s2'))+ mergeExtFieldValue a b = err $ "mergeExtFieldValue : mismatch of constructors "++show (a,b) instance Default ExtField where@@ -385,14 +408,16 @@ Nothing -> Right Nothing Just (ExtFromWire wt raw) -> either Left (getExt' . snd) (parseWireExtMaybe k wt raw) Just x -> getExt' x- where getExt' (ExtRepeated t' _) = Left $ "getKey Maybe: ExtField has repeated type: "++show (k,t')+ where getExt' (ExtRepeated t' _) = Left $ "getExt Maybe: ExtField has repeated type: "++show (k,t')+ getExt' (ExtPacked t' _) = Left $ "getExt Maybe: ExtField has packed type: "++show (k,t') getExt' (ExtOptional t' (GPDyn GPWitness d)) | t/=t' = Left $ "getExt Maybe: Key's FieldType does not match ExtField's: "++show (k,t') | otherwise = case cast d of Nothing -> Left $ "getExt Maybe: Key's value cast failed: "++show (k,typeOf d) Just d' -> Right (Just d')- getExt' _ = err $ "Impossible? getExt.getExt' Maybe should not have this case (after parseWireExt)!"+ getExt' (ExtFromWire {}) = err $ "Impossible? getExt.getExt' Maybe should not have ExtFromWire case (after parseWireExt)!"+ wireGetKey k@(Key i t mv) msg = do let myCast :: Maybe a -> Get a myCast = undefined@@ -416,7 +441,8 @@ Nothing -> fail $ "wireGetKey Maybe: previous Maybe value case failed: "++show (k,typeOf vOld) Just vOld' -> return $ ExtOptional t (GPDyn GPWitness (mergeAppend vOld' v)) wtf -> fail $ "wireGetKey Maybe: Weird parseGetWireMaybe return value: "++show (k,wtf)- wtf -> fail $ "wireGetKey Maybe: ExtRepeated found with ExtOptional expected: "++show (k,wtf)+ Just wtf@(ExtRepeated {}) -> fail $ "wireGetKey Maybe: ExtRepeated found with ExtOptional expected: "++show (k,wtf)+ Just wtf@(ExtPacked {}) -> fail $ "wireGetKey Maybe: ExtPacked found with ExtOptional expected: "++show (k,wtf) let ef' = M.insert i v' ef seq v' $ seq ef' $ return (putExtField (ExtField ef') msg) @@ -453,7 +479,7 @@ ef' = M.insert i v' ef in seq v' $ seq ef' (putExtField (ExtField ef') msg) - clearExt (Key i _ _ ) msg =+ clearExt (Key i _ _) msg = let (ExtField ef) = getExtField msg ef' = M.delete i ef in seq ef' (putExtField (ExtField ef') msg)@@ -464,14 +490,15 @@ Nothing -> Right Seq.empty Just (ExtFromWire wt raw) -> either Left (getExt' . snd) (parseWireExtSeq k wt raw) Just x -> getExt' x- where getExt' (ExtOptional t' _) = Left $ "getKey Seq: ExtField has optional type: "++show (k,t')+ where getExt' (ExtOptional t' _) = Left $ "getExt Seq: ExtField has optional type: "++show (k,t')+ getExt' (ExtPacked t' _) = Left $ "getExt Seq: ExtField has packed type: "++show (k,t') getExt' (ExtRepeated t' (GPDynSeq GPWitness s)) | t'/=t = Left $ "getExt Seq: Key's FieldType does not match ExtField's: "++show (k,t') | otherwise = case cast s of Nothing -> Left $ "getExt Seq: Key's Seq value cast failed: "++show (k,typeOf s) Just s' -> Right s'- getExt' _ = err $ "Impossible? getExt.getExt' Maybe should not have this case (after parseWireExtSeq)!"+ getExt' (ExtFromWire {}) = err $ "Impossible? getExt.getExt' Seq should not have ExtFromWire case (after parseWireExtSeq)!" -- This is more complicated than the Maybe instance because the old -- Seq needs to be retrieved and perhaps parsed and then appended@@ -500,14 +527,15 @@ Nothing -> fail $ "wireGetKey Seq: previous Seq value cast failed: "++show (k,typeOf s) Just s' -> return $ ExtRepeated t (GPDynSeq GPWitness (s' |> v)) wtf -> fail $ "wireGetKey Seq: Weird parseWireExtSeq return value: "++show (k,wtf)- wtf -> fail $ "wireGetKey Seq: ExtOptional found when ExtRepeated expected: "++show (k,wtf)+ Just wtf@(ExtOptional {}) -> fail $ "wireGetKey Seq: ExtOptional found when ExtRepeated expected: "++show (k,wtf)+ Just wtf@(ExtPacked {}) -> fail $ "wireGetKey Seq: ExtPacked found when ExtRepeated expected: "++show (k,wtf) let ef' = M.insert i v' ef seq v' $ seq ef' $ return (putExtField (ExtField ef') msg) -- | used by 'getVal' and 'wireGetKey' for the 'Seq' instance parseWireExtSeq :: Key Seq msg v -> WireType -> Seq ByteString -> Either String (FieldId,ExtFieldValue) parseWireExtSeq k@(Key i t mv) wt raw | wt /= toWireType t =- Left $ "parseWireExt Maybe: Key mismatch! Key's FieldType does not match ExtField's wire type: "++show (k,toWireType t,wt)+ Left $ "parseWireExtSeq: Key mismatch! Key's FieldType does not match ExtField's wire type: "++show (k,toWireType t,wt) | otherwise = do let mkWitType :: Maybe a -> GPWitness a mkWitType = undefined@@ -517,6 +545,75 @@ if null errs then Right (i,(ExtRepeated t (GPDynSeq witness (Seq.fromList [ a | Right a <- parsed ])))) else Left (unlines errs) +instance ExtKey PackedSeq where+ putExt key@(Key i t _) (PackedSeq s) msg | Seq.null s = clearExt key msg+ | otherwise =+ let (ExtField ef) = getExtField msg+ v' = ExtPacked t (GPDynSeq GPWitness s)+ ef' = M.insert i v' ef+ in seq v' $ seq ef' (putExtField (ExtField ef') msg)+ + clearExt (Key i _ _) msg =+ let (ExtField ef) = getExtField msg+ ef' = M.delete i ef+ in seq ef' (putExtField (ExtField ef') msg)++ getExt k@(Key i t _) msg =+ let (ExtField ef) = getExtField msg+ in case M.lookup i ef of+ Nothing -> Right (PackedSeq Seq.empty)+ Just (ExtFromWire wt raw) -> either Left (getExt' . snd) (parseWireExtPackedSeq k wt raw)+ Just x -> getExt' x+ where getExt' (ExtOptional t' _) = Left $ "getExt PackedSeq: ExtField has optional type: "++show (k,t')+ getExt' (ExtRepeated t' _) = Left $ "getExt PackedSeq: ExtField has repeated type: "++show (k,t')+ getExt' (ExtPacked t' (GPDynSeq GPWitness s)) | t'/=t =+ Left $ "getExt PackedSeq: Key's FieldType does not match ExtField's: "++show (k,t')+ | otherwise =+ case cast s of+ Nothing -> Left $ "getExt PackedSeq: Key's Seq value cast failed: "++show (k,typeOf s)+ Just s' -> Right (PackedSeq s')+ getExt' (ExtFromWire {}) = err $ "Impossible? getExt.getExt' PackedSeq should not have ExtFromWire case (after parseWireExtSeq)!"++ wireGetKey k@(Key i t mv) msg = do+ let myCast :: Maybe a -> Get (Seq a)+ myCast = undefined+ vv <- wireGetPacked t `asTypeOf` (myCast mv)+ let (ExtField ef) = getExtField msg+ v' <- case M.lookup i ef of+ Nothing -> return $ ExtPacked t (GPDynSeq GPWitness vv)+ Just (ExtPacked t' (GPDynSeq GPWitness s)) | t/=t' ->+ fail $ "wireGetKey PackedSeq: Key mismatch! found wrong field type: "++show (k,t,t')+ | otherwise ->+ case cast s of+ Nothing -> fail $ "wireGetKey PackedSeq: previous Seq value cast failed: "++show (k,typeOf s)+ Just s' -> return $ ExtRepeated t (GPDynSeq GPWitness (s' >< vv))+ Just (ExtFromWire wt raw) ->+ case parseWireExtPackedSeq k wt raw of+ Left errMsg -> fail $ "wireGetKey PackedSeq: Could not parseWireExtPackedSeq: "++show k++"\n"++errMsg+ Right (_,ExtPacked t' (GPDynSeq GPWitness s)) | t/=t' ->+ fail $ "wireGetKey PackedSeq: Key mismatch! parseWireExtPackedSeq returned wrong field type: "++show (k,t,t')+ | otherwise ->+ case cast s of+ Nothing -> fail $ "wireGetKey PackedSeq: previous Seq value cast failed: "++show (k,typeOf s)+ Just s' -> return $ ExtRepeated t (GPDynSeq GPWitness (s' >< vv))+ wtf -> fail $ "wireGetKey PackedSeq: Weird parseWireExtPackedSeq return value: "++show (k,wtf)+ Just wtf@(ExtOptional {}) -> fail $ "wireGetKey PackedSeq: ExtOptional found when ExtPacked expected: "++show (k,wtf)+ Just wtf@(ExtRepeated {}) -> fail $ "wireGetKey PackedSeq: ExtRepeated found when ExtPacked expected: "++show (k,wtf)+ let ef' = M.insert i v' ef+ seq v' $ seq ef' $ return (putExtField (ExtField ef') msg)++parseWireExtPackedSeq :: Key PackedSeq msg v -> WireType -> Seq ByteString -> Either String (FieldId,ExtFieldValue)+parseWireExtPackedSeq k@(Key i t mv) wt raw | wt /= 2 {- packed wire type is 2, length delimited -} =+ Left $ "parseWireExtPackedSeq: Key mismatch! Key's FieldType does not match ExtField's wire type: "++show (k,toWireType t,wt)+ | otherwise = do+ let mkWitType :: Maybe a -> GPWitness a+ mkWitType = undefined+ witness = GPWitness `asTypeOf` (mkWitType mv)+ parsed = map (applyGet (wireGetPacked t)) . F.toList $ raw+ errs = [ m | Left m <- parsed ]+ if null errs then Right (i,(ExtPacked t (GPDynSeq witness (mconcat [ a | Right a <- parsed ]))))+ else Left (unlines errs)+ -- | This is used by the generated code wireSizeExtField :: ExtField -> WireSize wireSizeExtField (ExtField m) = F.foldl' aSize 0 (M.assocs m) where@@ -529,6 +626,9 @@ aSize old (fi,(ExtRepeated ft (GPDynSeq GPWitness s))) = old + let tagSize = size'Varint (getWireTag (toWireTag fi ft)) in wireSizeRep tagSize ft s+ aSize old (fi,(ExtPacked ft (GPDynSeq GPWitness s))) = old ++ let tagSize = size'Varint (getWireTag (toPackedWireTag fi))+ in wireSizePacked tagSize ft s -- | This is used by the generated code. The data is serialized in -- order of increasing field number.@@ -537,6 +637,7 @@ aPut (fi,(ExtFromWire wt raw)) = F.mapM_ (\bs -> putVarUInt (getWireTag $ mkWireTag fi wt) >> putLazyByteString bs) raw aPut (fi,(ExtOptional ft (GPDyn GPWitness d))) = wirePutOpt (toWireTag fi ft) ft (Just d) aPut (fi,(ExtRepeated ft (GPDynSeq GPWitness s))) = wirePutRep (toWireTag fi ft) ft s+ aPut (fi,(ExtPacked ft (GPDynSeq GPWitness s))) = wirePutPacked (toPackedWireTag fi) ft s notExtension :: (ReflectDescriptor a, ExtendMessage a,Typeable a) => FieldId -> WireType -> a -> Get a notExtension fieldId _wireType msg = throwError ("Field id "++show fieldId++" is not a valid extension field id for "++show (typeOf (undefined `asTypeOf` msg)))@@ -548,6 +649,7 @@ --loadExtension fieldId wireType msg = unknown fieldId wireType msg -- XXX loadExtension fieldId wireType msg = do let (ExtField ef) = getExtField msg+ badwt :: WireType -> Get a badwt wt = do here <- bytesRead fail $ "Conflicting wire types at byte position "++show here ++ " for extension to message: "++show (typeOf msg,fieldId,wireType,wt) case M.lookup fieldId ef of@@ -572,6 +674,12 @@ | otherwise -> do a <- wireGet ft let v' = ExtRepeated ft (GPDynSeq x (s |> a))+ ef' = M.insert fieldId v' ef+ seq v' $ seq ef' $ return (putExtField (ExtField ef') msg)+ Just (ExtPacked ft (GPDynSeq x@GPWitness s)) | 2 /= wireType -> badwt 2 {- packed uses length delimited: 2 -}+ | otherwise -> do+ aa <- wireGetPacked ft+ let v' = ExtPacked ft (GPDynSeq x (s >< aa)) ef' = M.insert fieldId v' ef seq v' $ seq ef' $ return (putExtField (ExtField ef') msg)
Text/ProtocolBuffers/Header.hs view
@@ -2,7 +2,8 @@ -- compile. This and the Prelude will both be imported qualified as -- P', the prime ensuring no name conflicts are possible. module Text.ProtocolBuffers.Header- ( emptyBS, pack, append, fromMaybe, ap+ ( append, emptyBS+ , pack, fromMaybe, ap , fromDistinctAscList, member , throwError,catchError , module Data.Generics@@ -29,7 +30,7 @@ import Text.ProtocolBuffers.Default() import Text.ProtocolBuffers.Extensions ( wireSizeExtField,wirePutExtField,loadExtension,notExtension- , GPB,Key(..),ExtField,ExtendMessage(..),MessageAPI(..),ExtKey(wireGetKey) )+ , GPB,Key(..),ExtField,ExtendMessage(..),MessageAPI(..),ExtKey(wireGetKey),PackedSeq ) import Text.ProtocolBuffers.Identifiers(FIName(..),MName(..),FName(..)) import Text.ProtocolBuffers.Mergeable() import Text.ProtocolBuffers.Reflections@@ -41,12 +42,14 @@ ( prependMessageSize,putSize , wireSizeReq,wireSizeOpt,wireSizeRep , wirePutReq,wirePutOpt,wirePutRep- , getMessageWith,getBareMessageWith,wireGetEnum+ , getMessageWith,getBareMessageWith,wireGetEnum,wireGetPackedEnum , wireSizeErr,wirePutErr,wireGetErr , unknown,unknownField) +{-# INLINE append #-} append :: Seq a -> a -> Seq a append = (|>) +{-# INLINE emptyBS #-} emptyBS :: ByteString emptyBS = Data.ByteString.Lazy.empty
Text/ProtocolBuffers/Identifiers.hs view
@@ -1,10 +1,10 @@ -- | This modules colelct utility routines related to the different -- incarnations of identifiers in the code. The basic identifier is--- always ASCII, but because of the self gereneted DescriptorProto+-- always ASCII, but because of the self generated DescriptorProto -- data structures it is stored in 'Utf8' tagged lazy bytestrings. -- -- An 'identifier' is a non-empty ASCII string made of [a-zA-Z0-9_]--- where the first cahracter is never in [0-9].+-- where the first character is never in [0-9]. -- -- A 'field' is a mangled identifer that is a valid Haskell name that -- begins with lower case, and which may have a single quote at the@@ -13,7 +13,7 @@ -- -- A 'module' is a mangled identifier that is a valid Haskell name -- that begins with upper case. These never have a single quote. A--- leading _ is replaced with a leading U'_ to make a valid+-- leading '_' is replaced with a leading "U'_" to make a valid -- identifier. module Text.ProtocolBuffers.Identifiers ( unull,toString,fromString
Text/ProtocolBuffers/Mergeable.hs view
@@ -2,7 +2,8 @@ module Text.ProtocolBuffers.Mergeable() where import Text.ProtocolBuffers.Basic-import Data.Monoid(mempty,mappend)+-- import Data.Monoid(mempty,mappend)+import Data.Sequence(empty,(><)) -- Base types are not very mergeable, but their Maybe and Seq versions are: instance Mergeable a => Mergeable (Maybe a) where@@ -10,8 +11,8 @@ mergeAppend = mayMerge instance Mergeable (Seq a) where- mergeEmpty = mempty- mergeAppend = mappend+ mergeEmpty = empty+ mergeAppend = (><) -- These all have errors as mergeEmpty and use the second paramater for mergeAppend instance Mergeable Bool
Text/ProtocolBuffers/Reflections.hs view
@@ -96,6 +96,7 @@ , fieldNumber :: FieldId , wireTag :: WireTag , wireTagLength :: WireSize -- ^ Bytes required in the Varint formatted wireTag+ , isPacked :: Bool , isRequired :: Bool , canRepeat :: Bool , typeCode :: FieldType -- ^ fromEnum of Text.DescriptorProtos.FieldDescriptorProto.Type
Text/ProtocolBuffers/WireMessage.hs view
@@ -15,7 +15,8 @@ ( -- * User API functions -- ** Main encoding and decoding operations (non-delimited message encoding) messageSize,messagePut,messageGet,messagePutM,messageGetM- -- ** The author's home brewed encoding (length written first to delimit message)+ -- ** These should agree with the length delimited message format of protobuf-2.10, where the+ -- message size preceeds the data. , messageWithLengthSize,messageWithLengthPut,messageWithLengthGet,messageWithLengthPutM,messageWithLengthGetM -- ** Encoding to write or read a single message field (good for delimited messages or incremental use) , messageAsFieldSize,messageAsFieldPutM,messageAsFieldGetM@@ -24,12 +25,12 @@ -- * The Wire monad itself. Users should beware that passing an incompatible 'FieldType' is a runtime error or fail , Wire(..) -- * The internal exports, for use by generated code and the "Text.ProtcolBuffer.Extensions" module- , size'Varint,toWireType,toWireTag,mkWireTag+ , size'Varint,toWireType,toWireTag,toPackedWireTag,mkWireTag , prependMessageSize,putSize,putVarUInt,getVarInt,putLazyByteString,splitWireTag- , wireSizeReq,wireSizeOpt,wireSizeRep- , wirePutReq,wirePutOpt,wirePutRep+ , wireSizeReq,wireSizeOpt,wireSizeRep,wireSizePacked+ , wirePutReq,wirePutOpt,wirePutRep,wirePutPacked , wireSizeErr,wirePutErr,wireGetErr- , getMessageWith,getBareMessageWith,wireGetEnum+ , getMessageWith,getBareMessageWith,wireGetEnum,wireGetPackedEnum , unknownField,unknown,wireGetFromWire , castWord64ToDouble,castWord32ToFloat,castDoubleToWord64,castFloatToWord32 , zzEncode64,zzEncode32,zzDecode64,zzDecode32@@ -44,6 +45,8 @@ import qualified Data.Foldable as F(foldl',forM_) import Data.List (genericLength) import Data.Maybe(fromMaybe)+import Data.Sequence ((|>))+import qualified Data.Sequence as Seq(length,empty) import qualified Data.Set as Set(delete,null) import Data.Typeable (Typeable(..)) -- GHC internals for getting at Double and Float representation as Word64 and Word32@@ -188,57 +191,115 @@ {-# INLINE wirePutReq #-} -- | Used in generated code.-wirePutReq :: Wire b => WireTag -> FieldType -> b -> Put-wirePutReq wireTag 10 b = let startTag = getWireTag wireTag+wirePutReq :: Wire v => WireTag -> FieldType -> v -> Put+wirePutReq wireTag 10 v = let startTag = getWireTag wireTag endTag = succ startTag- in putVarUInt startTag >> wirePut 10 b >> putVarUInt endTag-wirePutReq wireTag fieldType b = putVarUInt (getWireTag wireTag) >> wirePut fieldType b+ in putVarUInt startTag >> wirePut 10 v >> putVarUInt endTag+wirePutReq wireTag fieldType v = putVarUInt (getWireTag wireTag) >> wirePut fieldType v {-# INLINE wirePutOpt #-} -- | Used in generated code.-wirePutOpt :: Wire b => WireTag -> FieldType -> Maybe b -> Put+wirePutOpt :: Wire v => WireTag -> FieldType -> Maybe v -> Put wirePutOpt _wireTag _fieldType Nothing = return ()-wirePutOpt wireTag fieldType (Just b) = wirePutReq wireTag fieldType b +wirePutOpt wireTag fieldType (Just v) = wirePutReq wireTag fieldType v {-# INLINE wirePutRep #-} -- | Used in generated code.-wirePutRep :: Wire b => WireTag -> FieldType -> Seq b -> Put-wirePutRep wireTag fieldType bs = F.forM_ bs (\b -> wirePutReq wireTag fieldType b)+wirePutRep :: Wire v => WireTag -> FieldType -> Seq v -> Put+wirePutRep wireTag fieldType vs = F.forM_ vs (\v -> wirePutReq wireTag fieldType v) +{-# INLINE wirePutPacked #-}+-- | Used in generated code.+wirePutPacked :: Wire v => WireTag -> FieldType -> Seq v -> Put+wirePutPacked wireTag fieldType vs = do+ putVarUInt (getWireTag wireTag)+ let size = F.foldl' (\n v -> n + wireSize fieldType v) 0 vs+ putSize size+ F.forM_ vs (\v -> wirePut fieldType v)+ {-# INLINE wireSizeReq #-} -- | Used in generated code.-wireSizeReq :: Wire b => Int64 -> FieldType -> b -> Int64+wireSizeReq :: Wire v => Int64 -> FieldType -> v -> Int64 wireSizeReq tagSize 10 v = tagSize + wireSize 10 v + tagSize-wireSizeReq tagSize i v = tagSize + wireSize i v+wireSizeReq tagSize fieldType v = tagSize + wireSize fieldType v {-# INLINE wireSizeOpt #-} -- | Used in generated code.-wireSizeOpt :: Wire b => Int64 -> FieldType -> Maybe b -> Int64+wireSizeOpt :: Wire v => Int64 -> FieldType -> Maybe v -> Int64 wireSizeOpt _tagSize _i Nothing = 0 wireSizeOpt tagSize i (Just v) = wireSizeReq tagSize i v {-# INLINE wireSizeRep #-} -- | Used in generated code.-wireSizeRep :: Wire b => Int64 -> FieldType -> Seq b -> Int64-wireSizeRep tagSize i s = F.foldl' (\n v -> n + wireSizeReq tagSize i v) 0 s+wireSizeRep :: Wire v => Int64 -> FieldType -> Seq v -> Int64+wireSizeRep tagSize i vs = F.foldl' (\n v -> n + wireSizeReq tagSize i v) 0 vs +{-# INLINE wireSizePacked #-} -- | Used in generated code.+wireSizePacked :: Wire v => Int64 -> FieldType -> Seq v -> Int64+wireSizePacked tagSize i vs = tagSize + prependMessageSize (F.foldl' (\n v -> n + wireSize i v) 0 vs)++-- | Used in generated code. putSize :: WireSize -> Put putSize = putVarUInt +toPackedWireTag :: FieldId -> WireTag+toPackedWireTag fieldId = mkWireTag fieldId 2 {- packed always uses Length delimited and has wire type of 2 -}+ toWireTag :: FieldId -> FieldType -> WireTag toWireTag fieldId fieldType- = ((fromIntegral . getFieldId $ fieldId) `shiftL` 3) .|. (fromIntegral . getWireType . toWireType $ fieldType)+ = mkWireTag fieldId (toWireType fieldType) mkWireTag :: FieldId -> WireType -> WireTag-mkWireTag fieldId fieldType- = ((fromIntegral . getFieldId $ fieldId) `shiftL` 3) .|. (fromIntegral . getWireType $ fieldType)+mkWireTag fieldId wireType+ = ((fromIntegral . getFieldId $ fieldId) `shiftL` 3) .|. (fromIntegral . getWireType $ wireType) splitWireTag :: WireTag -> (FieldId,WireType) splitWireTag (WireTag wireTag) = ( FieldId . fromIntegral $ wireTag `shiftR` 3 , WireType . fromIntegral $ wireTag .&. 7 ) +{-# INLINE wireGetPackedEnum #-}+wireGetPackedEnum :: (Typeable e,Enum e) => (Int -> Maybe e) -> Get (Seq e)+wireGetPackedEnum toMaybe'Enum = do+ packedLength <- getVarInt+ start <- bytesRead+ let stop = packedLength+start+ next soFar = do+ here <- bytesRead+ case compare stop here of+ EQ -> return soFar+ LT -> tooMuchData packedLength soFar start here+ GT -> do+ value <- wireGetEnum toMaybe'Enum+ next $! soFar |> value+ next Seq.empty+ where+ Just e = undefined `asTypeOf` (toMaybe'Enum undefined)+ tooMuchData packedLength soFar start here =+ throwError ("Text.ProtocolBuffers.WireMessage.wireGetPackedEnum: overran expected length."+ ++ "\n The type and count of values so far is " ++ show (typeOf (undefined `asTypeOf` e),Seq.length soFar)+ ++ "\n at (packedLength,start,here) == " ++ show (packedLength,start,here)) +{-# INLINE genericPacked #-}+genericPacked :: Wire a => FieldType -> Get (Seq a)+genericPacked ft = do+ packedLength <- getVarInt+ start <- bytesRead+ let stop = packedLength+start+ next soFar = do+ here <- bytesRead+ case compare stop here of+ EQ -> return soFar+ LT -> tooMuchData packedLength soFar start here+ GT -> do+ value <- wireGet ft+ next $! soFar |> value+ next Seq.empty+ where+ tooMuchData packedLength soFar start here =+ throwError ("Text.ProtocolBuffers.WireMessage.genericPacked: overran expected length."+ ++ "\n The FieldType and count of values so far are " ++ show (ft,Seq.length soFar)+ ++ "\n at (packedLength,start,here) == " ++ show (packedLength,start,here)) -- getMessageWith assumes the wireTag for the message, if it existed, has already been read. -- getMessageWith assumes that it still needs to read the Varint encoded length of the message.@@ -277,11 +338,11 @@ notEnoughData messageLength start = throwError ("Text.ProtocolBuffers.WireMessage.getMessageWith: Required fields missing when processing " ++ (show . descName . reflectDescriptorInfo $ initialMessage)- ++ " at (messageLength,start) == " ++ show (messageLength,start))+ ++ "\n at (messageLength,start) == " ++ show (messageLength,start)) tooMuchData messageLength start here = throwError ("Text.ProtocolBuffers.WireMessage.getMessageWith: overran expected length when processing" ++ (show . descName . reflectDescriptorInfo $ initialMessage)- ++ " at (messageLength,start,here) == " ++ show (messageLength,start,here))+ ++ "\n at (messageLength,start,here) == " ++ show (messageLength,start,here)) -- | Used by generated code -- getBareMessageWith assumes the wireTag for the message, if it existed, has already been read.@@ -328,8 +389,9 @@ unknown fieldId wireType initialMessage = do here <- bytesRead throwError ("Text.ProtocolBuffers.WireMessage.unknown: Unknown field found or failure parsing field (e.g. unexpected Enum value):"- ++ "(message type name,field id number,wire type code,bytes read) == "- ++ show (typeOf initialMessage,fieldId,wireType,here) ++ " when processing "+ ++ "\n (message type name,field id number,wire type code,bytes read) == "+ ++ show (typeOf initialMessage,fieldId,wireType,here)+ ++ "\n when processing " ++ (show . descName . reflectDescriptorInfo $ initialMessage)) {-# INLINE castWord32ToFloat #-}@@ -372,6 +434,8 @@ wirePut ft x = wirePutErr ft x wireGet {- TYPE_DOUBLE -} 1 = fmap castWord64ToDouble getWord64le wireGet ft = wireGetErr ft+ wireGetPacked 1 = genericPacked 1+ wireGetPacked ft = wireGetErr ft instance Wire Float where wireSize {- TYPE_FLOAT -} 2 _ = 4@@ -380,6 +444,8 @@ wirePut ft x = wirePutErr ft x wireGet {- TYPE_FLOAT -} 2 = fmap castWord32ToFloat getWord32le wireGet ft = wireGetErr ft+ wireGetPacked 2 = genericPacked 2+ wireGetPacked ft = wireGetErr ft instance Wire Int64 where wireSize {- TYPE_INT64 -} 3 x = size'Varint x@@ -394,6 +460,10 @@ wireGet {- TYPE_SINT64 -} 18 = fmap zzDecode64 getVarInt wireGet {- TYPE_SFIXED64 -} 16 = fmap fromIntegral getWord64le wireGet ft = wireGetErr ft+ wireGetPacked 3 = genericPacked 3+ wireGetPacked 18 = genericPacked 18+ wireGetPacked 16 = genericPacked 16+ wireGetPacked ft = wireGetErr ft instance Wire Int32 where wireSize {- TYPE_INT32 -} 5 x = size'Varint x@@ -408,6 +478,10 @@ wireGet {- TYPE_SINT32 -} 17 = fmap zzDecode32 getVarInt wireGet {- TYPE_SFIXED32 -} 15 = fmap fromIntegral getWord32le wireGet ft = wireGetErr ft+ wireGetPacked 5 = genericPacked 5+ wireGetPacked 17 = genericPacked 17+ wireGetPacked 15 = genericPacked 15+ wireGetPacked ft = wireGetErr ft instance Wire Word64 where wireSize {- TYPE_UINT64 -} 4 x = size'Varint x@@ -419,6 +493,9 @@ wireGet {- TYPE_FIXED64 -} 6 = getWord64le wireGet {- TYPE_UINT64 -} 4 = getVarInt wireGet ft = wireGetErr ft+ wireGetPacked 6 = genericPacked 6+ wireGetPacked 4 = genericPacked 4+ wireGetPacked ft = wireGetErr ft instance Wire Word32 where wireSize {- TYPE_UINT32 -} 13 x = size'Varint x@@ -430,6 +507,9 @@ wireGet {- TYPE_UINT32 -} 13 = getVarInt wireGet {- TYPE_FIXED32 -} 7 = getWord32le wireGet ft = wireGetErr ft+ wireGetPacked 13 = genericPacked 13+ wireGetPacked 7 = genericPacked 7+ wireGetPacked ft = wireGetErr ft instance Wire Bool where wireSize {- TYPE_BOOL -} 8 _ = 1@@ -444,6 +524,8 @@ x' | x' < 128 -> return True _ -> throwError ("TYPE_BOOL read failure : " ++ show x) wireGet ft = wireGetErr ft+ wireGetPacked 8 = genericPacked 8+ wireGetPacked ft = wireGetErr ft instance Wire Utf8 where -- items of TYPE_STRING is already in a UTF8 encoded Data.ByteString.Lazy@@ -471,6 +553,8 @@ wirePut ft x = wirePutErr ft x wireGet {- TYPE_ENUM -} 14 = getVarInt wireGet ft = wireGetErr ft+ wireGetPacked 14 = genericPacked 14 -- Should actually be used, see wireGetPackedEnum+ wireGetPacked ft = wireGetErr ft {-# INLINE verifyUtf8 #-} verifyUtf8 :: ByteString -> Get Utf8@@ -481,7 +565,7 @@ {-# INLINE wireGetEnum #-} wireGetEnum :: (Typeable e, Enum e) => (Int -> Maybe e) -> Get e wireGetEnum toMaybe'Enum = do- int <- wireGet 14+ int <- wireGet 14 -- uses the "instance Wire Int" defined above case toMaybe'Enum int of Just v -> return v Nothing -> throwError (msg ++ show int)
− google/protobuf/unittest.proto
@@ -1,452 +0,0 @@-// Protocol Buffers - Google's data interchange format-// Copyright 2008 Google Inc.-// http://code.google.com/p/protobuf/-//-// Licensed under the Apache License, Version 2.0 (the "License");-// you may not use this file except in compliance with the License.-// You may obtain a copy of the License at-//-// http://www.apache.org/licenses/LICENSE-2.0-//-// Unless required by applicable law or agreed to in writing, software-// distributed under the License is distributed on an "AS IS" BASIS,-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-// See the License for the specific language governing permissions and-// limitations under the License.--// Author: kenton@google.com (Kenton Varda)-// Based on original Protocol Buffers design by-// Sanjay Ghemawat, Jeff Dean, and others.-//-// A proto file we will use for unit testing.---import "google/protobuf/unittest_import.proto";--// We don't put this in a package within proto2 because we need to make sure-// that the generated code doesn't depend on being in the proto2 namespace.-// In test_util.h we do "using namespace unittest = protobuf_unittest".-package protobuf_unittest;--// Protos optimized for SPEED use a strict superset of the generated code-// of equivalent ones optimized for CODE_SIZE, so we should optimize all our-// tests for speed unless explicitly testing code size optimization.-option optimize_for = SPEED;--option java_outer_classname = "UnittestProto";--// This proto includes every type of field in both singular and repeated-// forms.-message TestAllTypes {- message NestedMessage {- // The field name "b" fails to compile in proto1 because it conflicts with- // a local variable named "b" in one of the generated methods. Doh.- // This file needs to compile in proto1 to test backwards-compatibility.- optional int32 bb = 1;- }-- enum NestedEnum {- FOO = 1;- BAR = 2;- BAZ = 3;- }-- // Singular- optional int32 optional_int32 = 1;- optional int64 optional_int64 = 2;- optional uint32 optional_uint32 = 3;- optional uint64 optional_uint64 = 4;- optional sint32 optional_sint32 = 5;- optional sint64 optional_sint64 = 6;- optional fixed32 optional_fixed32 = 7;- optional fixed64 optional_fixed64 = 8;- optional sfixed32 optional_sfixed32 = 9;- optional sfixed64 optional_sfixed64 = 10;- optional float optional_float = 11;- optional double optional_double = 12;- optional bool optional_bool = 13;- optional string optional_string = 14;- optional bytes optional_bytes = 15;-- optional group OptionalGroup = 16 {- optional int32 a = 17;- }-- optional NestedMessage optional_nested_message = 18;- optional ForeignMessage optional_foreign_message = 19;- optional protobuf_unittest_import.ImportMessage optional_import_message = 20;-- optional NestedEnum optional_nested_enum = 21;- optional ForeignEnum optional_foreign_enum = 22;- optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;-- optional string optional_string_piece = 24 [ctype=STRING_PIECE];- optional string optional_cord = 25 [ctype=CORD];-- // Repeated- repeated int32 repeated_int32 = 31;- repeated int64 repeated_int64 = 32;- repeated uint32 repeated_uint32 = 33;- repeated uint64 repeated_uint64 = 34;- repeated sint32 repeated_sint32 = 35;- repeated sint64 repeated_sint64 = 36;- repeated fixed32 repeated_fixed32 = 37;- repeated fixed64 repeated_fixed64 = 38;- repeated sfixed32 repeated_sfixed32 = 39;- repeated sfixed64 repeated_sfixed64 = 40;- repeated float repeated_float = 41;- repeated double repeated_double = 42;- repeated bool repeated_bool = 43;- repeated string repeated_string = 44;- repeated bytes repeated_bytes = 45;-- repeated group RepeatedGroup = 46 {- optional int32 a = 47;- }-- repeated NestedMessage repeated_nested_message = 48;- repeated ForeignMessage repeated_foreign_message = 49;- repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;-- repeated NestedEnum repeated_nested_enum = 51;- repeated ForeignEnum repeated_foreign_enum = 52;- repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;-- repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];- repeated string repeated_cord = 55 [ctype=CORD];-- // Singular with defaults- optional int32 default_int32 = 61 [default = 41 ];- optional int64 default_int64 = 62 [default = 42 ];- optional uint32 default_uint32 = 63 [default = 43 ];- optional uint64 default_uint64 = 64 [default = 44 ];- optional sint32 default_sint32 = 65 [default = -45 ];- optional sint64 default_sint64 = 66 [default = 46 ];- optional fixed32 default_fixed32 = 67 [default = 47 ];- optional fixed64 default_fixed64 = 68 [default = 48 ];- optional sfixed32 default_sfixed32 = 69 [default = 49 ];- optional sfixed64 default_sfixed64 = 70 [default = -50 ];- optional float default_float = 71 [default = 51.5 ];- optional double default_double = 72 [default = 52e3 ];- optional bool default_bool = 73 [default = true ];- optional string default_string = 74 [default = "hello"];- optional bytes default_bytes = 75 [default = "world"];-- optional NestedEnum default_nested_enum = 81 [default = BAR ];- optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];- optional protobuf_unittest_import.ImportEnum- default_import_enum = 83 [default = IMPORT_BAR];-- optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];- optional string default_cord = 85 [ctype=CORD,default="123"];-}--// Define these after TestAllTypes to make sure the compiler can handle-// that.-message ForeignMessage {- optional int32 c = 1;-}--enum ForeignEnum {- FOREIGN_FOO = 4;- FOREIGN_BAR = 5;- FOREIGN_BAZ = 6;-}--message TestAllExtensions {- extensions 1 to max;-}--extend TestAllExtensions {- // Singular- optional int32 optional_int32_extension = 1;- optional int64 optional_int64_extension = 2;- optional uint32 optional_uint32_extension = 3;- optional uint64 optional_uint64_extension = 4;- optional sint32 optional_sint32_extension = 5;- optional sint64 optional_sint64_extension = 6;- optional fixed32 optional_fixed32_extension = 7;- optional fixed64 optional_fixed64_extension = 8;- optional sfixed32 optional_sfixed32_extension = 9;- optional sfixed64 optional_sfixed64_extension = 10;- optional float optional_float_extension = 11;- optional double optional_double_extension = 12;- optional bool optional_bool_extension = 13;- optional string optional_string_extension = 14;- optional bytes optional_bytes_extension = 15;-- optional group OptionalGroup_extension = 16 {- optional int32 a = 17;- }-- optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;- optional ForeignMessage optional_foreign_message_extension = 19;- optional protobuf_unittest_import.ImportMessage- optional_import_message_extension = 20;-- optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;- optional ForeignEnum optional_foreign_enum_extension = 22;- optional protobuf_unittest_import.ImportEnum- optional_import_enum_extension = 23;-- optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];- optional string optional_cord_extension = 25 [ctype=CORD];-- // Repeated- repeated int32 repeated_int32_extension = 31;- repeated int64 repeated_int64_extension = 32;- repeated uint32 repeated_uint32_extension = 33;- repeated uint64 repeated_uint64_extension = 34;- repeated sint32 repeated_sint32_extension = 35;- repeated sint64 repeated_sint64_extension = 36;- repeated fixed32 repeated_fixed32_extension = 37;- repeated fixed64 repeated_fixed64_extension = 38;- repeated sfixed32 repeated_sfixed32_extension = 39;- repeated sfixed64 repeated_sfixed64_extension = 40;- repeated float repeated_float_extension = 41;- repeated double repeated_double_extension = 42;- repeated bool repeated_bool_extension = 43;- repeated string repeated_string_extension = 44;- repeated bytes repeated_bytes_extension = 45;-- repeated group RepeatedGroup_extension = 46 {- optional int32 a = 47;- }-- repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;- repeated ForeignMessage repeated_foreign_message_extension = 49;- repeated protobuf_unittest_import.ImportMessage- repeated_import_message_extension = 50;-- repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;- repeated ForeignEnum repeated_foreign_enum_extension = 52;- repeated protobuf_unittest_import.ImportEnum- repeated_import_enum_extension = 53;-- repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];- repeated string repeated_cord_extension = 55 [ctype=CORD];-- // Singular with defaults- optional int32 default_int32_extension = 61 [default = 41 ];- optional int64 default_int64_extension = 62 [default = 42 ];- optional uint32 default_uint32_extension = 63 [default = 43 ];- optional uint64 default_uint64_extension = 64 [default = 44 ];- optional sint32 default_sint32_extension = 65 [default = -45 ];- optional sint64 default_sint64_extension = 66 [default = 46 ];- optional fixed32 default_fixed32_extension = 67 [default = 47 ];- optional fixed64 default_fixed64_extension = 68 [default = 48 ];- optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];- optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];- optional float default_float_extension = 71 [default = 51.5 ];- optional double default_double_extension = 72 [default = 52e3 ];- optional bool default_bool_extension = 73 [default = true ];- optional string default_string_extension = 74 [default = "hello"];- optional bytes default_bytes_extension = 75 [default = "world"];-- optional TestAllTypes.NestedEnum- default_nested_enum_extension = 81 [default = BAR];- optional ForeignEnum- default_foreign_enum_extension = 82 [default = FOREIGN_BAR];- optional protobuf_unittest_import.ImportEnum- default_import_enum_extension = 83 [default = IMPORT_BAR];-- optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,- default="abc"];- optional string default_cord_extension = 85 [ctype=CORD, default="123"];-}--// We have separate messages for testing required fields because it's-// annoying to have to fill in required fields in TestProto in order to-// do anything with it. Note that we don't need to test every type of-// required filed because the code output is basically identical to-// optional fields for all types.-message TestRequired {- required int32 a = 1;- optional int32 dummy2 = 2;- required int32 b = 3;-- extend TestAllExtensions {- optional TestRequired single = 1000;- repeated TestRequired multi = 1001;- }-- // Pad the field count to 32 so that we can test that IsInitialized()- // properly checks multiple elements of has_bits_.- optional int32 dummy4 = 4;- optional int32 dummy5 = 5;- optional int32 dummy6 = 6;- optional int32 dummy7 = 7;- optional int32 dummy8 = 8;- optional int32 dummy9 = 9;- optional int32 dummy10 = 10;- optional int32 dummy11 = 11;- optional int32 dummy12 = 12;- optional int32 dummy13 = 13;- optional int32 dummy14 = 14;- optional int32 dummy15 = 15;- optional int32 dummy16 = 16;- optional int32 dummy17 = 17;- optional int32 dummy18 = 18;- optional int32 dummy19 = 19;- optional int32 dummy20 = 20;- optional int32 dummy21 = 21;- optional int32 dummy22 = 22;- optional int32 dummy23 = 23;- optional int32 dummy24 = 24;- optional int32 dummy25 = 25;- optional int32 dummy26 = 26;- optional int32 dummy27 = 27;- optional int32 dummy28 = 28;- optional int32 dummy29 = 29;- optional int32 dummy30 = 30;- optional int32 dummy31 = 31;- optional int32 dummy32 = 32;-- required int32 c = 33;-}--message TestRequiredForeign {- optional TestRequired optional_message = 1;- repeated TestRequired repeated_message = 2;- optional int32 dummy = 3;-}--// Test that we can use NestedMessage from outside TestAllTypes.-message TestForeignNested {- optional TestAllTypes.NestedMessage foreign_nested = 1;-}--// TestEmptyMessage is used to test unknown field support.-message TestEmptyMessage {-}--// Like above, but declare all field numbers as potential extensions. No-// actual extensions should ever be defined for this type.-message TestEmptyMessageWithExtensions {- extensions 1 to max;-}--// Test that really large tag numbers don't break anything.-message TestReallyLargeTagNumber {- // The largest possible tag number is 2^28 - 1, since the wire format uses- // three bits to communicate wire type.- optional int32 a = 1;- optional int32 bb = 268435455;-}--message TestRecursiveMessage {- optional TestRecursiveMessage a = 1;- optional int32 i = 2;-}--// Test that mutual recursion works.-message TestMutualRecursionA {- optional TestMutualRecursionB bb = 1;-}--message TestMutualRecursionB {- optional TestMutualRecursionA a = 1;- optional int32 optional_int32 = 2;-}--// Test that groups have disjoint field numbers from their siblings and-// parents. This is NOT possible in proto1; only proto2. When outputting-// proto1, the dup fields should be dropped.-message TestDupFieldNumber {- optional int32 a = 1;- optional group Foo = 2 { optional int32 a = 1; }- optional group Bar = 3 { optional int32 a = 1; }-}---// Needed for a Python test.-message TestNestedMessageHasBits {- message NestedMessage {- repeated int32 nestedmessage_repeated_int32 = 1;- repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;- }- optional NestedMessage optional_nested_message = 1;-}---// Test an enum that has multiple values with the same number.-enum TestEnumWithDupValue {- FOO1 = 1;- BAR1 = 2;- BAZ = 3;- FOO2 = 1;- BAR2 = 2;-}--// Test an enum with large, unordered values.-enum TestSparseEnum {- SPARSE_A = 123;- SPARSE_B = 62374;- SPARSE_C = 12589234;-// SPARSE_D = -15;-// SPARSE_E = -53452;- SPARSE_F = 0;- SPARSE_G = 2;-}--// Test message with CamelCase field names. This violates Protocol Buffer-// standard style.-message TestCamelCaseFieldNames {- optional int32 PrimitiveField = 1;- optional string StringField = 2;- optional ForeignEnum EnumField = 3;- optional ForeignMessage MessageField = 4;- optional string StringPieceField = 5 [ctype=STRING_PIECE];- optional string CordField = 6 [ctype=CORD];-- repeated int32 RepeatedPrimitiveField = 7;- repeated string RepeatedStringField = 8;- repeated ForeignEnum RepeatedEnumField = 9;- repeated ForeignMessage RepeatedMessageField = 10;- repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];- repeated string RepeatedCordField = 12 [ctype=CORD];-}---// We list fields out of order, to ensure that we're using field number and not-// field index to determine serialization order.-message TestFieldOrderings {- optional string my_string = 11;- extensions 2 to 10;- optional int64 my_int = 1;- extensions 12 to 100;- optional float my_float = 101;-}---extend TestFieldOrderings {- optional string my_extension_string = 50;- optional int32 my_extension_int = 5;-}---message TestExtremeDefaultValues {- optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];- optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];- optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];- optional int32 small_int32 = 4 [default = -0x7FFFFFFF];- optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];-- // The default value here is UTF-8 for "\u1234". (We could also just type- // the UTF-8 text directly into this text file rather than escape it, but- // lots of people use editors that would be confused by this.)- optional string utf8_string = 6 [default = "\341\210\264"];-}--// Test that RPC services work.-message FooRequest {}-message FooResponse {}--service TestService {- rpc Foo(FooRequest) returns (FooResponse);- rpc Bar(BarRequest) returns (BarResponse);-}---message BarRequest {}-message BarResponse {}
− google/protobuf/unittest_custom_options.proto
@@ -1,271 +0,0 @@-// Protocol Buffers - Google's data interchange format-// Copyright 2008 Google Inc. All rights reserved.-// http://code.google.com/p/protobuf/-//-// Redistribution and use in source and binary forms, with or without-// modification, are permitted provided that the following conditions are-// met:-//-// * Redistributions of source code must retain the above copyright-// notice, this list of conditions and the following disclaimer.-// * Redistributions in binary form must reproduce the above-// copyright notice, this list of conditions and the following disclaimer-// in the documentation and/or other materials provided with the-// distribution.-// * Neither the name of Google Inc. nor the names of its-// contributors may be used to endorse or promote products derived from-// this software without specific prior written permission.-//-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.--// Author: benjy@google.com (Benjy Weinberger)-// Based on original Protocol Buffers design by-// Sanjay Ghemawat, Jeff Dean, and others.-//-// A proto file used to test the "custom options" feature of proto2.---// A custom file option (defined below).-option (file_opt1) = 9876543210;--import "google/protobuf/descriptor.proto";--// We don't put this in a package within proto2 because we need to make sure-// that the generated code doesn't depend on being in the proto2 namespace.-package protobuf_unittest;---// Some simple test custom options of various types.--extend google.protobuf.FileOptions {- optional uint64 file_opt1 = 7736974;-}--extend google.protobuf.MessageOptions {- optional int32 message_opt1 = 7739036;-}--extend google.protobuf.FieldOptions {- optional fixed64 field_opt1 = 7740936;- // This is useful for testing that we correctly register default values for- // extension options.- optional int32 field_opt2 = 7753913 [default=42];-}--extend google.protobuf.EnumOptions {- optional sfixed32 enum_opt1 = 7753576;-}--// TODO(benjy): Test options on enum values when the parser supports them.--extend google.protobuf.ServiceOptions {- optional sint64 service_opt1 = 7887650;-}--enum MethodOpt1 {- METHODOPT1_VAL1 = 1;- METHODOPT1_VAL2 = 2;-}--extend google.protobuf.MethodOptions {- optional MethodOpt1 method_opt1 = 7890860;-}--// A test message with custom options at all possible locations (and also some-// regular options, to make sure they interact nicely).-message TestMessageWithCustomOptions {- option message_set_wire_format = false;-- option (message_opt1) = -56;-- optional string field1 = 1 [ctype=CORD,- (field_opt1)=8765432109];-- enum AnEnum {- option (enum_opt1) = -789;-- ANENUM_VAL1 = 1;- ANENUM_VAL2 = 2;- }-}---// A test RPC service with custom options at all possible locations (and also-// some regular options, to make sure they interact nicely).-message CustomOptionFooRequest {-}--message CustomOptionFooResponse {-}--service TestServiceWithCustomOptions {- option (service_opt1) = -9876543210;-- rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {- option (method_opt1) = METHODOPT1_VAL2;- }-}----// Options of every possible field type, so we can test them all exhaustively.--message DummyMessageContainingEnum {- enum TestEnumType {- TEST_OPTION_ENUM_TYPE1 = 22;- TEST_OPTION_ENUM_TYPE2 = -23;- }-}--message DummyMessageInvalidAsOptionType {-}--extend google.protobuf.MessageOptions {- optional bool bool_opt = 7706090;- optional int32 int32_opt = 7705709;- optional int64 int64_opt = 7705542;- optional uint32 uint32_opt = 7704880;- optional uint64 uint64_opt = 7702367;- optional sint32 sint32_opt = 7701568;- optional sint64 sint64_opt = 7700863;- optional fixed32 fixed32_opt = 7700307;- optional fixed64 fixed64_opt = 7700194;- optional sfixed32 sfixed32_opt = 7698645;- optional sfixed64 sfixed64_opt = 7685475;- optional float float_opt = 7675390;- optional double double_opt = 7673293;- optional string string_opt = 7673285;- optional bytes bytes_opt = 7673238;- optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;- optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;-}--message CustomOptionMinIntegerValues {- option (bool_opt) = false;- option (int32_opt) = -0x80000000;- option (int64_opt) = -0x8000000000000000;- option (uint32_opt) = 0;- option (uint64_opt) = 0;- option (sint32_opt) = -0x80000000;- option (sint64_opt) = -0x8000000000000000;- option (fixed32_opt) = 0;- option (fixed64_opt) = 0;- option (sfixed32_opt) = -0x80000000;- option (sfixed64_opt) = -0x8000000000000000;-}--message CustomOptionMaxIntegerValues {- option (bool_opt) = true;- option (int32_opt) = 0x7FFFFFFF;- option (int64_opt) = 0x7FFFFFFFFFFFFFFF;- option (uint32_opt) = 0xFFFFFFFF;- option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;- option (sint32_opt) = 0x7FFFFFFF;- option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;- option (fixed32_opt) = 0xFFFFFFFF;- option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;- option (sfixed32_opt) = 0x7FFFFFFF;- option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;-}--message CustomOptionOtherValues {- option (int32_opt) = -100; // To test sign-extension.- option (float_opt) = 12.3456789;- option (double_opt) = 1.234567890123456789;- option (string_opt) = "Hello, \"World\"";- option (bytes_opt) = "Hello\0World";- option (enum_opt) = TEST_OPTION_ENUM_TYPE2;-}--message SettingRealsFromPositiveInts {- option (float_opt) = 12;- option (double_opt) = 154;-}--message SettingRealsFromNegativeInts {- option (float_opt) = -12;- option (double_opt) = -154;-}--// Options of complex message types, themselves combined and extended in-// various ways.--message ComplexOptionType1 {- optional int32 foo = 1;-- extensions 100 to max;-}--message ComplexOptionType2 {- optional ComplexOptionType1 bar = 1;- optional int32 baz = 2;-- message ComplexOptionType4 {- optional int32 waldo = 1;-- extend google.protobuf.MessageOptions {- optional ComplexOptionType4 complex_opt4 = 7633546;- }- }-- optional ComplexOptionType4 fred = 3;-- extensions 100 to max;-}--message ComplexOptionType3 {- optional int32 qux = 1;-- optional group ComplexOptionType5 = 2 {- optional int32 plugh = 3;- }-}--extend ComplexOptionType1 {- optional int32 quux = 7663707;- optional ComplexOptionType3 corge = 7663442;-}--extend ComplexOptionType2 {- optional int32 grault = 7650927;- optional ComplexOptionType1 garply = 7649992;-}--extend google.protobuf.MessageOptions {- optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;- optional ComplexOptionType2 complex_opt2 = 7636949;- optional ComplexOptionType3 complex_opt3 = 7636463;- optional group ComplexOpt6 = 7595468 {- optional int32 xyzzy = 7593951;- }-}--// Note that we try various different ways of naming the same extension.-message VariousComplexOptions {- option (.protobuf_unittest.complex_opt1).foo = 42;- option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;- option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;- option (complex_opt2).baz = 987;- option (complex_opt2).(grault) = 654;- option (complex_opt2).bar.foo = 743;- option (complex_opt2).bar.(quux) = 1999;- option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;- option (complex_opt2).(garply).foo = 741;- option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;- option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;- option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;- option (complex_opt2).fred.waldo = 321;- option (protobuf_unittest.complex_opt3).qux = 9;- option (complex_opt3).complexoptiontype5.plugh = 22;- option (complexopt6).xyzzy = 24;-}
− google/protobuf/unittest_import.proto
@@ -1,47 +0,0 @@-// Protocol Buffers - Google's data interchange format-// Copyright 2008 Google Inc.-// http://code.google.com/p/protobuf/-//-// Licensed under the Apache License, Version 2.0 (the "License");-// you may not use this file except in compliance with the License.-// You may obtain a copy of the License at-//-// http://www.apache.org/licenses/LICENSE-2.0-//-// Unless required by applicable law or agreed to in writing, software-// distributed under the License is distributed on an "AS IS" BASIS,-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-// See the License for the specific language governing permissions and-// limitations under the License.--// Author: kenton@google.com (Kenton Varda)-// Based on original Protocol Buffers design by-// Sanjay Ghemawat, Jeff Dean, and others.-//-// A proto file which is imported by unittest.proto to test importing.---// We don't put this in a package within proto2 because we need to make sure-// that the generated code doesn't depend on being in the proto2 namespace.-// In test_util.h we do-// "using namespace unittest_import = protobuf_unittest_import".-package protobuf_unittest_import;--option optimize_for = SPEED;--// Excercise the java_package option.-option java_package = "com.google.protobuf.test";--// Do not set a java_outer_classname here to verify that Proto2 works without-// one.--message ImportMessage {- optional int32 d = 1;-}--enum ImportEnum {- IMPORT_FOO = 7;- IMPORT_BAR = 8;- IMPORT_BAZ = 9;-}-
protocol-buffers.cabal view
@@ -1,5 +1,5 @@ name: protocol-buffers-version: 1.4.0+version: 1.5.0 cabal-version: >= 1.6 build-type: Simple license: BSD3@@ -18,9 +18,6 @@ extra-source-files: Setup.hs TODO README- google/protobuf/unittest.proto- google/protobuf/unittest_import.proto- google/protobuf/unittest_custom_options.proto -- extra-tmp-files: flag small_base