anchor.diff:  ;;;; Lisp wrappers
   
   (in-package #:grpc)
  -
  -(defmacro wrap-c-fun (wrapper-name c-fun-name
  -                      wrapper-args-with-type c-fun-args-with-type
  -                      &optional docstring)
  -  "Creates a wrapper with symbol WRAPPER-NAME that uses WRAPPER-ARGS-WITH-TYPE
  - over a C function called C-FUN-NAME that uses WRAPPER-ARGS-WITH-TYPE and
  - C-FUN-ARGS-WITH-TYPE and with a docstring DOCSTRING. Use the macro as follows:
  -
  - (wrap-c-fun wrapped-fun-symbol c-fun<a string> docstring
  -                                        ((:int arg1))
  -                                        ((:pointer cffi:null-pointer))
  -                                        docstring)
  -
  - Now use the wrapped function as follows (wrapped-fun-symbol 6)
  -
  - The types can be any defined in cffi and with libffi can be defined with
  - defcstruct and defcenum too."
  -  (progn
  -    (if docstring
  -        (setf (documentation wrapper-name 'function) docstring))
  -    (flet ((unnest (li)
  -           (let (ret)
  -             (dolist (p li)
  -               (setf ret (append ret p)))
  -             ret)))
  -    `(defun ,wrapper-name ,(mapcar #'second wrapper-args-with-type)
  -       (cffi:foreign-funcall ,c-fun-name
  -                        ,@(unnest wrapper-args-with-type)
  -                        ,@(unnest c-fun-args-with-type)
  -                        :pointer)))))
   
   ;; gRPC Enums
   (cffi:defcenum grpc-security-level
  
positive.code:   (serialized-server-authorization-policy-length :size)
    (instance-info-required :int))
  
  (wrap-c-fun c-grpc-client-new-loas2-credentials
              "grpc_loas2_credentials_create"
              ((:pointer options))
              ()
              "This method creates a LOAS2 channel credential object.")
  
  (cffi:defcfun ("delete_grpc_loas2_credentials_options" grpc-loas2-credentials-options-delete)
      :void
    "Deletes OPTIONS, a grpc_loas2_credentials_options object."
     (options :pointer))
  
  (wrap-c-fun c-grpc-client-new-alts-credentials
              "grpc_alts_credentials_create"
              ((:pointer options)
               (grpc-security-level min-security-level))
              ()
              "This method creates an ALTS channel credential object. The security
    level of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY.")
  
  (wrap-c-fun c-grpc-client-new-access-token-credentials
              "grpc_access_token_credentials_create"
              ((:string access_token))
              ((:pointer (cffi:null-pointer)))
              "Creates an Oauth2 Access Token credentials with an access token
  that was acquired by an out of band mechanism.")
  
  (wrap-c-fun c-grpc-client-new-composite-call-credentials
              "grpc_composite_call_credentials_create"
              ((:pointer creds1)
               (:pointer creds2))
              ((:pointer (cffi:null-pointer)))
              "Creates a composite call credentials object.")
  
  (wrap-c-fun c-grpc-client-new-composite-channel-credentials
              "grpc_composite_channel_credentials_create"
              ((:pointer channel-creds)
               (:pointer call-creds))
              ((:pointer (cffi:null-pointer)))
              "Creates a composite channel credentials object. The security level of
    resulting connection is determined by CHANNEL-CREDS.")
  
  (wrap-c-fun c-grpc-client-new-local-credentials
              "grpc_local_credentials_create"
              ((:pointer type))
              ()
              "This method creates a local channel credential object. The security
   level of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY for UDS and
     GRPC_SECURITY_NONE for LOCAL_TCP.")
  
  (wrap-c-fun c-grpc-client-new-tls-credentials
              "grpc_tls_credentials_create"
              ((:pointer options))
              ()
              "Creates a TLS channel credential object based on the
    grpc_tls_credentials_options specified by callers. The
    security level of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY.")
  
  (wrap-c-fun c-grpc-client-new-google-default-credentials
              "grpc_google_default_credentials_create"
              ((:pointer options))
              ()
              "Creates default credentials to connect to a google gRPC service.
     WARNING: Do NOT use this credentials to connect to a non-google service as
     this could result in an oauth2 token leak. The security level of the
     resulting connection is GRPC_PRIVACY_AND_INTEGRITY.")
  
  (wrap-c-fun c-grpc-client-new-google-compute-engine-credentials
              "grpc_google_compute_engine_credentials_create"
              ()
              ((:pointer (cffi:null-pointer)))
              "Creates a compute engine credentials object for connecting to Google.
     WARNING: Do NOT use this credentials to connect to a non-google service as
     this could result in an oauth2 token leak.")
  
  (wrap-c-fun c-grpc-client-new-xds-credentials
              "grpc_xds_credentials_create"
              ((:pointer fallback-credentials))
              ()
              "This method creates an xDS channel credentials object.")
  
  (wrap-c-fun c-grpc-client-new-external-account-credentials
              "grpc_external_account_credentials_create"
              ((:string json-string)
               (:string scopes-string))
              ()
              "Builds External Account credentials.
   - JSON-STRING is the JSON string containing the credentials options.
   - SCOPES-STRING contains the scopes to be binded with the credentials.")
  
  (wrap-c-fun c-grpc-client-new-refresh-token-credentials
              "grpc_google_refresh_token_credentials_create"
              ((:string json-refresh))
              ((:pointer (cffi:null-pointer)))
              "Creates an Oauth2 Refresh Token credentials object for connecting to Google.
     WARNING: Do NOT use this credentials to connect to a non-google service as
     this could result in an oauth2 token leak.
     - JSON-REFRESH-TOKEN is the JSON string containing the refresh token itself
       along with a client_id and client_secret")
  
  (wrap-c-fun c-grpc-client-new-google-iam-credentials
              "grpc_google_iam_credentials_create"
              ((:string authorization-token)
               (:string authorirt-selector))
              ((:pointer (cffi:null-pointer)))
              "Creates an IAM credentials object for connecting to Google.")
  
  (wrap-c-fun c-grpc-client-new-sts-credentials
              "grpc_sts_credentials_create"
              ((:pointer options))
              ((:pointer (cffi:null-pointer)))
              "Creates an STS credentials following the STS Token Exchanged specifed in the
     IETF draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16.")
  
  ;; gRPC Server Credentials
  
  (wrap-c-fun c-grpc-server-new-loas2-credentials
              "grpc_loas2_server_credentials_create"
              ((:pointer options))
              ()
              "This method creates a LOAS2 channel credential object.")
  
  (wrap-c-fun c-grpc-server-new-ssl-credentials
              "grpc_ssl_server_credentials_create_with_options"
              ((:pointer options))
              ()
              "Creates an SSL server_credentials object using the provided options struct.")
  
  (wrap-c-fun c-grpc-server-new-ssl-credentials-options
              "grpc_ssl_server_credentials_create_options_using_config"
              ((grpc-ssl-client-certificate-request-type client-certificate-request)
               (:pointer certificate-config))
              ()
              " Creates an options object using a certificate config. Use this method when
     the certificates and keys of the SSL server will not change during the
     server's lifetime.")
  
  (wrap-c-fun c-grpc-server-new-local-credentials
              "grpc_local_server_credentials_create"
              ((:pointer type))
              ()
              "This method creates a local server credential object")
  
  (wrap-c-fun c-grpc-server-new-tls-credentials
              "grpc_tls_server_credentials_create"
              ((:pointer options))
              ()
              "Creates a TLS server credential object based on the
    grpc_tls_credentials_options specified by callers.")
  
  (wrap-c-fun c-grpc-server-new-xds-credentials
              "grpc_xds_server_credentials_create"
              ((:pointer fallback-credentials))
              ()
              "his method creates an xDS server credentials object.")
  
  (wrap-c-fun c-grpc-server-new-alts-credentials
              "grpc_alts_server_credentials_create"
              ((:pointer fallback-credentials))
              ()
              "This method creates an ALTS server credential object.")
  
  (wrap-c-fun c-grpc-completion-queue-create-for-pluck
              "grpc_completion_queue_create_for_pluck"
              ()
              ((:pointer (cffi:null-pointer)))
              "This wrapper creates a completion_queue* that is used to start a batch
  of operation and check the success.")
  
  ;; Wrapped grpc-client.cc functions
  
  
negative.code:   :GRPC-CALL-ERROR-COMPLETION-QUEUE-SHUTDOWN)
  
  ;; gRPC Client Channel wrappers
  (defun c-grpc-client-new-insecure-channel (target args)
    "Creates a client channel to TARGET with ARGS."
    (cffi:foreign-funcall "grpc_insecure_channel_create"
                          :string target
                          :pointer args
                          :pointer (cffi-sys:null-pointer)
                          :pointer))
  
  (defun c-grpc-client-new-secure-channel (creds target args)
    "Creates a secure channel to TARGET using the passed-in
  credentials CREDS. Additional channel level configuration MAY be provided
  by grpc_channel_ARGS."
    (cffi:foreign-funcall "grpc_secure_channel_create"
                          :pointer creds
                          :string target
                          :pointer args
                          :pointer (cffi-sys:null-pointer)
                          :pointer))
  
  (defun c-grpc-client-new-default-channel (call-creds user-provided-audience)
    "Creates default credentials to connect to a google gRPC service.
  WARNING: Do NOT use this credentials to connect to a non-google service as
  this could result in an oauth2 token leak. The security level of the
  resulting connection is GRPC_PRIVACY_AND_INTEGRITY.
  
   - CALL-CREDS is an optional parameter will be attached to the
     returned channel credentials object.
  
   - USER-PROVIDED-AUDIENCE is an optional field for user to override the
     audience in the JWT token if used."
    (cffi:foreign-funcall "grpc_google_default_credentials_create"
                          :pointer call-creds
                          :string user-provided-audience
                          :pointer))
  
  ;; gRPC Client Credentials wrappers
  
  (defun c-grpc-client-new-ssl-credentials
      (pem-roots-certs pem-key-cert-pair verify-options)
    "Creates an SSL credentials object.
  The security level of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY.
   - PEM-ROOTS-CERTS is the PEM encoding of the server root certificates.
   - PEM-KEY-CERT-PAIR is a pointer on the object containing client's private
     key and certificate chain.
   - VERIFY-OPTIONS holds additional options controlling how peer certificates
     are verified."
    (cffi:foreign-funcall "grpc_ssl_credentials_create_ex"
                          :pointer pem-roots-certs
                          :pointer pem-key-cert-pair
                          :pointer verify-options
                          :pointer (cffi-sys:null-pointer)
                          :pointer))
  
  (defun c-grpc-client-new-metadata-credentials (plugin min-security-level)
  "This method creates a local channel credential object. The security
  level of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY for UDS and
  GRPC_SECURITY_NONE for LOCAL_TCP. It is used for experimental purpose
  for now and subject to change."
    (cffi:foreign-funcall "grpc_metadata_credentials_create_from_plugin"
                          :pointer plugin grpc-security-level min-security-level :pointer))
  
  (cffi:defcfun ("create_grpc_loas2_credentials_options"
                 create-grpc-loas2-credentials-options) :pointer
  