Skip to content

Commit

Permalink
Merge pull request #16 from moreal/update-wrong-syntax-in-readme
Browse files Browse the repository at this point in the history
Update wrong syntax on example codes in readme
  • Loading branch information
moreal committed Jul 9, 2019
2 parents 5d9dda6 + 919fe7c commit 3a053d1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $ pip install pystructs
from typing import List
from pystructs import fields


class Attribute(fields.Struct):
type = fields.BytesField(size=1)
length = fields.Int32Field(byteorder='big')
Expand All @@ -30,8 +31,15 @@ class StunMessage(fields.Struct):
length = fields.Int32Field(byteorder='big')
attributes: List[Attribute] = fields.MultipleField(count='length', field=Attribute())

message = StunMessage(<bytes>)

message = StunMessage(
b'\x09\x00\x00\x00\x02'
b'\x01\x00\x00\x00\x03\x12\x34\x56'
b'\x02\x00\x00\x00\x03\x12\x34\x56')

message.initialize()

# Just use!
print(message.length) # 2
print(message.attributes[0].length) # 3
print(message.attributes[1].length) # 3
```

0 comments on commit 3a053d1

Please sign in to comment.