packages feed

wireform-proto-0.2.0.0: src/Proto/Google/Protobuf/Struct.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.Struct 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\x1c\x67\x6f\x6f\x67\x6c\x65\x2f\x70\x72\x6f\x74\x6f\x62\x75\x66\x2f\x73\x74\x72\x75\x63\x74\x2e\x70\x72\x6f\x74\x6f\x12\x0f\x67\x6f\x6f\x67\x6c\x65\x2e\x70\x72\x6f\x74\x6f\x62\x75\x66\x22\x25\x0a\x06\x53\x74\x72\x75\x63\x74\x12\x1b\x0a\x06\x66\x69\x65\x6c\x64\x73\x18\x01\x20\x03\x28\x0b\x32\x0b\x66\x69\x65\x6c\x64\x73\x45\x6e\x74\x72\x79\x22\xab\x01\x0a\x05\x56\x61\x6c\x75\x65\x12\x1d\x0a\x0a\x6e\x75\x6c\x6c\x5f\x76\x61\x6c\x75\x65\x18\x01\x20\x01\x28\x0b\x32\x09\x4e\x75\x6c\x6c\x56\x61\x6c\x75\x65\x12\x14\x0a\x0c\x6e\x75\x6d\x62\x65\x72\x5f\x76\x61\x6c\x75\x65\x18\x02\x20\x01\x28\x01\x12\x14\x0a\x0c\x73\x74\x72\x69\x6e\x67\x5f\x76\x61\x6c\x75\x65\x18\x03\x20\x01\x28\x09\x12\x12\x0a\x0a\x62\x6f\x6f\x6c\x5f\x76\x61\x6c\x75\x65\x18\x04\x20\x01\x28\x08\x12\x1c\x0a\x0c\x73\x74\x72\x75\x63\x74\x5f\x76\x61\x6c\x75\x65\x18\x05\x20\x01\x28\x0b\x32\x06\x53\x74\x72\x75\x63\x74\x12\x1d\x0a\x0a\x6c\x69\x73\x74\x5f\x76\x61\x6c\x75\x65\x18\x06\x20\x01\x28\x0b\x32\x09\x4c\x69\x73\x74\x56\x61\x6c\x75\x65\x42\x06\x0a\x04\x6b\x69\x6e\x64\x22\x22\x0a\x09\x4c\x69\x73\x74\x56\x61\x6c\x75\x65\x12\x15\x0a\x06\x76\x61\x6c\x75\x65\x73\x18\x01\x20\x03\x28\x0b\x32\x05\x56\x61\x6c\x75\x65\x2a\x19\x0a\x09\x4e\x75\x6c\x6c\x56\x61\x6c\x75\x65\x12\x0c\x0a\x0a\x4e\x55\x4c\x4c\x5f\x56\x41\x4c\x55\x45\x62\x06\x70\x72\x6f\x74\x6f\x33"


data Struct = Struct
  { structFields :: !(Map.Map Text Value)
  , structUnknownFields :: ![UnknownField]
  }
  deriving stock (Show, Eq, Generic)
  deriving anyclass (NFData)


defaultStruct :: Struct
defaultStruct =
  Struct
    { structFields = Map.empty
    , structUnknownFields = []
    }


instance MessageEncode Struct where
  buildMessage msg =
    Map.foldlWithKey' (\acc k v -> acc <> encodeMapField 1 (encodeFieldString 1 k) (encodeFieldMessage 2 v)) mempty msg.structFields
      <> encodeUnknownFields msg.structUnknownFields


