Limitation on the length in bitmatch?

34 views
Skip to first unread message

Brian Kidney

unread,
Jan 24, 2015, 1:50:46 PM1/24/15
to bits...@googlegroups.com
I have a type that is defined with a member

  content_len : int32

I am matching binary data structure in which this field is populated and then used to extract another bitstring via:

  content : content_len * 8 : bitstring;

but I get the error:

 Error: This expression has type int32 but an expression was expected of type int

Is the bitstring library limited to using a length of type int or am I doing something else wrong?

Thanks,
Brian


Matthieu Dubuget

unread,
Jan 24, 2015, 1:59:41 PM1/24/15
to bits...@googlegroups.com
content : content_len * 8 : bitstring;

    content_len * 8

means

    apply the function '*' to 'content_len' and '8'.

The type of function * is : int -> int -> int

but content_len is not an int. There is no implicit cast
in OCaml. That's a feature.

You have to provide an int. I mean, find a way to transform
your int32 into an int.

I think that you'll find the right function in the Int32 module:
Int32.to_int should be the one (to be checked).

Of course you'll have to find another solution if content_len is
so big that content_len × 8 would be to high for int type.

Cheers

-- 
Matthieu Dubuget
Guide d’autodéfense numérique : http://guide.boum.org

Brian Kidney

unread,
Jan 30, 2015, 9:14:55 AM1/30/15
to bits...@googlegroups.com, matthieu...@gmail.com
I think the int type will be too limiting in my case. I am working on a file system and the content blocks will be in the order of kilobytes. It looks like it will be the case that bitstring will be too limiting for my use. I think I may have to find an alternative.

Thanks for your response.
Brian
Reply all
Reply to author
Forward
0 new messages