示例#1
0
文件: UnitTest1.cs 项目: Astn/ekati
        public void SizePrefixedBytesWorks()
        {
            var pw    = new PaddedWrapper();
            var data1 = new byte[10];
            var data2 = new byte[10];

            Array.Fill(data1, (byte)0xFF);
            Array.Fill(data2, (byte)0x11);

            var spb  = new SizePrefixedBytes();
            var spb2 = new SizePrefixedBytes();

            spb.data  = new byte[10 + sizeof(int)];
            spb2.data = new byte[10 + sizeof(int)];
            BitConverter.TryWriteBytes(spb.data, 10);
            BitConverter.TryWriteBytes(spb2.data, 10);
            Array.Copy(data1, 0, spb.data, sizeof(int), data1.Length);
            Array.Copy(data2, 0, spb2.data, sizeof(int), data1.Length);

            if (!pw.CanPackIn(spb2.data))
            {
                pw = pw.CopyToBigger(spb2.data.Length);
            }
            pw.initFrom(spb);
            pw.PackIn(spb2.data);
        }
示例#2
0
        public async ValueTask <OperationStatus> UpsertNode(Node node)
        {
            CheckDisposed();
            var id    = node.Id;
            var attrs = node.Attributes;
            var bytes = attrs.ToSizePrefixedBytes();
            var pw    = new PaddedWrapper();

            pw.initFrom(bytes);
            var stat = await _session.UpsertAsync(ref id, ref pw, Empty.Default, Interlocked.Increment(ref _serial));

            while (stat.Status == Status.PENDING)
            {
                stat = await stat.CompleteAsync();
            }
            return((OperationStatus)stat.Status);
        }