@@ -418,18 +418,39 @@ i of grpc_byte_buffer BUFFER."
418
418
these operation guide the interaction between the client and server."
419
419
(num-ops :int ))
420
420
421
+ (defun make-metadata (metadata)
422
+ " Sets OP[INDEX] to a Send Initial Metadata operation by adding metadata
423
+ METADATA, the count of metadata COUNT, and the flag FLAG."
424
+ (let* ((arr-size (length metadata))
425
+ (metadata
426
+ (loop for (key value) in metadata
427
+ collect
428
+ (cffi :foreign-funcall " lisp_make_grpc_metadata"
429
+ :string key
430
+ :string value)))
431
+ (l-arr (make-array (list arr-size)
432
+ :initial-contents metadata)))
433
+ (cffi :with-foreign-array (arr l-arr (list :array :int64 arr-size))
434
+ (cffi :foreign-funcall " create_new_grpc_metadata_array_with_data"
435
+ :pointer arr
436
+ :size arr-size))))
437
+
421
438
(defun make-send-metadata-op (op metadata
422
439
&key count flag
423
- index)
440
+ index)
424
441
" Sets OP[INDEX] to a Send Initial Metadata operation by adding metadata
425
442
METADATA, the count of metadata COUNT, and the flag FLAG."
426
- (cffi :foreign-funcall " lisp_grpc_make_send_metadata_op"
427
- :pointer op
428
- :int index
429
- :pointer metadata
430
- :int count
431
- :int (convert-metadata-flag-to-integer flag)
432
- :void ))
443
+ (let ((metadata-ptr (if metadata
444
+ (make-metadata metadata)
445
+ (cffi :null-pointer))))
446
+
447
+ (cffi :foreign-funcall " lisp_grpc_make_send_metadata_op"
448
+ :pointer op
449
+ :int index
450
+ :pointer metadata-ptr
451
+ :int count
452
+ :int (convert-metadata-flag-to-integer flag)
453
+ :void ))
433
454
434
455
(defun make-send-message-op (op message &key index)
435
456
" Sets OP[INDEX] to a 'Send Message' operation that sends MESSAGE
@@ -509,7 +530,7 @@ want. Returns a plist containing keys being the op type and values being the ind
509
530
(setf (getf ops-plist message-type) (incf cur-index))))
510
531
511
532
(when send-metadata
512
- (make-send-metadata-op ops ( cffi :null-pointer)
533
+ (make-send-metadata-op ops send-metadata
513
534
:count 0 :flag 0 :index (next-marker :send-metadata )))
514
535
(when send-message
515
536
(make-send-message-op ops send-message :index (next-marker :send-message )))
@@ -585,9 +606,12 @@ macros and only call once."
585
606
(method-name " " :type string )
586
607
; ; This is a plist where the key is a keyword for a type of op
587
608
; ; and the value is the index of that op in an op-array.
588
- (ops-plist nil :type list ))
609
+ (ops-plist nil :type list )
610
+ (context nil :type (or null client-context server-context)))
589
611
590
- ; ; Shared call functions
612
+ (defstruct context
613
+ (deadline -1 :type integer )
614
+ (metadata nil :type list ))
591
615
592
616
(defun receive-message (call)
593
617
" Receive a message from the client for a CALL."
@@ -628,7 +652,12 @@ macros and only call once."
628
652
(ops (create-new-grpc-ops num-ops))
629
653
(grpc-slice
630
654
(convert-bytes-to-grpc-byte-buffer bytes-to-send))
631
- (ops-plist (prepare-ops ops :send-message grpc-slice))
655
+ (context (call-context call))
656
+ (ops-plist (prepare-ops
657
+ ops
658
+ :send-message grpc-slice
659
+ :send-metadata (and context
660
+ (context-metadata context))))
632
661
(call-code (call-start-batch c-call ops num-ops tag)))
633
662
(declare (ignore ops-plist))
634
663
(unless (eql call-code :grpc-call-ok )
0 commit comments