簡體   English   中英

如何在python中創建復雜的數據結構

[英]How to create complex data structure in python

我想在python中創建自己的自定義復雜數據結構。 下面是相同的格式。

DownloadInfoIndication () { 
    dsmccMessageHeader () { 
        protocolDiscriminator                   8 bits
        messageId                               16 bits
        transactionId                           32 bits
        adaptationLength                        8 bits
        messageLength                           16 bits
        if (adaptation length > 0) {    
            dsmccAdaptationHeader ()            adaptationLength
        }   
    }   
    downloadId                                  32 bits
    windowSize                                  8 bits (0x00)
    tCDownloadWindow                            32 bits (0x00)
    tCDownloadScenario                          32 bits
    numberOfModules                             16 bits
    for (i = 0; i < numberOfModules; i++) { 
        moduleId                                16 bits
        moduleSize                              32 bits
        moduleVersion                           8 bits
        moduleInfoLength                        8 bits
        for (j = 0; j < moduleInfoLength; j++) {    
            moduleInfoByte                      moduleInfoLength
        }   
    }   
    privateDataLength                           16 bits
    DescriptorCount                             8 bits
    for (k = 0; k < DescriptorCount; k++) { 
        tag                                     8 bits
        length                                  8 bits
        data                                    length
    }   
}

我嘗試探索struct模塊,但無法獲得任何格式相似的示例。 誰能幫忙。

不能完全確定您的用例是什么,但乍看之下似乎可以使用OOP(面向對象編程)來處理。 一個簡單的類就足夠了。

看看Python文檔: https : //docs.python.org/3/tutorial/classes.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM