starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.75k stars 387 forks source link

Using a service #48

Closed daurnimator closed 6 years ago

daurnimator commented 6 years ago

I'm investingating various lua libraries for use with gRPC. Using the current git HEAD, I was able to parse a .proto file containing a gRPC service definition. However I'm not sure how to actually use the service: e.g. pb.type("myservice") doesn't return the service.

For initial testing, I'm using the example service definition from here:

// Copyright 2015 gRPC authors.
//
// 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.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}
starwing commented 6 years ago

This is only a protobuf encode/decode module, just as Google's own protobuf library. It only offers the basic implementation of protobuf data format, but not gRPC.

daurnimator commented 6 years ago

It only offers the basic implementation of protobuf data format, but not gRPC.

I'd like to use it as a base to build a gRPC library. What would be required to have your parser emit the definition of a service? (I want to use my own socket/http library(s))

starwing commented 6 years ago

you could just load the schema as the Lua table using pb.decode("google.protobuf.FileDescriptorSet", pb_file_string),and then you can do what you like with service. I just don't have an interface to read the service information. or use protoc module, it may return the table format of the FileDescriptorProto message of the schema.