ProtoDef-io / node-protodef

Describe your protocol, and read it with ease.
MIT License
31 stars 18 forks source link

Make count more general #35

Open rom1504 opened 8 years ago

rom1504 commented 8 years ago

roblabla: something like "count": "$variable", "count": "@type", "count": 64 roblabla: having both count and countType annoys me roblabla: and beside that would be reusable for other stuff too like conditionals and stuff

useful for https://github.com/mhsjlw/minecraft-classic-protocol/blob/master/src/datatypes/minecraft.js http://wiki.vg/Classic_Protocol#Protocol_Data_Types

(+ what about padding ?)

roblabla commented 8 years ago

Concerning padding, I'm thinking of adding a min/max datatype. Something like ["min", 64, ["container", []] or ["max", 64, ["container", []]. This is for replacing the current garantee that we know the datatype size in NMP. With the same datatype, we could add a padding value so that if it doesn't reach that value, it adds that padding until it does.

rom1504 commented 8 years ago

handling "count":64 is indeed useful. (need it for node-raknet) I think I'll add that soon

rom1504 commented 8 years ago

can't see how that would eliminate countType.

countType means "add the length before the array", count doesn't do that

roblabla commented 8 years ago

The idea is that in places where we can accept both a static number or a protocol-defined number (or anything else for that matter), we should have a standardized way to do it. A "selector".

count: 64
count: "$var"
count: "@type"

This pattern comes up quite often in datatypes (array, the fixed data-type I talk about in #57, a few other datatypes I wrote myself in other projects) so having a standardized way to do it with tools to easily operate with that would be good.

rom1504 commented 8 years ago

Ah, this would allow compareTo:"value".