Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array of struct using asn.1

Tags:

arrays

asn.1

Am learning to write asn.1 grammar. I wish if asn.1 provides facility to write array of sequence. It has a pattern of same type of structure repeated again and again, but with minor modification. I wonder if ASN.1 would allow me to write array kind of grammar to fit it in few rather than write this big grammar.

gamePlayer {
gamePlayer {
    gamePlayer type: user (0)
    playerDetail  {
        name: player_1
        team: red
        ip: 10.3.3.1
        membership: level_2
    }
}
gamePlayer {
    gamePlayer type: user (0)
    playerDetail  {
        name: player_2
        team: blue
        ip: 10.3.3.2
        membership: level_4
    }
}
gamePlayer {
    gamePlayer type: ai (1)
    playerDetail  {
        name: ai_1
        team: red
        bot: bikeBot
    }
}
gamePlayer {
    gamePlayer type: ai (1)
    playerDetail  {
        name: ai_2
        team: blue
        bot: bikeBot
    }
}
gamePlayer {
    gamePlayer type: ai (1)
    playerDetail  {
        name: ai_3
        team: blue
        bot: carBot
    }
}

}

like image 840
Gopi Avatar asked Apr 10 '26 23:04

Gopi


1 Answers

I would use ENUMERATED for gameplayer type. Differences in playerDetail would be possible to solve with OPTIONAL members. Array of game players would be solved by SEQUENCE OF.

This is the example of ASN.1 module (I have not tested if it is correct) GamePlayerModule

DEFINITIONS IMPLICIT TAGS ::= BEGIN

GamePlayers ::= SEQUENCE OF GamePlayer

Gameplayer ::= SEQUENCE {
   type ::=         ENUMERATED
                       {
                          user  (0)
                          ai    (1)

                       },
   playerDetail     PlayerDetail
}

PlayerDetail ::= SEQUENCE {
    name            UTF8STRING,
    team            UTF8STRING,
    ip          [0] UTF8STRING OPTIONAL,
    membership  [1] UTF8STRING OPTIONAL,
    bot         [2] UTF8STRING OPTIONAL
}

END
like image 191
pepo Avatar answered Apr 12 '26 11:04

pepo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!