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

  • Home
  • SEARCH
  • 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 6095117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:46:34+00:00 2026-05-23T12:46:34+00:00

I’m trying to decide if this is not very nice, or not. Basically, I

  • 0

I’m trying to decide if this is not very nice, or not.
Basically, I am writing a client server system. To make it easier and less error prone, I decided all requests/responses/etc. between client and server should be defined as structs in a shared library that is used by both the client and server, and then have a serialization layer that knows how to serialize the structs (again used by both).

For example:

Shared Library:

requestparamstructs.h

#ifndef REQUEST_PARAMS_H
#define REQUEST_PARAMS_H

struct CreateUserRequestParams
{
    std::string name;
    std::string address;
    std::string username;
    int age;
    ..
    ..
};

struct CreateItemRequestParams
{
    std::string name;
    std::string description;   
};

..
..

#endif

And then somewhere in my client:

client.h

CreateUserRequestParams p;
p.name = "Foo";
p.address = "Somewhere";
p.username = "mrfoo";

Request<CreateUserRequestParams> myRequest(p);

client.queueRequest(myRequest);

And then the server receives the request, creates the appropriate struct with a factory and unserializes and performs whatever it needs to do.

Now initially I was putting each struct in a seperate file, but this seems like overkill.

Does putting these structs in a single header like this give you convulsions? The only thing missing I guess is a default constructor to initialise the variables which then makes it more of a class, which then feels like it should be separate files.

Bear in mind I’m going to need to create a lot of these..

Thanks!

EDIT:

1) Just to clarify, this is a client server system that communicates via TCP/IP. There’s no shared memory involve. The “shared library” is just code shared in a .lib file and linked in. All the common code that both the client and server can use is put here.

2) Parameterized templates would be great, I think, unfortunately VS2010 does not support variadic templates. At one point I was thinking of something like this:

template <Protocol::ClientRequest RequestCode, typename P1>
class RequestP1 : public Request
{
public:
    RequestP1() : Request(RequestCode) {}
    RequestP1(P1 p1) : Request(RequestCode), m_p1(p1) {}
    virtual void serialize(IArchive &ar)
    {
        serialize(ar, m_p1);
    }
    P1 m_p1;
};

template <Protocol::ClientRequest RequestCode, typename P1, typename P2>
class RequestP2 : public Request
{
public:
    RequestP2() : Request(RequestCode) {}
    RequestP2(P1 p1, P2 p2) : Request(RequestCode), m_p1(p1), m_p2(p2) {}
    virtual void serialize(IArchive &ar)
    {
        serialize(ar, m_p1);
        serialize(ar, m_p2);
    }
    P1 m_p1;
    P2 m_p2;
};

..
..

Which would allow me to do this:

typedef RequestP1<Protocol::CreateUser, CreateUserRequestParams> RequestCreateUser;

OR specifying the actual params (just showing the first two params here, name and address):

typedef RequestP1<Protocol::CreateUser, std::string, std::string> RequestCreateUser;

Hope that makes sense..

  • 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-23T12:46:35+00:00Added an answer on May 23, 2026 at 12:46 pm

    Does putting these structs in a single header like this give you convulsions?

    No.

    Assuming that your server and your client both use most (if not all) of the requests (and hence the *Params objects are used on both sides), the only thing that would make me consider putting them into separate files is the type of their fields.

    As long as your parameter objects just have primitives or common types like std::string, I’m fine. However, if you happen to introduce a message which uses types which are not defined in the standard library (e.g. a QPixmap of Qt or the like), I would consider moving that message (and other messages with the same dependencies) into a separate file so that only those clients which need to use those parameters have to pull in the dependencies. I suspect that this is unlikely in your case, so putting all of the Param structs into one file is fine IMHO.

    However, if it turns out that there are huge differences in the set of *Param objects used by different clients, I’d consider putting related groups into separate files to reduce compile-time dependencies. Otherwise, adding a new Param type to a group means recompiling all clients – even those, which don’t use the corresponding message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string

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.