private void decode_Response(PhotonCmdHeader cmd_hdr, BinaryReader packet) { // see func ReliableMessage() decode in... // https://github.com/broderickhyman/photon_spectator/blob/master/photon_command.go var opResponse = new ReliableMessage_Response(); opResponse.ChannelID = cmd_hdr.ChannelID; opResponse.OperationCode = packet.ReadByte(); // Operation Code opResponse.OperationResponseCode = packet.ReadUInt16(); // Operation Response Code opResponse.OperationDebugByte = packet.ReadByte(); // Operation Debug Byte opResponse.ParameterCount = packet.ReadInt16(); // Parameter Count (?? is this valid for all msg types?) Event_Photon_Cmd_Info?.Invoke("Photon Reliable Response - " + opResponse.OperationResponseCode); var parameters = new ReliableMessage_Response.Paramaters(); // decode the paramaters for (int i = 0; i < opResponse.ParameterCount; i++) { var paramID = packet.ReadByte(); // paramID PhotonParamType paramType = (PhotonParamType)packet.ReadByte(); // paramType var param_value = Decode_PhotonValueType.Decode(packet, paramType); parameters[paramID] = param_value; Event_Photon_Info?.Invoke("ParamID: " + paramID + " value: " + param_value.ToString()); } opResponse.ParamaterData = parameters; Event_Photon_ReliableResponse?.Invoke(opResponse); }
public static PhotonData_SliceType DecodeFrom_WithType(BinaryReader packet, PhotonParamType type) { var length = packet.ReadUInt16(); var acc = new List<PhotonDataAtom>(); for (int i = 0; i < length; i++) { acc.Add(Decode_PhotonValueType.Decode(packet, type)); } return new PhotonData_SliceType(type,new PhotonData_SliceValues(type, acc.ToArray())); }
public static PhotonData_SliceType DecodeFrom(BinaryReader packet) { var length = packet.ReadUInt16(); PhotonParamType value_types = (PhotonParamType)packet.ReadByte(); var acc = new List<PhotonDataAtom>(); for (int i=0;i<length;i++) { acc.Add(Decode_PhotonValueType.Decode(packet,value_types)); } return new PhotonData_SliceType(PhotonParamType.SliceType,new PhotonData_SliceValues(value_types,acc.ToArray())); }
public static PhotonDataAtom Decode(BinaryReader packet, PhotonParamType paramType) { switch (paramType) { case PhotonParamType.NilType_o: case PhotonParamType.NilType: return new PhotonData_Nil(); case PhotonParamType.BooleanType: return new PhotonData_Value<bool>(paramType, packet.ReadByte() == 1 ? true : false); case PhotonParamType.Int8Type: return new PhotonData_Value<byte>(paramType, packet.ReadByte()); case PhotonParamType.Int16Type_o: case PhotonParamType.Int16Type: return new PhotonData_Value<Int16>(paramType, packet.ReadInt16()); case PhotonParamType.Int32Type: return new PhotonData_Value<Int32>(paramType, packet.ReadInt32()); case PhotonParamType.Int64Type: return new PhotonData_Value<Int64>(paramType, packet.ReadInt64()); case PhotonParamType.Float32Type: return new PhotonData_Value<Single>(paramType, packet.ReadSingle()); case PhotonParamType.DoubleType: return new PhotonData_Value<Double>(paramType, packet.ReadDouble()); case PhotonParamType.SliceType: return PhotonData_SliceType.DecodeFrom(packet); case PhotonParamType.StringSliceType: return PhotonData_SliceType.DecodeFrom_WithType(packet, PhotonParamType.StringType); case PhotonParamType.Int8SliceType: return PhotonData_SliceType.DecodeFrom_WithType(packet,PhotonParamType.Int8Type); case PhotonParamType.Int32SliceType: return PhotonData_SliceType.DecodeFrom_WithType(packet, PhotonParamType.Int32Type); case PhotonParamType.StringType: var len = packet.ReadUInt16(); byte[] raw_data = packet.ReadBytes(len); string string_data = System.Text.Encoding.ASCII.GetString(raw_data); return new PhotonData_Value<string>(paramType, string_data); case PhotonParamType.Custom: case PhotonParamType.DictionaryType: case PhotonParamType.EventDateType: case PhotonParamType.Hashtable: case PhotonParamType.OperationResponseType: case PhotonParamType.OperationRequestType: case PhotonParamType.ObjectSliceType: return new PhotonData_NotYetParsed(paramType); default: return new PhotonData_UNRECOGNIZED(paramType); } }
public PhotonData_NotYetParsed(PhotonParamType type) { this.type = type; }
public PhotonData_UNRECOGNIZED(PhotonParamType type) { this.type = type; }
public PhotonData_SliceType(PhotonParamType type, PhotonData_SliceValues data) { this.type = type; this.data = data; }
public PhotonData_SliceValues(PhotonParamType type, PhotonDataAtom[] values) { this.type = type; this.values = values; }
public PhotonData_Value(PhotonParamType type, T data) { this.type = type; this.data = data; }