从Proto文件中获取IMessage,而不生成C sharp文件



我有一个像这样的原型文件:

syntax = "proto3";
package _abbbd3832ad747a0a1b0cd1b3c6d6579;
enum Allocator {
// This needs to be here as a zero value.
DO_NOT_REMOVE = 0;
VALUE = 1;
};
enum StandardEventCodes {
// Signal: N/A
POWER_UP = 0;
// Signal: N/A
WAKE_UP = 1;
// Signal: N/A
POWER_OR_WAKE_UP = 2;
};
enum StandardFilterCodes {
// Signal: The current profile.
IS_CURRENT_PROFILE = 0;
// Signal: The restricted mode
// 0 - unrestricted
// 1 - restricted
// 2 - transport
// 3 - invalid
IS_RESTRICTED_MODE = 1;
};
enum StandardActionCodes {
// Signal: The profile to apply.
APPLY_PROFILE = 0;
};
message Config {
message Profile {
enum State {
ACTIVE = 0;
SLEEP = 1;
HIBERNATE = 2;
};
// The profile's 1 state.
State state = 2;
// What will wake the device up (input, adc_threshold, cell, etc).
uint32 wakeup_mask = 3;
// How long to wait before applying this profile in seconds.
uint32 delay_s = 4;
};
enum BaudRate {
// Slow rate (250 KBPS).
LOW = 0;
// Fast rate (500 KBPS).
HIGH = 1;
};
enum Pdu1 {
// Enable the Pdu1 PGN Mask.
ENABLE = 0;
// Disable the Pdu1 PGN Mask.
DISABLE = 1;
TEST = 2;
};
// The profile's 3 state.
Profile profiles = 1;
// Protocol Data Units message format.
Pdu1 pdu = 2;
};

是否可以在不生成cs文件的情况下获取IMessage、字段描述符等。我正在使用谷歌protobuff。

根据本文,我认为这曾经只适用于C++和Java,但C#实现也通过此功能进行了扩展。我认为这篇stackoverflow的帖子可能会对你有所帮助:如何在C#中将.proto文件解析为FileDescriptor?

此外,这个应用程序在运行时解析proto文件并生成C#代码,所以我相信你想要做的是可能的。

相关内容

最新更新