Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol abstraction in C#

There are dozens of network protocols and file formats (WAV, TCP, BMP, etc. etc.)

Is there a solution available to create an abstraction layer between the implementation of a protocol and the code that uses the resulting data?

Take a WAV file. A software component could contain logic to identify chucks and parse them into classes. The user of this component would not need to know whether the number of channels is stored in two or four bytes.

The WAV file format specification is not all the different from hundreds of other formats and protocols, so why not make a generic solution? To create an even better abstraction, the protocol specification could be stored in XML. I've had no luck finding anything like this. Can you point me in the right direction?

EDIT: This clearly is not a problem that is easily communicated over a post. The current answers are not really what I'm looking for, but I'd like to thank everyone for at least giving it a shot.

like image 351
Matt Avatar asked Dec 28 '25 16:12

Matt


2 Answers

This sounds a lot like generalisation gone too far. Most of these formats and protocols are so different from eachother that they have little more in common than being stored in a file.

I.e. there are far more differences commonalities between these formats, and most commonalities are already abstracted away by standard libraries and/or the OS. Thus this doesn't exactly look like a very practical idea.

Edit: PS Have a look at http://www.codinghorror.com/blog/2004/12/it-came-from-planet-architecture.html because this feels very much like trying to play the architecture astronaut.

like image 105
Giel Avatar answered Dec 30 '25 04:12

Giel


Unless this is for academic purposes, I do not think that such an abstraction layer would be a good idea.

Depending on the format and amount of data it would significantly degrade performance to the point where it would be better to go for a native implementation. Also, Using XML for the specification would make your performance problems even worse.

like image 26
Adrian Grigore Avatar answered Dec 30 '25 04:12

Adrian Grigore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!