Skip to content

Commit 9f8fa96

Browse files
committed
doc: More doc
1 parent 9bc37b7 commit 9f8fa96

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/binary_parser/macros/array.cr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
class BinaryParser
2+
3+
# Declare an array field
4+
#
5+
# ### Argument:
6+
# - name: Field name
7+
# - opt: Options
8+
# - `:type`: Element type, must implement `from_io`
9+
# - `:count`: Element size, can be a number for fixed size, or a symbol for variable size
10+
#
11+
# ### Example:
12+
# ```crystal
13+
# # Fixed size
14+
# class Parser < BinaryParser
15+
# array :arr, { type: UInt8, count: 10 } # Array of 10 UInt8
16+
# end
17+
#
18+
# # Variable size
19+
# class Parser < BinaryParser
20+
# uint32 :size
21+
# array :arr, { type: UInt8, count: :size }
22+
# end
23+
# ```
24+
#
225
macro array(name, opt)
326
{% raise "Must have count and type" unless opt[:type] && opt[:count] %}
427
property! :{{name.id}}

src/binary_parser/macros/string.cr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
class BinaryParser
2+
3+
# Declare a string field
4+
#
5+
# ### Argument:
6+
# - name: Field name
7+
# - opt: Options
8+
# - `:count`: Sting length, can be a number for fixed size, `-1` for zero terminated, or a symbol for variable size
9+
#
10+
# ### Example:
11+
# ```crystal
12+
# # Fixed size
13+
# class Parser < BinaryParser
14+
# string :str, { count: 10 } # Array of 10 UInt8
15+
# end
16+
#
17+
# # Variable size
18+
# class Parser < BinaryParser
19+
# uint32 :size
20+
# string :str, { count: :size }
21+
# end
22+
# ```
23+
#
224
macro string(name, opt = { count: -1 })
325
property! :{{name.id}}
426
@{{name.id}} = ""

src/binary_parser/macros/type.cr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
class BinaryParser
2+
3+
# Nested BinaryParser
4+
#
5+
# ### Argument:
6+
# - name: Field name
7+
# - klass: Another BinaryParser
8+
#
9+
# ### Example:
10+
# ```crystal
11+
#
12+
# class InnerParser < BinaryParser
13+
# uint8 :foo
14+
# end
15+
#
16+
# class Parser < BinaryParser
17+
# type :inner, InnerParser
18+
# end
19+
# ```
20+
#
221
macro type(name, klass)
322
property! :{{name.id}}
423
@{{name.id}} = {{klass}}.new

0 commit comments

Comments
 (0)