Search code examples
c#design-patternsprotocolsfile-formatabstraction

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.


Solution

  • Most things can be wrapped in protocols - just think how much has been wrapped up in URLs. But that doesn't always mean that the structure is really abstracted into a meaningful layer. I think the variety of protocols and formats indicates that there are probably categories for which you could abstract, but not one abstraction to rule them all.

    For instance, there might be differences between accessing an IMAP mailbox and opening a ZIP file so significant that there is very little common ground.