File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ class BinaryParser
2+
3+ # Declare a int64 field
4+ #
5+ # ```crystal
6+ # int64 :value # name of field
7+ # ```
8+ macro int64 (name )
9+ property! :{{name.id}}
10+ @{{name.id}} = 0 i64
11+
12+ def _read_ {{name.id}}(io : IO )
13+ @{{name.id}} = io.not_nil!.read_bytes(Int64 ).as(Int64 )
14+ end
15+
16+ def _write_ {{name.id}}(io : IO )
17+ io.not_nil!.write_bytes(@{{name.id}}.not_nil!)
18+ end
19+
20+ def _size_static_ {{name.id}}
21+ sizeof(Int64 )
22+ end
23+ end
24+ end
Original file line number Diff line number Diff line change 1+ class BinaryParser
2+
3+ # Declare a uint64 field
4+ #
5+ # ```crystal
6+ # uint64 :value # name of field
7+ # ```
8+ macro uint64 (name )
9+ property! :{{name.id}}
10+ @{{name.id}} = 0 u64
11+
12+ def _read_ {{name.id}}(io : IO )
13+ @{{name.id}} = io.not_nil!.read_bytes(UInt64 ).as(UInt64 )
14+ end
15+
16+ def _write_ {{name.id}}(io : IO )
17+ io.not_nil!.write_bytes(@{{name.id}}.not_nil!)
18+ end
19+
20+ def _size_static_ {{name.id}}
21+ sizeof(UInt64 )
22+ end
23+ end
24+ end
You can’t perform that action at this time.
0 commit comments