Esempio n. 1
0
 /// <summary>
 /// <para>DEPRECATED. Use <see cref="Notify(string, object, int)"/> instead.</para>
 /// </summary>
 public void Notify(string route, int timeout, IMessage msg)
 {
     ProtobufSerializer.SerializationFormat format = _binding.ClientSerializer(_client);
     NotifyInternal(route, msg, SerializerFactory.CreateProtobufSerializer(format), timeout);
 }
Esempio n. 2
0
 public IPitayaSerializer CreateProtobufSerializer(ProtobufSerializer.SerializationFormat format)
 {
     return(new ProtobufSerializer(format));
 }
Esempio n. 3
0
 /// <summary>
 /// <para>DEPRECATED. Use <see cref="Request&lt;TResponse&gt;(string, object, Action&lt;TResponse&gt;, Action&lt;PitayaError&gt;, int)"/> instead.</para>
 /// </summary>
 public void Request <T>(string route, IMessage msg, int timeout, Action <T> action, Action <PitayaError> errorAction)
 {
     ProtobufSerializer.SerializationFormat format = _binding.ClientSerializer(_client);
     RequestInternal(route, msg, timeout, SerializerFactory.CreateProtobufSerializer(format), action, errorAction);
 }
Esempio n. 4
0
        private static PitayaError CreatePitayaError(PitayaBindingError errorBinding, ProtobufSerializer.SerializationFormat format)
        {
            var rawData = new byte[errorBinding.Buffer.Len];

            Marshal.Copy(errorBinding.Buffer.Data, rawData, 0, (int)errorBinding.Buffer.Len);

            if (format == ProtobufSerializer.SerializationFormat.Protobuf)
            {
                Error error = new ProtobufSerializer(format).Decode <Error>(rawData);
                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));
        }