lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



It was thus said that the Great Sean Connor once stated:


  Actually, that's just one of several different packet types for SMPP, and
not included there are the optional parameters.  I'm reading your
documentation on Pack [1] and I'm not seeing anything that can actually
handle the optional part of the SUBMIT_SM packet (what I'm actually encoding
there).  You list:

	atomic		A single instance
	sequence	Multiple values in a given order
	array		Multiple values of the same type
	struct		Ordered collection of named values

  The optional parts of the SUBMIT_SM are a series of values that can appear
in any order.  Now, they all follow a similar format:

	tag	2 byte integer network byte order
	length	2 byte integer network byte order
	value	variable, based upon length

  For an even weirder example, we have a custom binary format.

	tag	1 or 3 bytes
	length	1 or 3 bytes
	value	variable length

  For the tag or length, if the byte is less than 255, then that's the
value; if it is 255, then the actual value is the next two bytes, in network
byte order.  The order of tags does not matter, *except* that tag value of 1
should always be first.

  CBOR [2] is similar---integer values can be 1 byte, 2 bytes, 3 bytes, 5
bytes or 9 bytes in size, and the type is encoded with the value in some
cases.

  Then there are protocols like IP, where some fields are only a few bits in
size, but it looks like you handle that somewhat.

  -spc

[1]	https://github.com/tobbik/lua-t/blob/master/docs/Pack.rst

[2]	Concise Binary Object Representation RFC-7049
	http://cbor.io/

I see, this is an issue that was actually solved by construct for Python [1] using the context and their 'this' expression. It is very powerful and ultimately I'd like to provide a way in lua-t to make that happen bit there are ways to go. It's
actually not trivial to provide this functionality (in an efficient and easily
usable way that is).

However, I do think that functionality like this requires to stray from the simple formatting string to a more complex and declarative syntax very similar to what I provided in the previous mail. And to reiterate the point and the comment on the very topic of the original post this is definitely worth it to be packed into a
separate library.


https://construct.readthedocs.io/en/latest/meta.html#using-this-expression