Commits

Bryan O'Sullivan committed 3c0b4c3

Implement listBuckets and listKeys.

Comments (0)

Files changed (6)

     Network.Riakextra.RpbGetClientIdReq
     Network.Riakextra.RpbSetClientIdResp
     Network.Riakextra.RpbGetServerInfoReq
+    Network.Riakextra.RpbListBucketsReq
   
   build-depends:       
     base == 4.*,

src/Network/Riak.hs

     , get
     , Network.Riak.put
     , delete
+    , listBuckets
+    , listKeys
     ) where
 
 import qualified Data.ByteString.Char8 as B
 import Network.Riakclient.RpbPutResp
 import Network.Riakclient.RpbDelReq
 import Network.Riakclient.RpbGetServerInfoResp
+import Network.Riakclient.RpbListBucketsResp
+import Network.Riakclient.RpbListKeysReq
+import Network.Riakclient.RpbListKeysResp
 import Network.Riakextra.RpbPingReq
 import Network.Riakextra.RpbGetClientIdReq
 import Network.Riakextra.RpbGetServerInfoReq
+import Network.Riakextra.RpbListBucketsReq
 import qualified Data.ByteString.Lazy.Char8 as L
 import Numeric (showHex)
 import System.Random
 delete conn bucket key rw = do
   sendRequest conn $ RpbDelReq bucket key (fromQuorum <$> rw)
   recvResponse_ conn DelResp
+
+listBuckets :: Connection -> IO (Seq T.Bucket)
+listBuckets conn = do
+  sendRequest conn $ RpbListBucketsReq
+  buckets <$> recvResponse conn
+
+listKeys :: Connection -> T.Bucket -> IO (Seq T.Key, Maybe Bool)
+listKeys conn bucket = do
+  sendRequest conn $ RpbListKeysReq bucket
+  RpbListKeysResp{..} <- recvResponse conn
+  return (keys, done)

src/Network/Riak/Message/Tag.hs

 import Network.Riakclient.RpbPutReq
 import Network.Riakclient.RpbPutResp
 import Network.Riakclient.RpbDelReq
+import Network.Riakclient.RpbListKeysResp
 import Network.Riakclient.RpbGetClientIdResp
 import Network.Riakclient.RpbGetServerInfoResp
 import Network.Riakextra.RpbSetClientIdResp
 import Network.Riakextra.RpbGetServerInfoReq
 import Network.Riakclient.RpbListKeysReq
 import Network.Riakclient.RpbGetBucketReq
+import Network.Riakclient.RpbGetBucketResp
 import Network.Riakclient.RpbSetBucketReq
+import Network.Riakclient.RpbListBucketsResp
 import Network.Riakclient.RpbMapRedReq
 import Network.Riakextra.RpbPingReq
 import Network.Riakextra.RpbGetClientIdReq
+import Network.Riakextra.RpbListBucketsReq
 import Text.ProtocolBuffers
 import Text.ProtocolBuffers.Get
 import Network.Riak.Types.Internal as Types
 
 instance Request RpbDelReq
 
