开发者

Protocol abstraction in C#

开发者 https://www.devze.com 2023-01-04 07:52 出处:网络
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 th

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.


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.


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.


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.


If you abstract something too far it gets to be useless and you have to bust open the black box to get anything done.

A "generic" container that holds sound files, images, and spreadsheets is going to be useless, because you are going to have code that deals with stuff specific to those types of data anyway, but now you're straddled with additional generic container nonsense.

0

精彩评论

暂无评论...
验证码 换一张
取 消