Custom read/write functions#13
Conversation
|
This is making several different changes in one go and I need to understand the motivation a little better. I'm hesitant to commit to the interface for reading and writing types. Can you help explain the use cases for the two main changes that you're proposing, an example or two can help me understand the benefit of adding it.
|
|
I'm implementing server which talks to existing flash application. General format of messages used there is: length of message first and then bytes of message itself, so I've modified writeData to return size. Also I needed new data type - string with variable length - length frist, then char array, which I couldn't do with existing structs. So I've written custom read and write functions. |
|
I've been thinking on this a little bit and in this case I would probably end up using the lower level API to read the variable length amount. In fact if it is only ever the message length and the message, the low level functions are probably better. I don't want to commit to a specific format for custom readers and writers yet. Though there needs to more generally be a better way to do this, I'm not sure that this is the best way yet. |
|
He should be able to do something like the following, right? var parser = new mod_ctype.Parser({ endian: 'big' }),
buffer = new Buffer(9);
parser.writeData([
{ 'len': { type: 'uint32_t' } },
{ 'message': { type: 'char[len]' } }
], buffer, 0, [ 5, new Buffer('hello') ]);If I understand him correctly, it seems like the functionality is now available. |
Hi
I needed to implement a custom data type for my project, with custom read and write functions, but I couldn't find a way to add it to parser, so I created this small patch.
Basically it allows to do things like this: