-(defmethod find-enum ((protobuf protobuf) (name string))
- (labels ((find-it (proto)
- (let ((enum (find name (proto-enums proto) :key #'proto-name :test #'string=)))
- (when enum
- (return-from find-enum enum))
- (map () #'find-it (proto-imported-schemas proto)))))
- (find-it protobuf)))
+(defmethod find-message ((schema protobuf-schema) (type symbol) &optional relative-to)
+ (declare (ignore relative-to))
+ ;; Extended messages "shadow" non-extended ones
+ (labels ((find-it (schema)
+ (let ((message (or (find type (proto-extenders schema) :key #'proto-class)
+ (find type (proto-messages schema) :key #'proto-class))))
+ (when message
+ (return-from find-message message))
+ (map () #'find-it (proto-imported-schemas schema)))))
+ (find-it schema)))
+
+(defmethod find-message ((schema protobuf-schema) (type class) &optional relative-to)
+ (find-message schema (class-name type) (or relative-to schema)))
+
+(defmethod find-message ((schema protobuf-schema) (name string) &optional relative-to)
+ (let ((relative-to (or relative-to schema)))
+ (labels ((find-it (schema)
+ (let ((message (or (find-qualified-name name (proto-extenders schema)
+ :relative-to relative-to)
+ (find-qualified-name name (proto-messages schema)
+ :relative-to relative-to))))
+ (when message
+ (return-from find-message message))
+ (map () #'find-it (proto-imported-schemas schema)))))
+ (find-it schema))))
+
+(defgeneric find-service (protobuf name)
+ (:documentation
+ "Given a Protobufs schema,returns the Protobufs service of the given name."))
+
+(defmethod find-service ((schema protobuf-schema) (name symbol))
+ (find name (proto-services schema) :key #'proto-class))
+
+(defmethod find-service ((schema protobuf-schema) (name string))
+ (find-qualified-name name (proto-services schema)))
+
+;; Convenience function that accepts a schema name
+(defmethod find-service (schema-name name)
+ (let ((schema (find-schema schema-name)))
+ (assert schema ()
+ "There is no schema named ~A" schema-name)
+ (find-service schema name)))