Archived

This forum has been archived. Please start a new discussion on GitHub.

how can I pass a class by icestorm ?

hello!
I meet a problem that I need get a class value from the remote client ,but I don't and cannot define the class in the in ice document because it is very complex and refer to many other class. Luckly , both of server and client have the same class.
In order slove this problem I have try many method but fail.could you help me ?
wait for your help ,thanks very much ..


for example:
#include "RootObject.h"
#include "Federate.h"
.......


class crc{
public:
RootObject* _root;
map<FederateHandle,Federate*> _Federate;
FederateHandle findFederateName(string theName);
.............

}
when the server what to get the crc from the client ? how can i do ?


ateng 2012.5.11

Comments

  • hello!
    I meet a problem that I need get a class value from the remote client ,but I don't and cannot define the class in the in slice because it is very complex and refer to many other class. Luckly , both of server and client have the same class.
    In order slove this problem I have try many method but fail.could you help me ?
    wait for your help ,thanks very much ..


    for example:
    #include "RootObject.h"
    #include "Federate.h"
    .......


    class CRC{
    public:
    RootObject* _root;
    map<FederateHandle,Federate*> _Federate;
    FederateHandle findFederateName(string theName);
    .............

    }
    CRC crc;
    .........
    If the server want to get the crc from the client , how can i do ?


    ateng 2012.5.12
  • I have solve the problem by pass the value by bytes.
    beacause I find this method:


    Since the purpose of this ZeroC Labs project is to integrate Protocol Buffers with Ice, let's explore how we can use the protocol buffers version of Person. Our first step is to change the Slice definition of Person:

    // Slice
    module Demo {
    sequence<byte> Person;

    interface Transporter {
    void sendPerson(Person p);
    };
    };Person is now defined as a byte sequence, which essentially means that Ice will treat values of type Person as opaque blobs. Consequently, any time the application wants to transmit a Person value, it must manually convert the object to and from the format that Ice expects. Fortunately, the default representation (or mapping) of a byte sequence in the target languages makes this process relatively straightforward. In C++, a byte sequence maps to std::vector<Ice::Byte>, in Java it maps to a native byte array, and in Python it maps to a string.

    The example below shows how we can serialize and send a Protocol Buffers Person in C++:

    // C++
    tutorial::Person p;
    p.set_id(3);
    p.set_name("Fred Jones");
    std::vector<Ice::Byte> data(p.ByteSize());
    if (!p.SerializeToArray(&data[0], data.size()))
    assert(false);
    transporter->sendPerson(data);After instantiating a Person and initializing the required fields, the code serializes the value into a byte sequence and passes it as the parameter to sendPerson. A similar process is necessary on the receiving side to convert the value from a byte sequence back into a Person.


    ZeroC Labs: Protocol Buffers

    it is realy a good idea for other people who may meet the same problem as me.
    thank you very much !

    ateng 2012 .5.12