使用时可以省略“ protobuf软件包”吗?

时间:2019-06-21 01:59:04

标签: protocol-buffers protobuf-net

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

我用C ++编译了bazel,但他们没有这个问题。可以使用协议将Aslo编译为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:\01code\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'

1 个答案:

答案 0 :(得分:0)

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

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