PMunch / binaryparse

Binary parser for Nim
MIT License
71 stars 6 forks source link

Custom encoder does not support extra parameters #9

Closed sealmove closed 3 years ago

sealmove commented 3 years ago

When creating a custom parser with more parameters than just the stream, binaryparse expects an encoder signature with only 2 parameters - the stream and the input. If you try to add more parameters it doesn't work. For example:

import streams
import binaryparse

proc parseCustom(stream: Stream; extra: int): tuple[a: int] =    
  result = (1,)

proc encodeCustom(stream: Stream; input: var tuple[a: int], extra: int) =    
  discard

let custom = (get: parseCustom, put: encodeCustom)

createParser(x):
  *custom(1): y

This errors with:

test.nim(12, 13) template/generic instantiation of `createParser` from here
binaryparse.nim(358, 15) Error: type mismatch: got <Stream, tuple[a: int]>
but expected one of:
proc (stream: Stream, input: var tuple[a: int], extra: int){.noSideEffect, gcsafe, locks: 0.}