Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        //---------------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);
        }