473,769 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there possiblitity to portable way to serialize enum type?

Thank you for answer, but I still did not
got *how* to make serialization of enum type.

Can you provide more instructions or hint, please?

My task is to serialize enum to something like byte array,
and then load enum from that byte array to the same enum
type on other platform.

One way to do I see is:
- static cast enum to integer
- convert integer to network byte order with htonl()
- transmit the result via network to remote host
- get result and convert it to host byte order with ntohl()
- cast integer back to enum

Is it portable way? Is there any well-known
tenchnics for such kind of tasks?

Thanks for help,
Konstantin
Jul 22 '05 #1
2 4294
"Voronkov Konstantin" <be*******@yaho o.com> wrote in message
news:77******** *************** ***@posting.goo gle.com...
Thank you for answer, but I still did not
got *how* to make serialization of enum type.

Can you provide more instructions or hint, please?

My task is to serialize enum to something like byte array,
and then load enum from that byte array to the same enum
type on other platform.

One way to do I see is:
- static cast enum to integer
- convert integer to network byte order with htonl()
- transmit the result via network to remote host
- get result and convert it to host byte order with ntohl()
- cast integer back to enum

Is it portable way? Is there any well-known
tenchnics for such kind of tasks?


What you described is a way. However you're not using a function to
transform the enum, you're simply casting it to an integer.

For instance you can write a function that converts an enum to string, then
back to deserialzie, from string to enum (using a series of if/else or other
methods).

HTH,
Elias
Jul 22 '05 #2
be*******@yahoo .com (Voronkov Konstantin) wrote in message news:<77******* *************** ****@posting.go ogle.com>...
Thank you for answer, but I still did not
got *how* to make serialization of enum type.

Can you provide more instructions or hint, please?

My task is to serialize enum to something like byte array,
and then load enum from that byte array to the same enum
type on other platform.

One way to do I see is:
- static cast enum to integer
- convert integer to network byte order with htonl()
- transmit the result via network to remote host
- get result and convert it to host byte order with ntohl()
- cast integer back to enum

Is it portable way? Is there any well-known
tenchnics for such kind of tasks?

Thanks for help,
Konstantin


By example:

class RecordStream {
public:
//! Type of a record stream and database codes.
enum Type {
//! Unknown record stream type.
stUnknown = '\0',
//! Record stream generated from the external source.
stIncoming = 'i',
//! Record stream generated by the OSB.
stRegular = 'r',
//! Record stream contains error records.
stError = 'e',
//! Record stream contains filtered records.
stFilter = 'f'
};
};

RecordStream::T ype RecordStream::t oType(char c)
{
Type rc = Type(tolower(c) );
bool done = false;
switch (rc) {
case stIncoming: // fall through for all defined types
case stRegular:
case stError:
case stFilter:
case stUnknown: done = true; break;
// no default: let compiler warn
}
if (!done) rc = stUnknown;
return rc;
}

char RecordStream::t oChar(RecordStr eam::Type t)
{
int rc = t;
rc = toType(static_c ast<char>(rc));
return static_cast<cha r>(rc);
}

Note the casts in order to avoid compiler warnings.

Stephan Brönnimann
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1296
by: Fernando Callejon | last post by:
Hello, i'm trying to serialize a class with a enum property...it seems to be serializing ok, but when i try to de-serialize it throw me an error like " isn't valid for type ". someone have done this before? i'm sorry by my english
1
347
by: Voronkov Konstantin | last post by:
Hello, All! I want to ask question whether there is portable way to serialize enum type? Is it safe to threat enum as integer? Best Regards, Voronkov Konstantin
32
1723
by: Martin Vorbrodt | last post by:
Hi there. Is this code portable between platforms? Is it also 100% standard compliant? #include <iostream> using namespace std; class Point { public: enum COORDS { X = 0, Y, Z }; Point(int x, int y, int z) : _x(x), _y(y), _z(z) {}
1
2953
by: Michael | last post by:
Hi I anyone have a clue or can solve my problem I would be glad :-) Regards Michael I have a problem with creating an XML-document where the returning data from the webservice, have been serialized. In my program I am calling a webservice which then return the data to the calling program. The program then have to serialize the data and create an XML-document.
7
6542
by: Lars-Erik Aabech | last post by:
Hi! I've got problems with serializing my collections of business objects. The objects themselves serialize fine, but the collections fail. I've got the following structure: Base collection class: Derives MarshalByValueComponent Implements ICollection, IList and ISerializable Explicitly implements the IList methods as private members, (ie. int
1
15761
by: Chris Dunaway | last post by:
Suppose I have the following enum: public enum MyEnum { EnumVal1 = 1, EnumVal2 = 2, EnumVal3 = 3 } I want to serialize the enum but I want the /names/ of the enum to be stored in the .xml file, like this:
7
3548
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate." I've included the <Serializable()> attribute, but I'm still getting the same error. The class is below ... as you can see it contains a Collection, two
0
2071
by: John Manion via .NET 247 | last post by:
Long Post, thanks for your patience... I have and XML file that looks something like this: <?xml version="1.0" encoding="utf-8" ?> <Settings> <Location> <X>30</X> <Y>40</Y> </Location> <Size>
35
15285
by: dtschoepe | last post by:
Greetings. I am working on an assignment and can't seem to get the right concept for something I'm attempting to do with enum data types. I have defined the following in my code: enum color {red, blue, green, yellow, black, purple, pink}; What I am doing now is reading from a text file a string (char *). I
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.