Esempio n. 1
0
        public static byte[] Serialize(RootUst rootUst, bool isLineColumn, bool compress, ILogger logger,
                                       out int writeSize)
        {
            var textSpanSerializer = TextSpanSerializer.CreateWriter();

            textSpanSerializer.IsLineColumn = isLineColumn;
            textSpanSerializer.Logger       = logger;

            var sourceFileSerializer = FileSerializer.CreateWriter();

            sourceFileSerializer.Logger = logger;

            var rootUstSerializer = new RootUstMessagePackSerializer
            {
                textSpanSerializer = textSpanSerializer,
                fileSerializer     = sourceFileSerializer
            };

            if (buffer == null)
            {
                buffer = new byte[ushort.MaxValue + 1];
            }

            writeSize = rootUstSerializer.SerializeRootUst(ref buffer, 0, rootUst);

            if (compress)
            {
                var result = LZ4MessagePackSerializer.ToLZ4Binary(new ArraySegment <byte>(buffer, 0, writeSize));
                return(result);
            }

            return(buffer);
        }
        protected int ExecuteHttpSql(string sql, dynamic data = null)
        {
            MemoryStream ms  = new MemoryStream();
            CryptoStream cst = new CryptoStream(ms, _cryptoTransform, CryptoStreamMode.Write);

            StreamWriter sw = new StreamWriter(cst);

            sw.Write(sql);
            sw.Flush();
            cst.FlushFinalBlock();
            sw.Flush();

            string cryptoSql = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
            var    json      = JsonConvert.SerializeObject(new
            {
                Sql = cryptoSql,
                Dt  = data,
                D   = Core.Infrastructure.Database.Database.MySql
            });

            var encodingBytes = Encoding.UTF8.GetBytes(json);
            var bytes         = LZ4MessagePackSerializer.ToLZ4Binary(new ArraySegment <byte>(encodingBytes));
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, _api);

            //httpRequestMessage.Headers.Add("DotnetSpiderToken", Env.HttpCenterToken);
            httpRequestMessage.Headers.Add("DotnetSpiderToken", Env.HubServiceToken);
            httpRequestMessage.Content = new ByteArrayContent(bytes);
            var response = HttpSender.Client.SendAsync(httpRequestMessage).Result;

            response.EnsureSuccessStatusCode();

            return(Convert.ToInt16(response.Content.ReadAsStringAsync().Result));
        }
Esempio n. 3
0
        public void Serialize(object message, Stream stream, Type type)
        {
            using (var memStream = new MemoryStream())
            {
                _serializer.Serialize(message, memStream);

                memStream.TryGetBuffer(out var buffer);

                var lz4Buffer = LZ4MessagePackSerializer.ToLZ4Binary(buffer);

                stream.Write(lz4Buffer, 0, lz4Buffer.Length);
            }
        }