Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message [De]Serialization: A Design Question

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
GB
All,

I have a system that is designed to pass messages to / from third parties. I am about to write a plugin that will create messages (files) in a new format.

The format (EDINE) is well defined and documented. I will have two basic functions:

- format a message, populating values from out internal object representation
- parse a message to convert to our internal object representation

The messages are composed of segments and may include repeating groups (but note - it is not XML!).

Obviously there are a few ways to achieve this, I'd be interested to hear others views on what is best. My initial thoughts are:

- use interpreter pattern to parse and format the messages
- Very basic string manipulation (e.g. strip out various characters etc), could use RegEx as well
- Write custom [de]serialialization and attributes - much the same as the .Net XML Serialization works (not too sure on this?)
- Any other ideas?

I am using .Net 2.0. My goals for this development (in order of priority) are:

- Quick delivery
- Easily understandable / maintainable for others
- Elegant solution

Another consideration is there are different versions of this standard - I may (more than likely) have to cater for different versions.

I'd be grateful for any thoughts advice, or has anyone done something similar?

Thanks,

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
if the formatting was simple and there was exactly 1 format i would start with the regex string minipulation and refactor into an interpreter.
since there are multiple versions of the standard [oximoron? :)] then i would create a interperter for each version and a factory to create the interpors
Code:
interface Interpertor
{
   void Interpert(IObjectToInterpert objectToInterpert);
}

class VersionOneInterpertor: Interpertor
{
   void Interpert(IObjectToInterpert objectToInterpert) {}
}

class VersionTwoInterpertor: Interpertor
{
   void Interpert(IObjectToInterpert objectToInterpert) {}
}

class InterpertorFactory
{
   private IDictionary<Type, TypeOfInterpertorToCreate> interpertors = new Dictionary<Type, TypeOfInterpertorToCreate>();

   public InterpertorFactory()
   {
       interpertors[typeof(VersionOneInterceptor)] = new VersionOneInterceptor();
       interpertors[typeof(VersionTwoInterceptor)] = new VersionTwoInterceptor();
   }

   Interpertor Create<TypeOfInterpertorToCreate>() where TypeOfInterpertorToCreate : Interpertor, new()
   {
       return interpertors[typeof(TypeOfInterpertorToCreate)];
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top