Skip to content

Commit 4640bd8

Browse files
committed
feat: Support UInt64, Int64
1 parent 1923684 commit 4640bd8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/binary_parser/macros/int64.cr

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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}} = 0i64
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

src/binary_parser/macros/uint64.cr

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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}} = 0u64
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

0 commit comments

Comments
 (0)