Skip to content

Commit

Permalink
Merge pull request #7 from JuliaComputing/tan/gen
Browse files Browse the repository at this point in the history
use protobuf codegen enhancements
  • Loading branch information
tanmaykm authored Apr 7, 2021
2 parents 556ae23 + 9e67593 commit cc7c233
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
19 changes: 0 additions & 19 deletions src/generate.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const package_regex = r"package\s(\S*)[\s]*;.*"
const service_regex = r"service\s(\S*)[\s]*{.*"
const services_option_regex = r"option\s[a-z]*_generic_services[\s]*=[\s]*true[\s]*;"

function write_header(io, package, client_module_name)
print(io, """module $(client_module_name)
Expand Down Expand Up @@ -89,19 +88,6 @@ function write_service_method(io, package, service, method)
""")
end

function has_services_enabled(proto::String)
enabled = false
for line in readlines(proto)
line = strip(line)
regexmatches = match(services_option_regex, line)
if (regexmatches !== nothing)
enabled = true
break
end
end
enabled
end

function detect_services(proto::String)
package = ""
services = String[]
Expand Down Expand Up @@ -149,11 +135,6 @@ function generate(proto::String; outdir::String=pwd())

@info("Generating gRPC client", proto, outdir)

# ensure services are enabled in proto file
if !has_services_enabled(proto)
throw(ArgumentError("Service generation must be enabled in $proto, e.g. option py_generic_services = true;"))
end

# determine the package name and service name
package, services = detect_services(proto)
protodir = dirname(proto)
Expand Down
2 changes: 0 additions & 2 deletions test/RouteguideClients/route_guide.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ option go_package = "google.golang.org/grpc/examples/route_guide/routeguide";
option java_multiple_files = true;
option java_package = "io.grpc.examples.routeguide";
option java_outer_classname = "RouteGuideProto";
option py_generic_services = true;
option java_generic_services = true;

package routeguide;

Expand Down
24 changes: 12 additions & 12 deletions test/RouteguideClients/route_guide_pb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ end

# service methods for RouteGuide
const _RouteGuide_methods = MethodDescriptor[
MethodDescriptor("GetFeature", 1, routeguide.Point, routeguide.Feature),
MethodDescriptor("ListFeatures", 2, routeguide.Rectangle, Channel{routeguide.Feature}),
MethodDescriptor("RecordRoute", 3, Channel{routeguide.Point}, routeguide.RouteSummary),
MethodDescriptor("RouteChat", 4, Channel{routeguide.RouteNote}, Channel{routeguide.RouteNote})
MethodDescriptor("GetFeature", 1, Point, Feature),
MethodDescriptor("ListFeatures", 2, Rectangle, Channel{Feature}),
MethodDescriptor("RecordRoute", 3, Channel{Point}, RouteSummary),
MethodDescriptor("RouteChat", 4, Channel{RouteNote}, Channel{RouteNote})
] # const _RouteGuide_methods
const _RouteGuide_desc = ServiceDescriptor("routeguide.RouteGuide", 1, _RouteGuide_methods)

Expand All @@ -222,16 +222,16 @@ mutable struct RouteGuideBlockingStub <: AbstractProtoServiceStub{true}
RouteGuideBlockingStub(channel::ProtoRpcChannel) = new(ProtoServiceBlockingStub(_RouteGuide_desc, channel))
end # mutable struct RouteGuideBlockingStub

GetFeature(stub::RouteGuideStub, controller::ProtoRpcController, inp::routeguide.Point, done::Function) = call_method(stub.impl, _RouteGuide_methods[1], controller, inp, done)
GetFeature(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::routeguide.Point) = call_method(stub.impl, _RouteGuide_methods[1], controller, inp)
GetFeature(stub::RouteGuideStub, controller::ProtoRpcController, inp::Point, done::Function) = call_method(stub.impl, _RouteGuide_methods[1], controller, inp, done)
GetFeature(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::Point) = call_method(stub.impl, _RouteGuide_methods[1], controller, inp)

ListFeatures(stub::RouteGuideStub, controller::ProtoRpcController, inp::routeguide.Rectangle, done::Function) = call_method(stub.impl, _RouteGuide_methods[2], controller, inp, done)
ListFeatures(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::routeguide.Rectangle) = call_method(stub.impl, _RouteGuide_methods[2], controller, inp)
ListFeatures(stub::RouteGuideStub, controller::ProtoRpcController, inp::Rectangle, done::Function) = call_method(stub.impl, _RouteGuide_methods[2], controller, inp, done)
ListFeatures(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::Rectangle) = call_method(stub.impl, _RouteGuide_methods[2], controller, inp)

RecordRoute(stub::RouteGuideStub, controller::ProtoRpcController, inp::Channel{routeguide.Point}, done::Function) = call_method(stub.impl, _RouteGuide_methods[3], controller, inp, done)
RecordRoute(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::Channel{routeguide.Point}) = call_method(stub.impl, _RouteGuide_methods[3], controller, inp)
RecordRoute(stub::RouteGuideStub, controller::ProtoRpcController, inp::Channel{Point}, done::Function) = call_method(stub.impl, _RouteGuide_methods[3], controller, inp, done)
RecordRoute(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::Channel{Point}) = call_method(stub.impl, _RouteGuide_methods[3], controller, inp)

RouteChat(stub::RouteGuideStub, controller::ProtoRpcController, inp::Channel{routeguide.RouteNote}, done::Function) = call_method(stub.impl, _RouteGuide_methods[4], controller, inp, done)
RouteChat(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::Channel{routeguide.RouteNote}) = call_method(stub.impl, _RouteGuide_methods[4], controller, inp)
RouteChat(stub::RouteGuideStub, controller::ProtoRpcController, inp::Channel{RouteNote}, done::Function) = call_method(stub.impl, _RouteGuide_methods[4], controller, inp, done)
RouteChat(stub::RouteGuideBlockingStub, controller::ProtoRpcController, inp::Channel{RouteNote}) = call_method(stub.impl, _RouteGuide_methods[4], controller, inp)

export Point, Rectangle, Feature, RouteNote, RouteSummary, RouteGuide, RouteGuideStub, RouteGuideBlockingStub, GetFeature, ListFeatures, RecordRoute, RouteChat

3 comments on commit cc7c233

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/33758

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" cc7c23341eaa4e4c293fbc09cacae3d5dcefa857
git push origin v0.1.0

Please sign in to comment.