Skip to content

Commit

Permalink
fix incorrect use of toSszType (#82)
Browse files Browse the repository at this point in the history
* also fix missing `fromSszBytes`
  • Loading branch information
arnetheduck committed Mar 28, 2024
1 parent fe033e2 commit 248f2bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
15 changes: 3 additions & 12 deletions ssz_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ proc writeValue*[T](

proc readValue*(
r: var SszReader, val: var auto) {.raises: [SszError, IOError].} =
mixin readSszBytes
type T = typeof val
mixin readSszBytes, toSszType
type T = typeof toSszType(val)
when isFixedSize(T):
const minimalSize = fixedPortionSize(T)
if r.stream.readable(minimalSize):
Expand All @@ -289,13 +289,4 @@ proc readSszBytes*[T](
# Overload `readSszBytes` to perform custom operations on T after
# deserialization
mixin readSszValue

when T isnot SszType:
mixin toSszType
readSszValue(data, toSszType(val))
else:
# Although inside toSszType already have
# compile time check for SszType,
# somehow it will trigger `dereferencing pointer to incomplete type`
# error on linux gcc.
readSszValue(data, val)
readSszValue(data, val)
7 changes: 3 additions & 4 deletions ssz_serialization/codec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ proc readSszValue*[T](
T, "list element offset points past the end of the input")
int(offset)

when val is BitList:
when compiles(fromSszBytes(T, input)):
val = fromSszBytes(T, input)
elif val is BitList:
if input.len == 0:
raiseMalformedSszError(T, "invalid empty value")

Expand Down Expand Up @@ -439,9 +441,6 @@ proc readSszValue*[T](
else:
val = Opt.some(v)

elif val is UintN|bool:
val = fromSszBytes(T, input)

elif val is BitArray:
if sizeof(val) != input.len:
raiseIncorrectSize(T)
Expand Down

0 comments on commit 248f2bd

Please sign in to comment.