I have service that is utilizing web sockets in order to transfer data.
I need a way to encode a tree structure and transfer that tree structure over the websocket. I have been reading about the TLV and sub-TLV encoding which seems to be a great idea i.e. it is already used in the protocols such as Radius, LLDP which proves that this is working however my problems is that those protocols are usually used between a trusted devices i.e. between switches/routers (except the LLDP). My problems is that i will be transferring TLV that includes sub-TLVs that do have a random size/length as well as they do not have a statically defined structure for example if you take a look into the in the first TLV where the concept of the sub-TLV's have been defined i.e.
Extended IS Reachability TLV #22 then you will see that this tlv has a structure like this:
/* +-------+-------+-------+-------+-------+-------+-------+-------+
* | Type | 1
* +---------------------------------------------------------------+
* | Length ID | 1
* +---------------------------------------------------------------+
* | Neighbour ID | 7
* +---------------------------------------------------------------+
* | TE Metric | 3
* +---------------------------------------------------------------+
* | SubTLVs Length | 1
* +---------------------------------------------------------------+
* | SubTLVs value | variable
* +---------------------------------------------------------------+
* : :
*/
By structure i mean that i has predefined 7 byte Neighbour ID, and 3 bytes Metric , 1 byte SubTLVs Length and only then comes the variable part but at least you have some bits that are defined in advanced and can not change.
Now by reading some books (mainlly H Gredler The Complete IS-IS Routing Protocol 2005 - page 296) i found 4 techniques of validating those TLV's i.e.
1) Maximum Length Checking
2) Sub-TLV Overrun Checking
3) Discrete Length Checking
4) TLV Content Pattern Checking
I can not trust what is comming from the user at all, but i have two other problems i.e. how to validate TLV where the value is a) random length/size i.e. i do have a range that value could have i.e. not smaller than 1 byte not larger then 700 kb and b) i can not execute any pattern checking on that value since it is encrypted i.e. not in readable form, thus can not execute any pattern on it.
Thus my question is: How can achieve the same goal i.e. sending tree structure within some other structure i.e. maybe key value pairs or something similar (http is using this one, there should be a reason for that).
Is the TLV way really the best choice for transferring data in the tree structure. I know that if i send that in a binary form that i will hit two rabbits with one shot i.e. when sending files such as pictures i will not need to use some funny base64 encoding etc. but what I really want is a protocol that works on L5-7 (i.e. over websocket) that will allow be to send a data in the form of a tree structure where the receiving part will be able to identify and reassemble the tree, without having to think about serialization and de-serialization parts. So what would be the second best alternative ot TLVs?, taking into account that i am working with java on one side and javasctipt on the other.