Explain how to use byte code on PhotonPeer.RegisterType()

This link doesn't explain what byte code that we need to pass has to be. Can I get clarification? Why (byte)'W' in this example? What are the byte codes that are already being used by the framework? Thanks.

The example in this link is very confusing. The methodshort SerializeVector2(StreamBuffer outStream, object customobject)does not conform to the delegate signaturepublic delegate byte[] SerializeMethod(object customObject);

I'm integrating photon with our game.When I had stuck on custom serialization, I decided to use C# BinarySerializer, because we have much custom types (C# need only serialization attribute in most cases) and it isn't easy to define methods for all those types.Today we have perform performence tests and we had discovered, that BinarySerializer is sending redundant data.We decided to use photon custom serialization.

I had make and register methods for GameObject, Component and Vector3.We have more custom types, but I was curious what will happen (C# BinarySerializer needs only those 3 methods, cause other types had serialization flag).

I have run main client (create room) and join to this room by other client.Main client perform PhotonNetwork.Instantiate, passed argument was prefab with PhotonView and few components, that implements IPunObservable.When prefab appears (I gues, that there is chance that OnPhotonSerializeView was performed on that prefab), on the main client side, that error apears (edit - it apears always, this is not some kind of connection problem):

I gues, that this error apears because I miss some serialization methods, but, normaly there is error (or warning) about serialization and it informs me what have i miss (I have seen it once).Can someone explain it to me, why there is no error about serialization, and why that error apears?

I'm trying to add custom serialization method for class "a".Class "a" contains Vector3 field, which I need to serialize.I want use Vector3 serialization method to achieve that (DRY standard), which is defined in CustomTypes, but this method is private.I don't wan't to modify code provided by Exit Games (CustomTypes.cs and PhotonNetwork.cs - where CustomTypes.Register() is called - are provided by Exit Games).

How can I provide serialization method for class "a", without breaking DRY standard or modify Exit Games code?Is there any method, that can I call, for already defined custom types? It would be usefull, because calling serialization method directly, also isn't perfect idea... its only acceptable.Something like "Protocol.Serialize/outStream.Write(Registered type that photon can serialize)"

Edit: I need also to serialize String field in class "a", photon can serialize that type, but I'm forced to conver string to bytes on "my own hand"? Seriously?

I would like to notice, that:- serialization methods in "CustomTypes" class are private, but buffors associated with those methods, are public XD - there is no logic in that.- CustomTypes.Register() is called from Exit Games code - it's bad. Custom types are tool for developer, so developer should decide about custom types registration.- Using char, to register custom types, is rly, rly, rly bad - developer have to remember, which chars was used, it should be done like this (without handling chars):- Your code section (forum) is creepy- When i use post edit twice, my post vanish (when i click accept edit). It happens 3 times for me, its rly annoying. I'm writing post by 15-30 minutes (with editions) and... booom vanish, destroy, my 30 minutes goes to trash (there is hack for it, you have to press cancel and somehow post is restored from cache, but you have to copy it and post again).Bug screen shot:

I have figur out the solution, but there is huuge lack of documentation.There is method, that allow me, to serialize object, that photon knows (Protocol.Serialize (Object o)) - no documentation.There is also no documentation, about custom serialization methods parameters (for example length in deserialization), the same about StreamBuffer.

My today work was guessing, guessing and again guessing - no documentation...

Maybe my boss, will post code here (its is his decision). That code should be provided with photon...

@Jeanfabre - I had check that post. Its something new for me, I was thinking that there is only "stream way", to serialize custom objects.It still isn't clear for me, how it works - I can define serialization method for Vector3 using "stream way", and next try, to use Protocol.Serialize(Object o), which isn't "stream way".I guess, that "stream way" and "byte way" are not compatibile and there will be redundant gc (Photon need to create stream only for single method use)?

Edit:Two things:- There is no documentation, about that Photon is using Equals method, on custom type, to decide if it should be serialized or not (if it wasn't change). I have stuck on it, because I was thinking that this mechanism is working after serialization (based on byte array for e.g) and default equals method was not suitable for my case...- There is no documentation, about that Photon isn't perform serialization in the same line, when you call PhotonStream.SendNext. It causes races condition in my case (I was clearing queue right after that call).- You should copy object, if you wan't to compare it by equals. Curently, I'm reciving "this" reference in my Equals method - creepy solution. I will have to use custom serialization methods, before I will pass my object to photon. Consider using hashes...

yes, the problem is complex because there is yet another factor coming into play with streaming data where the stream is highly efficient at not sending a value that hasn't changed, so it is justified imo that you have two ways of serializing, one where you get the whole object within RPC data where you have no history of it and so you send everything, and one with streaming where it internally efficiently only send what has changed.

as for GC, I am not sure what you mean here because only one serialization technic is used at a time, for a given context, so there are no redundant GC. Photon Creates a stream for sending data to the server yes, but it doesn't create an extra stream because you want to serialize, it works the opposite way, photon detects you have registered a class.

to be clear: the registration and serialization will work as well for streaming data, simply use Stream.SendNext and Stream.ReceiveNext passing your custom class and all will be well.

full component below ( don't forget to observe that component for data to be streamed)

@jeanfabre its clear for me, that best way to sync is send only changes - its ok. I'm just telling you, that using equeals method, on objects without copying it, meakes high risk of this.equals(this) case, which will always return true (even if someone will override this method properly), even if content of some object will change.You should inform developer, that he shouldn't use serialization methods with not copied reference types or use hashes insted of equals.To by clear, consider this example:

-Serialization methods for MyDataAgregationClass and it registration here- (implementation is not important here)

For this case, data will be send only once, even if mdac.someData will change.

"Photon Creates a stream for sending data to the server yes, but it doesn't create an extra stream because you want to serialize"I'm only guessing. Its clear, that stream is created only once (in typical case), but what if I will use "Protocol.Serialize (-Type x object-);" huge ammount of times in other custom serialization methods? (I have defined serialization methods for type x, by the "stream way", so they need stream passed as a parameter).For each call of "Protocol.Serialize (-Type x object-);", photon needs to pass some stream, to my custom serialization methods - I'm guessing, that photon needs to create that stream, if there is no context of serialization (if you use "Protocol.Serialize (-Type x object-);", no context is passed).

Sorry, I am lost at what you trying to explain. there is no equal statement in the component I sent you, can you be more precise, maybe with pointing at a code line and giving a counter example? We always strive to improve this framework, so if we can change something to improve, we'll definitly consider it.

the serialization protocole is meant to be used by Photon, if you plan on using this serialization system outside Photon usage, then maybe you should look into your own serialization system. If you make custom usage of this protocole, Photon will nto be the one initiating the serialization process. so Photon will not create a new sream, Photon Only create a new stream when it needs to send/receive data.

4360 line in NetworkingPeer.cs - there is equal statement.In your case, everything is fine, because you are creating new CustomClassTest, in each OnPhotonSerializeView.

I'm using Protocol.Serialize in custom serialization methods (for Photon), is that "outside Photon usage"?If i have class, which contains Vector3 field, I'm not implementing whole Vector3 serialization again, but just using Protocol.Serialize(vector3FieldFromMentionedClass).As you can see, I'm not passing to that method any serialization context (stream in this case), but Vector3 serialization methods must get it in parameter - how it works? Where that stream comes from? Will it be the same stream instance, if I will call Protocol.Serialize(Vector3) three times?

Outside usage was meant to say if you are manually calling serialization, but if you have registered your types for serialization, then it falls into photon usage yes, as it will be Photon internals that will call for serializations on your custom class when required.

The Stream comes from Photon Internal handling of data coming in and out of photonViews.

Maybe you could provide a sample showing how you use your class and how you feed it to the photonView stream? then I'll look at it and be able to help some more.

Typically, we do need an equal statement because when we find that the content is the same we skip it and thus saves a lot of bandwidth, which cut down costs of hosting as well as improve networking and allow you to do more, if you create a custom class, you are also responsible for creating the right set of methods to take equal statements in consideration, you are doing this already right?