Re: ProtoContract applied to structs

2009-08-18 Thread martin

Damn that's a shame, I need to minimise allocations in my current
system (it's networking for games, and I eventually plan to port it to
the Xbox using XNA, and the xbox GC isn't so great)

THanks for the help Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: ProtoContract applied to structs

2009-08-18 Thread Marc Gravell

Part of the problem here is that I can't think of a clean way to do it
that doesn't go mad with boxing, or losing struct changes. I'm
guessing that for xna you have mutable structs, so immutability isn't
necessarily an issue, but then I need lots of ref instead... Fun...

Also; note that the CF version has some... quirks at the moment for
complex models; there is a plan to address this, but it is a lot of
work. The problem seems to be in inherent limitation of CF and
generics.

Marc

On Aug 18, 3:57 pm, martin martindev...@gmail.com wrote:
 Damn that's a shame, I need to minimise allocations in my current
 system (it's networking for games, and I eventually plan to port it to
 the Xbox using XNA, and the xbox GC isn't so great)

 THanks for the help Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: ProtoContract applied to structs

2009-08-17 Thread Marc Gravell

(oops, ignore the double-click!)

From ProtoContract, I'm taking this to be a protobuf-net question.

No, it doesn't currently offer a way to serialize structs; the main
reason for this being that structs should pretty-much always be
immutable, which makes a reflection-based API (such as protobuf-net)
very tricky.It could *perhaps* be possible to automate something if
there is always a constructor with parameter names/types a 100% match
to the designated members, but it isn't something I've prioritised.

Possible workarounds at the moment:
 - use a class
 - use a private serialization member that returns a calss-based DTO
for your data
 - use private serialization members that represent your struct

For an example of the second (although I'd need to check whether it
calls the setter when a non-null object is found):

struct Foo {
public Foo(string name) {this.name = name;}
private readonly string name;
public string Name {get {return name;}}
}
[ProtoContract]
class FooDto {
[ProtoMember(1)]
public string Name {get;set;}
}
[ProtoContract]
class MyMessage {
public Foo SomeValue {get;set;}

[ProtoMember(1, Name=SomeValue)]
private FooDto SomeValueDto {
get { return new FooDto { Name = SomeValue.Name }; }
set {
if(value == null) { /* up to you... */ }
else { SomeValue = new Foo(value.Name); }
}
}
}

Or an example of the third bullet:

[ProtoContract]
class MyMessage {
public Foo SomeValue {get;set;}

[ProtoMember(1, Name=SomeValueName)]
private string SomeValueName {
get { return SomeValue.Name; }
set { SomeValue = new Foo(value); /* set all other vals
etc*/ }
}
}



Beyond that, nothing at the moment. Simply: custom structs don't
happen anywhere *near* as much as classes, and due to their nature
they are a bit of a pain to deal with in code, unless you are using
code-gen to create them.

Marc

On Aug 18, 3:43 am, martin martindev...@gmail.com wrote:
 It can't be done, which is a shame, is there a particular reason for
 this and is there some way around it? (besides the obvious one of
 turning my struct into a class)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---