Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:10:37+00:00 2026-05-31T04:10:37+00:00

Signalling Protocols make frequent use of Enumerated types which have well defined integer values.

  • 0

Signalling Protocols make frequent use of Enumerated types which have well defined integer values. E.g.

public enum IpHdrProtocol {

TCP(6),
SCTP(132),
MPLS(137);
int Value;

IpProtocol(int value) {
    Value = value;
}

I am trying to find a way of de-serializing such a value to its corresponding Enumerated type using just the Enum Class type and the integer value for the instance.

If this requires a Static getEnumFromInt(int) function to be added to each enum then how can this ‘interface’ be defined so enum authors can ensure their enums can be serialized.

How can this best be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:10:38+00:00Added an answer on May 31, 2026 at 4:10 am

    Not sure on how far you want to go, but here is some pretty ugly code to be the less invasive on your enum:

    public class Main {
    
        public enum IpHdrProtocol {
    
            TCP(6), SCTP(132), MPLS(137);
            int Value;
    
            IpHdrProtocol(int value) {
                Value = value;
            }
        }
    
        public static void main(String[] argv) throws NoSuchMethodException, IllegalArgumentException, InvocationTargetException,
                IllegalAccessException, SecurityException, NoSuchFieldException {
            System.err.println(getProtocol(6));
            System.err.println(getProtocol(132));
            System.err.println(getProtocol(137));
        }
    
        private static IpHdrProtocol getProtocol(int i) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
                SecurityException, NoSuchFieldException {
            Field f = IpHdrProtocol.class.getDeclaredField("Value");
            Method m = IpHdrProtocol.class.getMethod("values", null);
            Object[] invoke = (Object[]) m.invoke(null, null);
            for (Object o : invoke) {
                if (!f.isAccessible()) {
                    f.setAccessible(true);
                }
                if (((Integer) f.get(o)).intValue() == i) {
                    return (IpHdrProtocol) o;
                }
            }
            return null;
        }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With a pthread_cond_t we have to associate a mutex, When signalling the condition I've
I have a a property defined as: [XmlArray(delete, IsNullable = true)] [XmlArrayItem(contact, typeof(ContactEvent)), XmlArrayItem(sms,
I have a .NET 2.0 application that uses WSE 3.0 to make web service
We have a macro for signalling errors in a common utilities library that goes
I have a Windows service which performs a fairly long running task. At the
I have a simple application which spawns two threads and assigns one with a
What's the best way to use NaNs in C++? I found std::numeric_limits<double>::quiet_NaN() and std::numeric_limits<double>::signaling_NaN()
How to implement waitAny on more than 64 handles? I have simple problem, i
I have a problem that I don't know how to solve. I have have
I have a Windows service that has a number of threads that all need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.