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

Unable to match bytestring (stream not consumed) #2

Open
agorer opened this issue Oct 29, 2024 · 0 comments
Open

Unable to match bytestring (stream not consumed) #2

agorer opened this issue Oct 29, 2024 · 0 comments

Comments

@agorer
Copy link

agorer commented Oct 29, 2024

I am having some problems matching some bytes but maybe it is because I don't really understand how matching should work. As a reduced test case I have:

let%test "match bytestring" =
  let str = "\x01\x02" in
  let bstr = Bytestring.of_string str in
  match%b bstr with
  | {| b1::8, b2::8 |} ->
    print_endline ((string_of_int b1) ^ " - " ^ (string_of_int b2));
    true
  | {| _rest |} -> false

which as I understand should print "1 - 2", but instead is failing the test (getting to the _rest branch). If I change it to something like:

let%test "match bytestring" =
  let str = "\x01\x02" in
  let bstr = Bytestring.of_string str in
  match%b bstr with
  | {| b1::8, b2::8, rest |} ->
    print_endline ((string_of_int b1) ^ " - " ^ (string_of_int b2) ^ " - " ^ (string_of_int (Bytestring.length rest)));
    true
  | {| _rest |} -> false

I got "0 - 0 - 2" printed which means in this case it takes the first branch, but it is not consuming anything for b1 and b2 and rest is just the whole bytestring that was matched.

Is there something wrong in how I try to match bytestrings?

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