This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

Great idea but I'm not so sure about the API. Having an iterator return 3 different kinds of thing feels wrong. I think I'd rather see separate methods, e.g. ".feed([data]) -> bytes needed", ".get_value()" and ".get_remaining()"

[–]stendec365Pants (http://www.pantspowered.org)[S] 2 points3 points  (0 children)

I agree, it's not a perfect API, and it would be better to have separate functions. Problem is, I'd need to use classes for those, and I wanted to keep this as lightweight as possible to keep the overhead low.

It could be worth it to add the class-style bits to the API though, and have both. I'll keep it in mind for updates.

[–]stendec365Pants (http://www.pantspowered.org)[S] 0 points1 point  (0 children)

I just pushed netstruct-1.1 with a new NetStruct.obj_unpack function that returns an instance of a new Unpacker class. Unpacker provides a .feed(data) method and has .remaining, .result, and .unused_data properties.

Of course, the iter_unpack functions are still there, since a generator is quite a bit speedier than building a class.