Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom encoder does not support extra parameters #9

Closed
sealmove opened this issue Dec 1, 2020 · 0 comments
Closed

Custom encoder does not support extra parameters #9

sealmove opened this issue Dec 1, 2020 · 0 comments

Comments

@sealmove
Copy link
Contributor

sealmove commented Dec 1, 2020

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.}
@sealmove sealmove changed the title Custom encoder doesn't allow for extra parameters Custom encoder does not support extra parameters Dec 1, 2020
@sealmove sealmove closed this as completed Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant