private static PitayaError CreatePitayaError(PitayaBindingError errorBinding, PitayaSerializer serializer) { var rawData = new byte[errorBinding.Buffer.Len]; Marshal.Copy(errorBinding.Buffer.Data, rawData, 0, (int)errorBinding.Buffer.Len); if (serializer == PitayaSerializer.Protobuf) { Error error = (Error)ProtobufSerializer.Decode(rawData, typeof(Error), serializer); return(new PitayaError(error.Code, error.Msg, error.Metadata)); } var jsonStr = Encoding.UTF8.GetString(rawData); var json = SimpleJson.SimpleJson.DeserializeObject <Dictionary <string, object> >(jsonStr); var code = (string)json["code"]; var msg = (string)json["msg"]; Dictionary <string, string> metadata; if (json.ContainsKey("metadata")) { metadata = (Dictionary <string, string>)SimpleJson.SimpleJson.CurrentJsonSerializerStrategy.DeserializeObject(json["metadata"], typeof(Dictionary <string, string>), new Dictionary <string, string>()); } else { metadata = new Dictionary <string, string>(); } return(new PitayaError(code, msg, metadata)); }
public void OnUserDefinedPush(string route, byte[] serializedBody) { object decoded; if (_typePushSubscriber.HasType(route)) { var type = _typePushSubscriber.GetType(route); decoded = ProtobufSerializer.Decode(serializedBody, type, PitayaBinding.ClientSerializer(_client)); } else { decoded = JsonSerializer.Decode(serializedBody); } _eventManager.InvokeOnEvent(route, decoded); }
//---------------Pitaya Listener------------------------// public void OnRequestResponse(uint rid, byte[] data) { object decoded; if (_typeRequestSubscriber.HasType(rid)) { var type = _typeRequestSubscriber.GetType(rid); decoded = ProtobufSerializer.Decode(data, type, PitayaBinding.ClientSerializer(_client)); } else { decoded = JsonSerializer.Decode(data); } _eventManager.InvokeCallBack(rid, decoded); }