You need to write a length before writing each message, so that when you
read them on the receiving end you can separate the messages before parsing
them.

On Sat, Sep 27, 2008 at 10:17 AM, <[EMAIL PROTECTED]> wrote:

>
> Hello again,
>
> I have another problem concerning repeated fields:
>
> The same example as above, every client sends continuously a Player
> message to the server.
> The server continuously generates a Playerlist message taking the
> newest Player's and sends one to every client.
>
> The problem is, when I parse a Playerlist on the client side, and
> there are more than one Playerlists in the buffer (probably all from
> the same player) I get one Playerlist with multiple players in it.
> I now realized that ParseFrom.... does actually merge messages and
> repeated fields are appended. This is not desired in my case, I just
> need the last one.
> Is there a way to disable the appending of repeated fields when
> parsing a buffer or is my idea for distributing the players anyway a
> bad solution ?
>
> Regards,
> Rico
>
> On Sep 24, 7:04 pm, [EMAIL PROTECTED] wrote:
> > Hello Kenton,
> >
> > Thanks a lot! That is exactly what I was looking for!
> >
> > Regards,
> > Rico
> >
> > On 24 Sep., 18:56, "Kenton Varda" <[EMAIL PROTECTED]> wrote:
> >
> > > Playerlist also has methods:
> > > const RepeatedPtrField<Player>& player() const;
> > > RepeatedPtrField<Player>* mutable_player();
> >
> > > RepeatedPtrField is documented here:
> >
> > >http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.
> ..
> >
> > > It has methods which allow you to add an existing object without
> copying
> > > (look under "Advanced memory management).  Of course, if you use these,
> then
> > > the Player objects will become property of the Playerlist.  You will
> have to
> > > be careful to take ownership back from the list later by repeatedly
> calling
> > > ReleaseLast().
> >
> > > Also note that every protocol message has a CopyFrom() method which can
> be
> > > used to copy an entire message object, so you would not have to call
> > > set_id(), set_x(), etc. manually.
> >
> > > On Wed, Sep 24, 2008 at 8:01 AM, <[EMAIL PROTECTED]> wrote:
> >
> > > > Hello,
> >
> > > > I have a question concerning the repeated fields. I'll start with an
> > > > example:
> >
> > > > message Player {
> > > >  required int32 id = 1;
> > > >  required int32 x =2;
> > > >  required int32 y=3;
> > > > }
> >
> > > > message Playerlist{
> > > >  repeated Player player= 1;
> > > > }
> >
> > > > I have a server and get Player's from different clients and hold them
> > > > in a map (this map is updated all the time). After a certain time I
> > > > want to get all Players, create a Playerlist and send it to all
> > > > clients. The Playerlist however has just a method
> >
> > > > Player* add_player();
> >
> > > > I will have to copy all the Player's I've already created :
> >
> > > > Player* newP = playerlist.add_player();
> > > > newP->set_id( playerFromMap->id() );
> >
> > > > Isn't there a better way to do this?
> >
> > > > Regards
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to