binarylang icon indicating copy to clipboard operation
binarylang copied to clipboard

More support for different string types

Open ajusa opened this issue 4 years ago • 3 comments

  1. Fixed length strings. In order to read a string that is exactly 200 bytes, you are forced to make a subparser and use @get. Ideally, we can define a new single letter type that stands for a fixed string length, and it is always 200 bytes long.
  2. Support for other string encodings. Maybe have s16 mean utf-16? This also isn't too bad to implement using getters and setters, but for really common encodings it might be worth including them straight into binarylang itself.

ajusa avatar Mar 28 '21 16:03 ajusa

(1): For this to work properly, left-hand side syntax has to be extended to support something like s(200). This is also compatible with (2) since we can have a syntax like this: s16(200) to denote a 16-bit-per-char string of fixed length equal to 200.

(2): This is definitely within plans. It probably needs changes in bitstreams and in general it's non-trivial to implement, so you folks have to wait this out for while. P.S.: similarly there are plans for supporting arbitrary float mantissas.

sealmove avatar Mar 28 '21 17:03 sealmove

Not sure what changed in the code in the last 2 years, but s: a_string(200) works for me, except that it has the side effect of breaking the parsing when it encounters a 0 value in the string. There is no easy workaround, but maybe writing a subparser like ajusa mentioned. For such a super trivial functionality, this is quite unfortunate :( please fix. Not sure what the optimal solution is, but there need to be one.

sgmihai avatar Jun 14 '23 15:06 sgmihai

Hello @sgmihai, What you really want from binarylang is an array of '8u'. This will do the parsing you want, not stopping at null bytes. What really bothers you is the resulting Nim type. In order to keep binarylang simpler and extensible, we do not adress this issue directly in the core syntax. Instead, you should read the "Operations" section of the manual. Also take a look at operations.nim where some basic 'operations' are already implemented. You may import existing ones, or/and make an MR to add a new one.

P.S.: I think the one you need is already included in operations.nim. Look 'toStrGet' and 'toStrPut'.

sealmove avatar Jun 16 '23 06:06 sealmove