示例#1
0
        public static byte[] EncodeMsg(Thrift.Protocol.TBase reqMsg)
        {
            var tmem  = new Thrift.Transport.TMemoryBuffer();
            var proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //proto.WriteMessageBegin(new Thrift.Protocol.TMessage("ff::RegisterToBrokerReq", Thrift.Protocol.TMessageType.Call, 0));
            reqMsg.Write(proto);
            //proto.WriteMessageEnd();
            byte[] byteData = tmem.GetBuffer();
            return(byteData);
        }
示例#2
0
 /// <summary>
 /// Gets bytes that represents the current object.
 /// </summary>
 /// <returns></returns>
 public static byte[] GetBytes <T>(T tobj) where T : TAbstractBase
 {
     using (var trans = new Thrift.Transport.TMemoryBuffer())
     {
         using (var oprot = new Thrift.Protocol.TBinaryProtocol(trans))
         {
             tobj.Write(oprot);
             return(trans.GetBuffer());
         }
     }
 }
示例#3
0
        public static bool decodeMsg <T>(T reqMsg, string strData) where T : Thrift.Protocol.TBase
        {
            byte[] data  = System.Text.Encoding.UTF8.GetBytes(strData);
            var    tmem  = new Thrift.Transport.TMemoryBuffer(data);
            var    proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //var msgdef = new Thrift.Protocol.TMessage("ffthrift", Thrift.Protocol.TMessageType.Call, 0);
            //proto.ReadMessageBegin();
            reqMsg.Read(proto);
            //proto.ReadMessageEnd();
            return(true);
        }
示例#4
0
        public static string encodeMsg <T>(T reqMsg) where T : Thrift.Protocol.TBase
        {
            var tmem  = new Thrift.Transport.TMemoryBuffer();
            var proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //proto.WriteMessageBegin(new Thrift.Protocol.TMessage("ff::RegisterToBrokerReq", Thrift.Protocol.TMessageType.Call, 0));
            reqMsg.Write(proto);
            //proto.WriteMessageEnd();
            byte[] byteData = tmem.GetBuffer();
            string strRet   = System.Text.Encoding.UTF8.GetString(byteData, 0, byteData.Length);

            return(strRet);
        }
示例#5
0
        /// <summary>
        /// Creates a new instance from the byte array provided.
        /// </summary>
        /// <param name="bytes"></param>
        public static T CreateObject <T>(byte[] bytes) where T : TBase, new()
        {
            using (var trans = new Thrift.Transport.TMemoryBuffer(bytes))
            {
                using (var oprot = new Thrift.Protocol.TBinaryProtocol(trans))
                {
                    var tobj = new T();

                    tobj.Read(oprot);
                    return(tobj);
                }
            }
        }
示例#6
0
        public static bool DecodeMsg(Thrift.Protocol.TBase reqMsg, byte[] data)
        {
            if (data.Length == 0)
            {
                return(false);
            }
            var tmem  = new Thrift.Transport.TMemoryBuffer(data);
            var proto = new Thrift.Protocol.TBinaryProtocol(tmem);

            //var msgdef = new Thrift.Protocol.TMessage("ffthrift", Thrift.Protocol.TMessageType.Call, 0);
            //proto.ReadMessageBegin();
            reqMsg.Read(proto);
            //proto.ReadMessageEnd();
            return(true);
        }