mirror of
https://github.com/github/semantic.git
synced 2025-01-05 05:58:34 +03:00
Merge branch 'master' into signal-handling
This commit is contained in:
commit
bc4dce9725
@ -1,15 +1,63 @@
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
|
||||
module Proto3.Google.Timestamp (Timestamp (..)) where
|
||||
|
||||
import Prologue
|
||||
|
||||
import Data.Aeson
|
||||
import Proto3.Suite
|
||||
|
||||
-- Code generated by protoc-gen-haskell 0.1.0, DO NOT EDIT.
|
||||
{-# LANGUAGE DerivingVia, DeriveAnyClass, DuplicateRecordFields #-}
|
||||
{-# OPTIONS_GHC -Wno-unused-imports -Wno-missing-export-lists #-}
|
||||
-- | Predefined timestamp message provided by Google. The schema can be found
|
||||
-- <https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto here>.
|
||||
module Proto3.Google.Timestamp (Timestamp (..)) where
|
||||
|
||||
import Control.DeepSeq
|
||||
import Control.Monad (msum)
|
||||
import qualified Data.Aeson as A
|
||||
import qualified Data.Aeson.Encoding as E
|
||||
import Data.ByteString (ByteString)
|
||||
import Data.Int
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Vector (Vector)
|
||||
import Data.Word
|
||||
import GHC.Generics
|
||||
import Proto3.Suite (decodeMessageField, encodeMessageField, nestedvec, packedvec)
|
||||
import qualified Proto3.Suite as Proto3
|
||||
import Proto3.Suite.JSONPB as JSONPB
|
||||
import Proto3.Wire (at, oneof)
|
||||
|
||||
data Timestamp = Timestamp
|
||||
{ timestampSeconds :: Int64
|
||||
, timestampNanos :: Int32
|
||||
} deriving (Eq, Ord, Show, Generic, Message, Named, NFData, FromJSON, ToJSON)
|
||||
{ seconds :: Int64
|
||||
, nanos :: Int32
|
||||
} deriving stock (Eq, Ord, Show, Generic)
|
||||
deriving anyclass (Proto3.Named, NFData)
|
||||
|
||||
instance FromJSONPB Timestamp where
|
||||
parseJSONPB = A.withObject "Timestamp" $ \obj -> Timestamp
|
||||
<$> obj .: "seconds"
|
||||
<*> obj .: "nanos"
|
||||
|
||||
instance ToJSONPB Timestamp where
|
||||
toJSONPB Timestamp{..} = object
|
||||
[
|
||||
"seconds" .= seconds
|
||||
, "nanos" .= nanos
|
||||
]
|
||||
toEncodingPB Timestamp{..} = pairs
|
||||
[
|
||||
"seconds" .= seconds
|
||||
, "nanos" .= nanos
|
||||
]
|
||||
|
||||
instance FromJSON Timestamp where
|
||||
parseJSON = parseJSONPB
|
||||
|
||||
instance ToJSON Timestamp where
|
||||
toJSON = toAesonValue
|
||||
toEncoding = toAesonEncoding
|
||||
|
||||
instance Proto3.Message Timestamp where
|
||||
encodeMessage _ Timestamp{..} = mconcat
|
||||
[
|
||||
encodeMessageField 1 seconds
|
||||
, encodeMessageField 2 nanos
|
||||
]
|
||||
decodeMessage _ = Timestamp
|
||||
<$> at decodeMessageField 1
|
||||
<*> at decodeMessageField 2
|
||||
dotProto = undefined
|
||||
|
@ -6,7 +6,10 @@ module Proto3.Google.Wrapped
|
||||
|
||||
import Prologue
|
||||
|
||||
import qualified Data.Aeson as A
|
||||
|
||||
import Proto3.Suite
|
||||
import Proto3.Suite.JSONPB as JSONPB
|
||||
|
||||
-- | Because protobuf primitive types (string, int32, etc.) are not nullable, Google provides a set of standard
|
||||
-- <https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto wrappers>
|
||||
@ -16,6 +19,27 @@ import Proto3.Suite
|
||||
newtype Wrapped a = Wrapped { value :: a }
|
||||
deriving (Eq, Show, Ord, Generic, NFData)
|
||||
|
||||
instance (HasDefault a, FromJSONPB a) => FromJSONPB (Wrapped a) where
|
||||
parseJSONPB = A.withObject "Value" $ \obj -> Wrapped
|
||||
<$> obj .: "value"
|
||||
|
||||
instance (HasDefault a, ToJSONPB a) => ToJSONPB (Wrapped a) where
|
||||
toJSONPB Wrapped{..} = object
|
||||
[
|
||||
"value" .= value
|
||||
]
|
||||
toEncodingPB Wrapped{..} = pairs
|
||||
[
|
||||
"value" .= value
|
||||
]
|
||||
|
||||
instance (HasDefault a, FromJSONPB a) => FromJSON (Wrapped a) where
|
||||
parseJSON = parseJSONPB
|
||||
|
||||
instance (HasDefault a, ToJSONPB a) => ToJSON (Wrapped a) where
|
||||
toJSON = toAesonValue
|
||||
toEncoding = toAesonEncoding
|
||||
|
||||
instance Named (Wrapped Text) where nameOf _ = "StringValue"
|
||||
instance Named (Wrapped ByteString) where nameOf _ = "BytesValue"
|
||||
instance Named (Wrapped Double) where nameOf _ = "DoubleValue"
|
||||
|
Loading…
Reference in New Issue
Block a user