大家晚上好
我被困住了,不知道该怎么办。我有一个应用程序,其中我将协议缓冲区消息中的数据存储在每个消息的DataTable中。为此,我需要获取每个列的字段名。对于枚举字段,我用这些值创建另一个DataTable,并将所有这些表放入单个消息的数据集中。下面是我的工作代码:
def makeMessageTables(self, messageType):
# Instance variable for the message DataSet
self.messageDataSet = DataSet()
###################################################################
# Create a table in the DataSet to hold the message structure.
###################################################################
messageTable = DataTable()
messageTable.TableName = 'messageTable'
# Construct columns in the table to correspons with the message fields.
messageFields = messageType.DESCRIPTOR.fields
for field in messageFields:
messageTable.Columns.Add(field.name)
# Add the table to the DataSet
self.messageDataSet.Tables.Add(messageTable)
###################################################################
# Make a table for each field that has an enum type associated
# with it. The table has the display values and the storage
# values in it foe setting up the ComboBox in the DataGridView
###################################################################
for field in messageFields:
if field.enum_type != None:
tableName = '{}_enumTable'.format(field.enum_type.name)
enumTable = DataTable()
enumTable.TableName = tableName;
enumTable.Columns.Add('enumDisplay')
enumTable.Columns.Add('enumValue')
for value in field.enum_type.values:
newRow = enumTable.NewRow()
newRow['enumDisplay'] = value.name
newRow['enumValue'] = value.number
enumTable.Rows.Add(newRow)
self.messageDataSet.Tables.Add(enumTable)
今天我找到了一条有子消息的消息。我想要一个单独的表,为每个子消息。我遇到的问题是,我不知道如何分解消息以从子消息中获取字段名称和其他信息。我提供了一个有代表性的样本信息,就像我试图处理下面。你知道吗
message SystemOneStatusDetails
{
required int32 field1 = 1;
required int32 field1 = 1;
required int32 field1 = 1;
required int32 field1 = 1;
}
message SystemTwoStatusDetails
{
required int32 field1 = 1;
required int32 field1 = 1;
required int32 field1 = 1;
required int32 field1 = 1;
}
message StatusMessage
{
repeated SystemOneStatusDetails sysOneStatus = 1;
repeated SystemTwoStatusDetails sysTwoStatus = 2;
}
我正在visualstudio中使用ironpython2.7。你知道吗
如果有人能把我引向正确的方向,我将不胜感激。你知道吗
谢谢你, 罗伯特·希克斯
我只在Java中使用了协议缓冲区,所以只能给出高级提示。希望有人对python中的协议缓冲区有更多的了解。你知道吗
每个消息都有一个定义,在每个消息中定义了每个字段。一切都很像原始文件。你知道吗
这是我使用的原始文件:
以下是字段定义(在Java中使用):![enter image description here](https://i.stack.imgur.com/q6Z5r.png)
您似乎正在编写一个通用实用程序,因此对于将来的参考协议,消息可能要复杂得多,例如,可以在消息中定义消息
}
此外,您还可以对消息进行扩展,例如:
相关问题 更多 >
编程相关推荐