"protobuf package"使用时可以省略吗?

Can "protobuf package" be omitted when using?

我有以下 protobuf 文件,我想使用“protobuf-gen”将它们编译成 C#。我发现"chassis.proto"可以成功,但是"perception_lane.proto"不行。我猜原因是"common.Header",应该是"apollo.common.Header":

我用C++编译bazel,他们没有这个问题。 Aslo 可以使用 protoc 编译成 python。问题是protobuf本身是否支持这种用法?或者“protobuf-net”不识别这样的用法?

header.proto

syntax = "proto2";

package apollo.common;

import "modules/common/proto/error_code.proto";

message Header {

  optional double timestamp_sec = 1;
  ...
}

chassis.proto

syntax = "proto2";

package apollo.canbus;

import "modules/common/proto/header.proto";

message Chassis {
  optional apollo.common.Header header = 19;
}

perception_lane.proto

syntax = "proto2";

package apollo.perception;

import "modules/common/proto/header.proto";


message PerceptionLanes {
    optional common.Header header = 1;
}

我收到以下错误消息:

C:code\protobuf-net-2.3.16\src\protogen\bin\Release\net462>protogen.exe --proto_path=../net462 --csharp_out=gen +names=original +langver=3 modules/perception/proto/perception_lane.proto
modules/perception/proto/perception_lane.proto(9,14,9,27): error: type not found: 'common.Header'
modules/perception/proto/perception_lane.proto(11,14,11,36): error: type not found: 'camera.CameraErrorCode'
modules/perception/proto/perception_lane.proto(12,14,12,37): error: type not found: 'camera.CameraCalibrator'
modules/perception/proto/perception_lane.proto(13,14,13,35): error: type not found: 'camera.CameraLaneLine'
modules/perception/proto/perception_camera.proto(50,14,50,28): error: type not found: 'common.Point2D'
modules/perception/proto/perception_camera.proto(51,14,51,28): error: type not found: 'common.Point2D'
modules/perception/proto/perception_camera.proto(62,14,62,28): error: type not found: 'common.Point3D'
modules/perception/proto/perception_camera.proto(64,14,64,28): error: type not found: 'common.Point2D'
modules/perception/proto/perception_camera.proto(96,14,96,28): error: type not found: 'common.Point2D'
modules/perception/proto/perception_camera.proto(97,14,97,28): error: type not found: 'common.Point2D'
modules/perception/proto/perception_camera.proto(98,14,98,28): error: type not found: 'common.Point2D'
modules/perception/proto/perception_camera.proto(104,14,104,27): error: type not found: 'common.Header'
modules/perception/proto/perception_obstacle.proto(30,12,30,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(36,12,36,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(48,12,48,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(51,12,51,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(58,12,58,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(86,12,86,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(89,12,89,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(93,12,93,26): error: type not found: 'common.Point3D'
modules/perception/proto/perception_obstacle.proto(157,12,157,25): error: type not found: 'common.Header'
modules/perception/proto/perception_obstacle.proto(158,12,158,28): error: type not found: 'common.ErrorCode'
modules/perception/proto/perception_lane.proto(5,8,5,41): warning: import not used: 'modules/common/proto/header.proto'
modules/perception/proto/perception_lane.proto(6,8,6,56): warning: import not used: 'modules/perception/proto/perception_camera.proto'

这听起来像是 protobuf-net.Reflection 中名称解析中的错误;可能最好登录 GitHub 并提供足够的信息来重现它(最好是最少的!)。甚至更好:您可以分叉、修复和 PR :)

作为解决方法,您可以尝试在架构中使用完全限定名称(以 . 开头)。例如,Empty.google.protobuf.Empty IIRC。