2. Improve proto types for using them in
collections
- Add Empty message type for void input or output
parameters.
- Add some repeatable types for data collections.
- Improve Client and server to use those types
- Don’t forget to add “Google.Protobuf.Custom v3.0.0-beta”
reference to Client and Server
3. // The request message containing the user's name.
message stringRequest {
string str = 1;
}
// The response message containing User
message User {
int32 id = 1;
string name = 2;
string surname = 3;
}
// The response message containing the USERS
message UsersCollection {
repeated User users = 1;
}
message Empty {
}
4. Server side code sample
//private server field
Google.Protobuf.Collections.RepeatedField<User> users;
public Task<UsersCollection> GetUserByName(stringRequest request, ServerCallContext context)
{
var reply = new UsersCollection();
var enumerator = users.GetEnumerator();
do
{
if (enumerator.Current != null)
{
if (enumerator.Current.Name == request.Str)
{
reply.Users.Add(enumerator.Current);
}
}
} while (enumerator.MoveNext());
return Task.FromResult(reply);
}
5. Client side code sample
var users = client.GetUserByName(new stringRequest { Str = user }).Users;
var enumerator = users.GetEnumerator();
do
{
if (enumerator.Current != null)
{
//do smth with user element
}
}
while (enumerator.MoveNext());
7. Interfaces
Client:
- Order a good (returns order id, or 0)
- Cancel order (by order id)
- Get my orders
Server:
- Buy, Cancel handling
- Some internal logic