-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tool that generates serialised file descriptor protos (#1654)
Motivation: In order to implement the reflection service we need to be able to generate serialised file descriptor protos of the services and messages that a server offers. Modifications: Added an option for protoc-gen-grpc-swift that enables generating a binary file containing a base64 encoded representation of the serialized file descriptor proto of the specified proto file. Result: This change enables the generation of serialised file descriptor protos that will be useful in the implementation of the reflection service.
- Loading branch information
1 parent
d576a74
commit 09c46b0
Showing
6 changed files
with
150 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Tests/GRPCTests/Codegen/Serialization/SerializationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2023, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
import GRPC | ||
import SwiftProtobuf | ||
import XCTest | ||
|
||
final class SerializationTests: GRPCTestCase { | ||
var fileDescriptorProto: Google_Protobuf_FileDescriptorProto! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
let binaryFileURL = URL(fileURLWithPath: #filePath) | ||
.deletingLastPathComponent().appendingPathComponent("echo.grpc.reflection.txt") | ||
let base64EncodedData = try! Data(contentsOf: binaryFileURL) | ||
let binaryData = Data(base64Encoded: base64EncodedData)! | ||
self | ||
.fileDescriptorProto = | ||
try! Google_Protobuf_FileDescriptorProto(serializedData: binaryData) | ||
} | ||
|
||
func testFileDescriptorMetadata() throws { | ||
let name = self.fileDescriptorProto.name | ||
XCTAssertEqual(name, "echo.proto") | ||
|
||
let syntax = self.fileDescriptorProto.syntax | ||
XCTAssertEqual(syntax, "proto3") | ||
|
||
let package = self.fileDescriptorProto.package | ||
XCTAssertEqual(package, "echo") | ||
} | ||
|
||
func testFileDescriptorMessages() { | ||
let messages = self.fileDescriptorProto.messageType | ||
XCTAssertEqual(messages.count, 2) | ||
for message in messages { | ||
XCTAssert((message.name == "EchoRequest") || (message.name == "EchoResponse")) | ||
XCTAssertEqual(message.field.count, 1) | ||
XCTAssertEqual(message.field.first!.name, "text") | ||
XCTAssert(message.field.first!.hasNumber) | ||
} | ||
} | ||
|
||
func testFileDescriptorServices() { | ||
let services = self.fileDescriptorProto.service | ||
XCTAssertEqual(services.count, 1) | ||
XCTAssertEqual(self.fileDescriptorProto.service.first!.method.count, 4) | ||
for method in self.fileDescriptorProto.service.first!.method { | ||
switch method.name { | ||
case "Get": | ||
XCTAssertEqual(method.inputType, ".echo.EchoRequest") | ||
XCTAssertEqual(method.outputType, ".echo.EchoResponse") | ||
case "Expand": | ||
XCTAssertEqual(method.inputType, ".echo.EchoRequest") | ||
XCTAssertEqual(method.outputType, ".echo.EchoResponse") | ||
XCTAssert(method.serverStreaming) | ||
case "Collect": | ||
XCTAssertEqual(method.inputType, ".echo.EchoRequest") | ||
XCTAssertEqual(method.outputType, ".echo.EchoResponse") | ||
XCTAssert(method.clientStreaming) | ||
case "Update": | ||
XCTAssertEqual(method.inputType, ".echo.EchoRequest") | ||
XCTAssertEqual(method.outputType, ".echo.EchoResponse") | ||
XCTAssert(method.clientStreaming) | ||
XCTAssert(method.serverStreaming) | ||
default: | ||
XCTFail("The method name is incorrect.") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CgplY2hvLnByb3RvEgRlY2hvIiEKC0VjaG9SZXF1ZXN0EhIKBHRleHQYASABKAlSBHRleHQiIgoMRWNob1Jlc3BvbnNlEhIKBHRleHQYASABKAlSBHRleHQy2AEKBEVjaG8SLgoDR2V0EhEuZWNoby5FY2hvUmVxdWVzdBoSLmVjaG8uRWNob1Jlc3BvbnNlIgASMwoGRXhwYW5kEhEuZWNoby5FY2hvUmVxdWVzdBoSLmVjaG8uRWNob1Jlc3BvbnNlIgAwARI0CgdDb2xsZWN0EhEuZWNoby5FY2hvUmVxdWVzdBoSLmVjaG8uRWNob1Jlc3BvbnNlIgAoARI1CgZVcGRhdGUSES5lY2hvLkVjaG9SZXF1ZXN0GhIuZWNoby5FY2hvUmVzcG9uc2UiACgBMAFK/QoKBhIEDgAoAQrCBAoBDBIDDgASMrcEIENvcHlyaWdodCAoYykgMjAxNSwgR29vZ2xlIEluYy4KCiBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKIHlvdSBtYXkgbm90IHVzZSB0aGlzIGZpbGUgZXhjZXB0IGluIGNvbXBsaWFuY2Ugd2l0aCB0aGUgTGljZW5zZS4KIFlvdSBtYXkgb2J0YWluIGEgY29weSBvZiB0a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