+instance Tagged RpbListBucketsReq where
+    messageTag _ = ListBucketsReq
+    {-# INLINE messageTag #-}
+
+instance Request RpbListBucketsReq
+
+instance Tagged RpbListBucketsResp where
+    messageTag _ = ListBucketsResp
+    {-# INLINE messageTag #-}
+
+instance Response RpbListBucketsResp
+
 instance Tagged RpbListKeysReq where
     messageTag _ = ListKeysReq
     {-# INLINE messageTag #-}
 
 instance Request RpbListKeysReq
 
+instance Tagged RpbListKeysResp where
+    messageTag _ = ListKeysResp
+    {-# INLINE messageTag #-}
+
+instance Response RpbListKeysResp
+
 instance Tagged RpbGetBucketReq where
     messageTag _ = GetBucketReq
     {-# INLINE messageTag #-}
 
 instance Request RpbGetBucketReq
 
+instance Tagged RpbGetBucketResp where
+    messageTag _ = GetBucketResp
+    {-# INLINE messageTag #-}
+
+instance Response RpbGetBucketResp
+
 instance Tagged RpbSetBucketReq where
     messageTag _ = SetBucketReq
     {-# INLINE messageTag #-}

src/Network/Riakextra.hs

 protoInfo :: ProtoInfo
 protoInfo
  = P'.read
-    "ProtoInfo {protoMod = ProtoName {protobufName = FIName \".Riakextra\", haskellPrefix = [MName \"Network\"], parentModule = [], baseName = MName \"Riakextra\"}, protoFilePath = [\"Network\",\"Riakextra.hs\"], protoSource = \"riakextra.proto\", extensionKeys = fromList [], messages = [DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbPingReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbPingReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbPingReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbPingResp\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbPingResp\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbPingResp.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbGetClientIdReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbGetClientIdReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbGetClientIdReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbSetClientIdResp\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbSetClientIdResp\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbSetClientIdResp.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbGetServerInfoReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbGetServerInfoReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbGetServerInfoReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False}], enums = [], knownKeyMap = fromList []}"
+    "ProtoInfo {protoMod = ProtoName {protobufName = FIName \".Riakextra\", haskellPrefix = [MName \"Network\"], parentModule = [], baseName = MName \"Riakextra\"}, protoFilePath = [\"Network\",\"Riakextra.hs\"], protoSource = \"riakextra.proto\", extensionKeys = fromList [], messages = [DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbPingReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbPingReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbPingReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbPingResp\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbPingResp\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbPingResp.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbGetClientIdReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbGetClientIdReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbGetClientIdReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbSetClientIdResp\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbSetClientIdResp\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbSetClientIdResp.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbGetServerInfoReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbGetServerInfoReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbGetServerInfoReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False},DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbListBucketsReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbListBucketsReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbListBucketsReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False}], enums = [], knownKeyMap = fromList []}"
  
 fileDescriptorProto :: FileDescriptorProto
 fileDescriptorProto
  = P'.getFromBS (P'.wireGet 11)
     (P'.pack
-      "p\n\SIriakextra.proto\"\f\n\nRpbPingReq\"\r\n\vRpbPingResp\"\DC3\n\DC1RpbGetClientIdReq\"\DC4\n\DC2RpbSetClientIdResp\"\NAK\n\DC3RpbGetServerInfoReq")
+      "\133\SOH\n\SIriakextra.proto\"\f\n\nRpbPingReq\"\r\n\vRpbPingResp\"\DC3\n\DC1RpbGetClientIdReq\"\DC4\n\DC2RpbSetClientIdResp\"\NAK\n\DC3RpbGetServerInfoReq\"\DC3\n\DC1RpbListBucketsReq")

src/Network/Riakextra/RpbListBucketsReq.hs

+module Network.Riakextra.RpbListBucketsReq (RpbListBucketsReq(..)) where
+import Prelude ((+))
+import qualified Prelude as P'
+import qualified Text.ProtocolBuffers.Header as P'
+ 
+data RpbListBucketsReq = RpbListBucketsReq{}
+                       deriving (P'.Show, P'.Eq, P'.Ord, P'.Typeable)
+ 
+instance P'.Mergeable RpbListBucketsReq where
+  mergeEmpty = RpbListBucketsReq
+  mergeAppend (RpbListBucketsReq) (RpbListBucketsReq) = RpbListBucketsReq
+ 
+instance P'.Default RpbListBucketsReq where
+  defaultValue = RpbListBucketsReq
+ 
+instance P'.Wire RpbListBucketsReq where
+  wireSize ft' self'@(RpbListBucketsReq)
+   = case ft' of
+       10 -> calc'Size
+       11 -> P'.prependMessageSize calc'Size
+       _ -> P'.wireSizeErr ft' self'
+    where
+        calc'Size = 0
+  wirePut ft' self'@(RpbListBucketsReq)
+   = case ft' of
+       10 -> put'Fields
+       11 -> do
+               P'.putSize (P'.wireSize 10 self')
+               put'Fields
+       _ -> P'.wirePutErr ft' self'
+    where
+        put'Fields
+         = do
+             P'.return ()
+  wireGet ft'
+   = case ft' of
+       10 -> P'.getBareMessageWith update'Self
+       11 -> P'.getMessageWith update'Self
+       _ -> P'.wireGetErr ft'
+    where
+        update'Self wire'Tag old'Self
+         = case wire'Tag of
+             _ -> let (field'Number, wire'Type) = P'.splitWireTag wire'Tag in P'.unknown field'Number wire'Type old'Self
+ 
+instance P'.MessageAPI msg' (msg' -> RpbListBucketsReq) RpbListBucketsReq where
+  getVal m' f' = f' m'
+ 
+instance P'.GPB RpbListBucketsReq
+ 
+instance P'.ReflectDescriptor RpbListBucketsReq where
+  getMessageInfo _ = P'.GetMessageInfo (P'.fromDistinctAscList []) (P'.fromDistinctAscList [])
+  reflectDescriptorInfo _
+   = P'.read
+      "DescriptorInfo {descName = ProtoName {protobufName = FIName \".Riakextra.RpbListBucketsReq\", haskellPrefix = [MName \"Network\"], parentModule = [MName \"Riakextra\"], baseName = MName \"RpbListBucketsReq\"}, descFilePath = [\"Network\",\"Riakextra\",\"RpbListBucketsReq.hs\"], isGroup = False, fields = fromList [], keys = fromList [], extRanges = [], knownKeys = fromList [], storeUnknown = False}"

src/riakextra.proto

 message RpbGetClientIdReq { }
 message RpbSetClientIdResp { }
 message RpbGetServerInfoReq { }
+message RpbListBucketsReq { }