packages feed

wireform-proto-0.2.0.0: src/Proto/Google/Protobuf/Any.hs

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
{-# OPTIONS_GHC -Wno-unused-imports -Wno-unused-matches -Wno-unused-top-binds #-}

{- | Auto-generated protobuf types from package @google.protobuf@.

__THIS FILE IS AUTO-GENERATED BY wireform. DO NOT EDIT.__

Any manual changes will be overwritten the next time code
generation is run.  To modify the types or instances, edit the
@.proto@ source file and re-run the code generator.
-}
module Proto.Google.Protobuf.Any where

import Control.DeepSeq (NFData (..))
import Data.Aeson qualified as Aeson
import Data.Aeson.Key qualified as AesonKey
import Data.Aeson.KeyMap qualified as AesonKM
import Data.Aeson.Types qualified as Aeson
import Data.ByteString (ByteString)
import Data.ByteString qualified as BS
import Data.Hashable (Hashable (..))
import Data.Int (Int32, Int64)
import Data.Map.Strict qualified as Map
import Data.Proxy (Proxy (..))
import Data.Reflection (Given (..), given)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Vector qualified as V
import Data.Vector.Unboxed qualified as VU
import Data.Word (Word32, Word64)
import GHC.Generics (Generic)
import Proto.Decode
import Proto.Encode
import Proto.Extension qualified
import Proto.Internal.Encode.Archetype (
  archBool,
  archBoolSize,
  archBytes,
  archBytesSize,
  archDouble,
  archFixed32,
  archFixed32Size,
  archFixed64,
  archFixed64Size,
  archFloat,
  archSVarint32,
  archSVarint64,
  archString,
  archStringSize,
  archSubmessage,
  archSubmessageSize,
  archVarint,
  archVarintSize,
 )
import Proto.Internal.JSON (bytesFieldToJSON, bytesMapFieldToJSON, jsonObject, parseBytesFieldMaybe, parseBytesMapFieldMaybe, parseFieldMaybe, protoBytesToJSON, (.=:))
import Proto.Internal.JSON.Extension qualified as PJExt
import Proto.Internal.Wire (Tag (..), WireType (..))
import Proto.Internal.Wire.Encode (
  fieldBoolSize,
  fieldBytesSize,
  fieldDoubleSize,
  fieldFixed32Size,
  fieldFixed64Size,
  fieldFloatSize,
  fieldMessageSize,
  fieldSVarint32Size,
  fieldSVarint64Size,
  fieldTextSize,
  fieldVarintSize,
  putByteString,
  putDouble,
  putFixed32,
  putFixed64,
  putFloat,
  putLengthDelimited,
  putSVarint32,
  putSVarint64,
  putTag,
  putText,
  putVarint,
  putVarintSigned,
  tagSize,
  varintSize,
  varintSize32,
  zigZag32,
  zigZag64,
 )
import Proto.Registry (IsMessage)
import Proto.Registry qualified
import Proto.Schema (FieldDescriptor (..), FieldLabel' (..), FieldTypeDescriptor (..), ProtoMessage (..), ScalarFieldType (..), SomeFieldDescriptor (..))
import Wireform.Builder qualified as B


{- | Serialized FileDescriptorProto for this .proto file.
Decode with @Proto.Google.Protobuf.Descriptor.decodeMessage@.
-}
fileDescriptorProtoBytes :: ByteString
fileDescriptorProtoBytes = "\x0a\x19\x67\x6f\x6f\x67\x6c\x65\x2f\x70\x72\x6f\x74\x6f\x62\x75\x66\x2f\x61\x6e\x79\x2e\x70\x72\x6f\x74\x6f\x12\x0f\x67\x6f\x6f\x67\x6c\x65\x2e\x70\x72\x6f\x74\x6f\x62\x75\x66\x22\x26\x0a\x03\x41\x6e\x79\x12\x10\x0a\x08\x74\x79\x70\x65\x5f\x75\x72\x6c\x18\x01\x20\x01\x28\x09\x12\x0d\x0a\x05\x76\x61\x6c\x75\x65\x18\x02\x20\x01\x28\x0c\x62\x06\x70\x72\x6f\x74\x6f\x33"


data Any = Any
  { anyTypeUrl :: !Text
  , anyValue :: !ByteString
  , anyUnknownFields :: ![UnknownField]
  }
  deriving stock (Show, Eq, Generic)
  deriving anyclass (NFData)


defaultAny :: Any
defaultAny =
  Any
    { anyTypeUrl = ""
    , anyValue = ""
    , anyUnknownFields = []
    }


instance MessageEncode Any where
  buildMessage msg =
    (if msg.anyTypeUrl == T.empty then mempty else archString 10 msg.anyTypeUrl)
      <> (if BS.null msg.anyValue then mempty else archBytes 18 msg.anyValue)
      <> encodeUnknownFields msg.anyUnknownFields


instance MessageSize Any where
  messageSize msg =
    (if msg.anyTypeUrl == T.empty then 0 else archStringSize msg.anyTypeUrl)
      + (if BS.null msg.anyValue then 0 else archBytesSize msg.anyValue)
      + unknownFieldsSize msg.anyUnknownFields


instance MessageDecode Any where
  {-# INLINE messageDecoder #-}
  messageDecoder = loop "" "" []
    where
      loop acc_0 acc_1 acc_unknown_ =
        withTagM
          (pure (Any {anyTypeUrl = acc_0, anyValue = acc_1, anyUnknownFields = reverse acc_unknown_}))
          ( \fn wt -> case fn of
              1 -> do
                v <- decodeFieldString
                loop v acc_1 acc_unknown_
              2 -> do
                v <- decodeFieldBytes
                loop acc_0 v acc_unknown_
              _ -> do
                uf <- captureUnknownField fn (toEnum wt)
                loop acc_0 acc_1 (uf : acc_unknown_)
          )


instance ProtoMessage Any where
  protoMessageName _ = "google.protobuf.Any"
  protoPackageName _ = "google.protobuf"
  protoDefaultValue = defaultAny
  protoFileDescriptorBytes _ = fileDescriptorProtoBytes
  protoFieldDescriptors _ =
    Map.fromList
      [
        ( 1
        , SomeField
            FieldDescriptor
              { fdName = "type_url"
              , fdNumber = 1
              , fdTypeDesc = ScalarType StringField
              , fdLabel = LabelOptional
              , fdGet = anyTypeUrl
              , fdSet = \v m -> m {anyTypeUrl = v}
              }
        )
      ,
        ( 2
        , SomeField
            FieldDescriptor
              { fdName = "value"
              , fdNumber = 2
              , fdTypeDesc = ScalarType BytesField
              , fdLabel = LabelOptional
              , fdGet = anyValue
              , fdSet = \v m -> m {anyValue = v}
              }
        )
      ]


instance IsMessage Any


instance Aeson.ToJSON Any where
  toJSON msg =
    jsonObject
      [ "typeUrl" .=: msg.anyTypeUrl
      , bytesFieldToJSON "value" msg.anyValue
      ]


instance Aeson.FromJSON Any where
  parseJSON = Aeson.withObject "Any" $ \obj -> do
    fld_anyTypeUrl <- parseFieldMaybe obj "typeUrl"
    fld_anyValue <- parseBytesFieldMaybe obj "value"
    pure
      defaultAny
        { anyTypeUrl = maybe (anyTypeUrl defaultAny) id fld_anyTypeUrl
        , anyValue = maybe (anyValue defaultAny) id fld_anyValue
        , anyUnknownFields = []
        }


instance Hashable Any where
  hashWithSalt salt msg = hashWithSalt (hashWithSalt (salt) msg.anyTypeUrl) msg.anyValue


instance Proto.Extension.HasExtensions Any where
  messageUnknownFields = anyUnknownFields
  setMessageUnknownFields !ufs msg = msg {anyUnknownFields = ufs}


instance Semigroup Any where
  a <> b =
    Any
      { anyTypeUrl = if b.anyTypeUrl == "" then a.anyTypeUrl else b.anyTypeUrl
      , anyValue = if b.anyValue == "" then a.anyValue else b.anyValue
      , anyUnknownFields = a.anyUnknownFields <> b.anyUnknownFields
      }


instance Monoid Any where
  mempty = defaultAny