Skip to content

Commit 7c4e159

Browse files
authored
Update proto (#4008)
* Delete old proto files * Adding new proto files * Changing dataType to string * Use enum for data type * Send load request with data type * Null check before assigning to dataType * Refactoring and testing conversion code * Naming convention for data type * Removing redundant checks for data types * Default behavior test for conversion * Making undefined the default enum choice * Explicit check for undefined data type
1 parent ec8984e commit 7c4e159

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

src/WebJobs.Script.Grpc/azure-functions-language-worker-protobuf/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ From within the Azure Functions language worker repo:
2424

2525
From within the Azure Functions language worker repo:
2626
1. Define remote branch for cleaner git commands
27-
- `git remote add proto-file https://github.com/mhoeger/azure-functions-language-worker-protobuf.git`
27+
- `git remote add proto-file https://github.com/azure/azure-functions-language-worker-protobuf.git`
2828
- `git fetch proto-file`
2929
2. Merge updates
3030
- `git merge -s subtree proto-file/<version branch> --squash --allow-unrelated-histories`

src/WebJobs.Script.Grpc/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,21 @@ message BindingInfo {
301301
inout = 2;
302302
}
303303

304+
// Indicates the type of the data for the binding
305+
enum DataType {
306+
undefined = 0;
307+
string = 1;
308+
binary = 2;
309+
stream = 3;
310+
}
311+
304312
// Type of binding (e.g. HttpTrigger)
305313
string type = 2;
306314

307315
// Direction of the given binding
308316
Direction direction = 3;
317+
318+
DataType data_type = 4;
309319
}
310320

311321
// Used to send logs back to the Host

src/WebJobs.Script/Description/Binding/DataType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Microsoft.Azure.WebJobs.Script.Description
88
/// </summary>
99
public enum DataType
1010
{
11+
Undefined,
1112
String,
1213
Binary,
1314
Stream

src/WebJobs.Script/Rpc/LanguageWorkerChannel.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,9 @@ internal void SendFunctionLoadRequest(FunctionRegistrationContext context)
334334

335335
foreach (var binding in metadata.Bindings)
336336
{
337-
request.Metadata.Bindings.Add(binding.Name, new BindingInfo
338-
{
339-
Direction = (BindingInfo.Types.Direction)binding.Direction,
340-
Type = binding.Type
341-
});
337+
BindingInfo bindingInfo = binding.ToBindingInfo();
338+
339+
request.Metadata.Bindings.Add(binding.Name, bindingInfo);
342340
}
343341

344342
SendStreamingMessage(new StreamingMessage

src/WebJobs.Script/Rpc/MessageExtensions/RpcMessageConversionExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Google.Protobuf;
1010
using Microsoft.AspNetCore.Http;
1111
using Microsoft.Azure.WebJobs.Extensions.Http;
12+
using Microsoft.Azure.WebJobs.Script.Description;
1213
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
1314
using Newtonsoft.Json;
1415
using Newtonsoft.Json.Linq;
@@ -159,5 +160,21 @@ public static TypedData ToRpc(this object value)
159160
}
160161
return typedData;
161162
}
163+
164+
public static BindingInfo ToBindingInfo(this BindingMetadata bindingMetadata)
165+
{
166+
BindingInfo bindingInfo = new BindingInfo
167+
{
168+
Direction = (BindingInfo.Types.Direction)bindingMetadata.Direction,
169+
Type = bindingMetadata.Type
170+
};
171+
172+
if (bindingMetadata.DataType != null)
173+
{
174+
bindingInfo.DataType = (BindingInfo.Types.DataType)bindingMetadata.DataType;
175+
}
176+
177+
return bindingInfo;
178+
}
162179
}
163180
}

test/WebJobs.Script.Tests/Rpc/RpcMessageConversionExtensionsTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System.Collections.Generic;
55
using Microsoft.AspNetCore.Http;
6+
using Microsoft.Azure.WebJobs.Script.Description;
7+
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
68
using Microsoft.Azure.WebJobs.Script.Rpc;
79
using Microsoft.WebJobs.Script.Tests;
810
using Xunit;
@@ -46,5 +48,42 @@ public void HttpObjects_Query(string queryString, string[] expectedKeys, string[
4648
Assert.Equal(rpcRequestObject.Http.Query.GetValueOrDefault(expectedKeys[i]), expectedValues[i]);
4749
}
4850
}
51+
52+
[Theory]
53+
[InlineData(BindingDirection.In, "blob", DataType.String)]
54+
[InlineData(BindingDirection.Out, "blob", DataType.Binary)]
55+
[InlineData(BindingDirection.InOut, "blob", DataType.Stream)]
56+
[InlineData(BindingDirection.InOut, "blob", DataType.Undefined)]
57+
public void ToBindingInfo_Converts_Correctly(BindingDirection bindingDirection, string type, DataType dataType)
58+
{
59+
BindingMetadata bindingMetadata = new BindingMetadata
60+
{
61+
Direction = bindingDirection,
62+
Type = type,
63+
DataType = dataType
64+
};
65+
66+
BindingInfo bindingInfo = bindingMetadata.ToBindingInfo();
67+
68+
Assert.Equal(bindingInfo.Direction, (BindingInfo.Types.Direction)bindingMetadata.Direction);
69+
Assert.Equal(bindingInfo.Type, bindingMetadata.Type);
70+
Assert.Equal(bindingInfo.DataType, (BindingInfo.Types.DataType)bindingMetadata.DataType);
71+
}
72+
73+
[Fact]
74+
public void ToBindingInfo_Defaults_EmptyDataType()
75+
{
76+
BindingMetadata bindingMetadata = new BindingMetadata
77+
{
78+
Direction = BindingDirection.In,
79+
Type = "blob"
80+
};
81+
82+
BindingInfo bindingInfo = bindingMetadata.ToBindingInfo();
83+
84+
Assert.Equal(bindingInfo.Direction, (BindingInfo.Types.Direction)bindingMetadata.Direction);
85+
Assert.Equal(bindingInfo.Type, bindingMetadata.Type);
86+
Assert.Equal(bindingInfo.DataType, BindingInfo.Types.DataType.Undefined);
87+
}
4988
}
5089
}

0 commit comments

Comments
 (0)