instance MessageSize Struct where
  messageSize msg =
    (Map.foldlWithKey' (\acc k v -> let entrySz = fieldTextSize 1 k + fieldMessageSize 2 (messageSize v) in acc + tagSize 1 + varintSize (fromIntegral entrySz) + entrySz) 0 msg.structFields)
      + unknownFieldsSize msg.structUnknownFields


instance MessageDecode Struct where
  {-# INLINE messageDecoder #-}
  messageDecoder = loop Map.empty []
    where
      loop acc_0 acc_unknown_ =
        withTagM
          (pure (Struct {structFields = acc_0, structUnknownFields = reverse acc_unknown_}))
          ( \fn wt -> case fn of
              1 -> do
                bs' <- getLengthDelimited
                let decodeEntry = runDecoder (decodeMapEntry decodeFieldString decodeFieldMessage "" undefined) bs'
                case decodeEntry of
                  Left _ -> loop acc_0 acc_unknown_
                  Right (mk', mv') -> loop (Map.union acc_0 (Map.singleton mk' mv')) acc_unknown_
              _ -> do
                uf <- captureUnknownField fn (toEnum wt)
                loop acc_0 (uf : acc_unknown_)
          )


instance ProtoMessage Struct where
  protoMessageName _ = "google.protobuf.Struct"
  protoPackageName _ = "google.protobuf"
  protoDefaultValue = defaultStruct
  protoFileDescriptorBytes _ = fileDescriptorProtoBytes
  protoFieldDescriptors _ =
    Map.fromList
      [
        ( 1
        , SomeField
            FieldDescriptor
              { fdName = "fields"
              , fdNumber = 1
              , fdTypeDesc = ScalarType BytesField
              , fdLabel = LabelRepeated
              , fdGet = structFields
              , fdSet = \v m -> m {structFields = v}
              }
        )
      ]


instance IsMessage Struct


instance Aeson.ToJSON Struct where
  toJSON msg =
    jsonObject
      [ "fields" .=: msg.structFields
      ]


instance Aeson.FromJSON Struct where
  parseJSON = Aeson.withObject "Struct" $ \obj -> do
    fld_structFields <- parseFieldMaybe obj "fields"
    pure
      defaultStruct
        { structFields = maybe (structFields defaultStruct) id fld_structFields
        , structUnknownFields = []
        }


instance Hashable Struct where
  hashWithSalt salt msg = Map.foldlWithKey' (\s k v -> s `hashWithSalt` k `hashWithSalt` v) (salt) msg.structFields


instance Proto.Extension.HasExtensions Struct where
  messageUnknownFields = structUnknownFields
  setMessageUnknownFields !ufs msg = msg {structUnknownFields = ufs}


instance Semigroup Struct where
  a <> b =
    Struct
      { structFields = a.structFields <> b.structFields
      , structUnknownFields = a.structUnknownFields <> b.structUnknownFields
      }


instance Monoid Struct where
  mempty = defaultStruct


data Value = Value
  { valueKind :: !(Maybe Value'Kind)
  , valueUnknownFields :: ![UnknownField]
  }
  deriving stock (Show, Eq, Generic)
  deriving anyclass (NFData)


data Value'Kind
  = Value'Kind'NullValue !NullValue
  | Value'Kind'NumberValue {-# UNPACK #-} !Double
  | Value'Kind'StringValue !Text
  | Value'Kind'BoolValue {-# UNPACK #-} !Bool
  | Value'Kind'StructValue !Struct
  | Value'Kind'ListValue !ListValue
  deriving stock (Show, Eq, Generic)
  deriving anyclass (NFData)


instance Aeson.ToJSON Value'Kind where
  toJSON _ = Aeson.Null


instance Aeson.FromJSON Value'Kind where
  parseJSON _ = fail "Cannot parse oneof from JSON"


instance Hashable Value'Kind where
  hashWithSalt salt (Value'Kind'NullValue v) = salt `hashWithSalt` (0 :: Int) `hashWithSalt` v
  hashWithSalt salt (Value'Kind'NumberValue v) = salt `hashWithSalt` (1 :: Int) `hashWithSalt` v
  hashWithSalt salt (Value'Kind'StringValue v) = salt `hashWithSalt` (2 :: Int) `hashWithSalt` v
  hashWithSalt salt (Value'Kind'BoolValue v) = salt `hashWithSalt` (3 :: Int) `hashWithSalt` v
  hashWithSalt salt (Value'Kind'StructValue v) = salt `hashWithSalt` (4 :: Int) `hashWithSalt` v
  hashWithSalt salt (Value'Kind'ListValue v) = salt `hashWithSalt` (5 :: Int) `hashWithSalt` v


defaultValue :: Value
defaultValue =
  Value
    { valueKind = Nothing
    , valueUnknownFields = []
    }


instance MessageEncode Value where
  buildMessage msg =
    ( case msg.valueKind of
        Nothing -> mempty
        Just (Value'Kind'NullValue v) -> (let sz = messageSize v in archSubmessage 10 sz (buildMessage v))
        Just (Value'Kind'NumberValue v) -> archDouble 17 v
        Just (Value'Kind'StringValue v) -> archString 26 v
        Just (Value'Kind'BoolValue v) -> archBool 32 v
        Just (Value'Kind'StructValue v) -> (let sz = messageSize v in archSubmessage 42 sz (buildMessage v))
        Just (Value'Kind'ListValue v) -> (let sz = messageSize v in archSubmessage 50 sz (buildMessage v))
    )
      <> encodeUnknownFields msg.valueUnknownFields


instance MessageSize Value where
  messageSize msg =
    ( case msg.valueKind of
        Nothing -> 0
        Just (Value'Kind'NullValue v) -> archSubmessageSize (messageSize v)
        Just (Value'Kind'NumberValue v) -> archFixed64Size
        Just (Value'Kind'StringValue v) -> archStringSize v
        Just (Value'Kind'BoolValue v) -> archBoolSize
        Just (Value'Kind'StructValue v) -> archSubmessageSize (messageSize v)
        Just (Value'Kind'ListValue v) -> archSubmessageSize (messageSize v)
    )
      + unknownFieldsSize msg.valueUnknownFields


instance MessageDecode Value where
  {-# INLINE messageDecoder #-}
  messageDecoder = loop Nothing []
    where
      loop acc_0 acc_unknown_ =
        withTagM
          (pure (Value {valueKind = acc_0, valueUnknownFields = reverse acc_unknown_}))
          ( \fn wt -> case fn of
              1 -> do
                v <- decodeFieldMessage
                loop (Just (Value'Kind'NullValue v)) acc_unknown_
              2 -> do
                v <- decodeFieldDouble
                loop (Just (Value'Kind'NumberValue v)) acc_unknown_
              3 -> do
                v <- decodeFieldString
                loop (Just (Value'Kind'StringValue v)) acc_unknown_
              4 -> do
                v <- decodeFieldBool
                loop (Just (Value'Kind'BoolValue v)) acc_unknown_
              5 -> do
                v <- decodeFieldMessage
                loop (Just (Value'Kind'StructValue v)) acc_unknown_
              6 -> do
                v <- decodeFieldMessage
                loop (Just (Value'Kind'ListValue v)) acc_unknown_
              _ -> do
                uf <- captureUnknownField fn (toEnum wt)
                loop acc_0 (uf : acc_unknown_)
          )


instance ProtoMessage Value where
  protoMessageName _ = "google.protobuf.Value"
  protoPackageName _ = "google.protobuf"
  protoDefaultValue = defaultValue
  protoFileDescriptorBytes _ = fileDescriptorProtoBytes
  protoFieldDescriptors _ =
    Map.fromList
      [
        ( 1
        , SomeField
            FieldDescriptor
              { fdName = "kind"
              , fdNumber = 1
              , fdTypeDesc = MessageType "kind"
              , fdLabel = LabelOptional
              , fdGet = valueKind
              , fdSet = \v m -> m {valueKind = v}
              }
        )
      ]


instance IsMessage Value


instance Aeson.ToJSON Value where
  toJSON msg =
    jsonObject
      [ "kind" .=: msg.valueKind
      ]


instance Aeson.FromJSON Value where
  parseJSON = Aeson.withObject "Value" $ \obj -> do
    fld_valueKind <- parseFieldMaybe obj "kind"
    pure
      defaultValue
        { valueKind = maybe (valueKind defaultValue) id fld_valueKind
        , valueUnknownFields = []
        }


instance Hashable Value where
  hashWithSalt salt msg = hashWithSalt (salt) msg.valueKind


instance Proto.Extension.HasExtensions Value where
  messageUnknownFields = valueUnknownFields
  setMessageUnknownFields !ufs msg = msg {valueUnknownFields = ufs}


instance Semigroup Value where
  a <> b =
    Value
      { valueKind = case b.valueKind of Nothing -> a.valueKind; x -> x
      , valueUnknownFields = a.valueUnknownFields <> b.valueUnknownFields
      }


instance Monoid Value where
  mempty = defaultValue


data NullValue
  = NullValue'NullValue
  deriving stock (Show, Eq, Ord, Enum, Bounded, Generic)
  deriving anyclass (NFData)


toProtoEnumNullValue :: NullValue -> Int
toProtoEnumNullValue NullValue'NullValue = 0


fromProtoEnumNullValue :: Int -> Maybe NullValue
fromProtoEnumNullValue 0 = Just NullValue'NullValue
fromProtoEnumNullValue _ = Nothing


instance MessageEncode NullValue where
  buildMessage _ = mempty


instance MessageSize NullValue where
  messageSize _ = 0


instance MessageDecode NullValue where
  messageDecoder = pure (toEnum 0)


instance Aeson.ToJSON NullValue where
  toJSON NullValue'NullValue = Aeson.String "NULL_VALUE"


instance Aeson.FromJSON NullValue where
  parseJSON = \case
    Aeson.String "NULL_VALUE" -> pure NullValue'NullValue
    Aeson.Number n -> pure (toEnum (round n))
    _ -> fail "Invalid enum value for NullValue"


instance Hashable NullValue where
  hashWithSalt salt x = hashWithSalt salt (toProtoEnumNullValue x)


data ListValue = ListValue
  { listValueValues :: !(V.Vector Value)
  , listValueUnknownFields :: ![UnknownField]
  }
  deriving stock (Show, Eq, Generic)
  deriving anyclass (NFData)


defaultListValue :: ListValue
defaultListValue =
  ListValue
    { listValueValues = V.empty
    , listValueUnknownFields = []
    }


instance MessageEncode ListValue where
  buildMessage msg =
    V.foldl' (\acc v -> let sz = messageSize v in acc <> archSubmessage 10 sz (buildMessage v)) mempty msg.listValueValues
      <> encodeUnknownFields msg.listValueUnknownFields


instance MessageSize ListValue where
  messageSize msg =
    (V.foldl' (\acc v -> acc + archSubmessageSize (messageSize v)) 0 msg.listValueValues)
      + unknownFieldsSize msg.listValueUnknownFields


instance MessageDecode ListValue where
  {-# INLINE messageDecoder #-}
  messageDecoder = loop V.empty []
    where
      loop acc_0 acc_unknown_ =
        withTagM
          (pure (ListValue {listValueValues = acc_0, listValueUnknownFields = reverse acc_unknown_}))
          ( \fn wt -> case fn of
              1 -> do
                v <- decodeFieldMessage
                loop (acc_0 <> V.singleton v) acc_unknown_
              _ -> do
                uf <- captureUnknownField fn (toEnum wt)
                loop acc_0 (uf : acc_unknown_)
          )


instance ProtoMessage ListValue where
  protoMessageName _ = "google.protobuf.ListValue"
  protoPackageName _ = "google.protobuf"
  protoDefaultValue = defaultListValue
  protoFileDescriptorBytes _ = fileDescriptorProtoBytes
  protoFieldDescriptors _ =
    Map.fromList
      [
        ( 1
        , SomeField
            FieldDescriptor
              { fdName = "values"
              , fdNumber = 1
              , fdTypeDesc = MessageType "Value"
              , fdLabel = LabelRepeated
              , fdGet = listValueValues
              , fdSet = \v m -> m {listValueValues = v}
              }
        )
      ]


instance IsMessage ListValue


instance Aeson.ToJSON ListValue where
  toJSON msg =
    jsonObject
      [ "values" .=: msg.listValueValues
      ]


instance Aeson.FromJSON ListValue where
  parseJSON = Aeson.withObject "ListValue" $ \obj -> do
    fld_listValueValues <- parseFieldMaybe obj "values"
    pure
      defaultListValue
        { listValueValues = maybe (listValueValues defaultListValue) id fld_listValueValues
        , listValueUnknownFields = []
        }


instance Hashable ListValue where
  hashWithSalt salt msg = V.foldl' hashWithSalt (salt) msg.listValueValues


instance Proto.Extension.HasExtensions ListValue where
  messageUnknownFields = listValueUnknownFields
  setMessageUnknownFields !ufs msg = msg {listValueUnknownFields = ufs}


instance Semigroup ListValue where
  a <> b =
    ListValue
      { listValueValues = a.listValueValues <> b.listValueValues
      , listValueUnknownFields = a.listValueUnknownFields <> b.listValueUnknownFields
      }


instance Monoid ListValue where
  mempty = defaultListValue