Пример #1
0
 public int Compare(WindowKeyBytes x, WindowKeyBytes y)
 {
     var bytes1 = x.Get;
     var bytes2 = y.Get;
     using (var buffer1 = ByteBuffer.Build(bytes1))
     {
         using(var buffer2 = ByteBuffer.Build(bytes2))
         {
             var key1 = buffer1.GetBytes(0, bytes1.Length - WindowKeyHelper.SUFFIX_SIZE);
             var key2 = buffer2.GetBytes(0, bytes2.Length - WindowKeyHelper.SUFFIX_SIZE);
             int compareKey = BytesComparer.Compare(key1, key2);
             if (compareKey == 0)
             {
                 long ts1 = buffer1.GetLong(bytes1.Length - WindowKeyHelper.SUFFIX_SIZE);
                 long ts2 = buffer2.GetLong(bytes2.Length - WindowKeyHelper.SUFFIX_SIZE);
                 int compareTs = ts1.CompareTo(ts2);
                 if (compareTs == 0)
                 {
                     int seq1 = buffer1.GetInt(bytes1.Length - WindowKeyHelper.TIMESTAMP_SIZE);
                     int seq2 = buffer2.GetInt(bytes2.Length - WindowKeyHelper.TIMESTAMP_SIZE);
                     return seq1.CompareTo(seq2);
                 }
                 else
                     return compareTs;
             }
             else
                 return compareKey;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 验证握手数据包
        /// </summary>
        /// <param name="handshake">握手数据包</param>
        /// <param name="key">密钥</param>
        /// <param name="iv">初始化向量</param>
        /// <returns>如果验证成功返回true;否则返回false</returns>
        public static bool VerifyHandshake(byte[] handshake, byte[] key, byte[] iv)
        {
            DictNode node = (DictNode)BEncode.Decode(handshake);

            byte[] handshakeKey = ((BytesNode)node["key"]).ByteArray;
            byte[] handshakeIV  = ((BytesNode)node["iv"]).ByteArray;
            return(BytesComparer.Compare(handshakeKey, key) && BytesComparer.Compare(handshakeIV, iv));
        }
        public void test()
        {
            BytesComparer comparer = new BytesComparer();
            var           serdes   = new StringSerDes();
            var           bytes    = serdes.Serialize("test", new Confluent.Kafka.SerializationContext());
            long          to       = DateTime.Now.GetMilliseconds();

            byte[] maxSuffix = ByteBuffer.Build(12)
                               .PutLong(to)
                               .PutInt(int.MaxValue)
                               .ToArray();

            var bytes2 = OrderedBytes.UpperRange(Bytes.Wrap(bytes), maxSuffix);
            var bytes3 = OrderedBytes.LowerRange(Bytes.Wrap(bytes), new byte[12]);
            int r      = comparer.Compare(bytes2, bytes3);
        }
Пример #4
0
        public static Signature FromBytes(byte[] bytes)
        {
            if (bytes is null)
            {
                throw new ArgumentNullException(nameof(bytes));
            }
            if (bytes.Length == 0)
            {
                throw Errors.ArrayCannotBeEmpty(nameof(bytes));
            }

            if (BytesComparer.IsZero(bytes))
            {
                throw Errors.BytesArrayCannotContainsOnlyZeros(nameof(bytes));
            }

            return(new(bytes));
        }
Пример #5
0
 /// <summary>
 /// Use to RocksDbRangeEnumerator to compare two keys
 /// </summary>
 /// <param name="key1">From key</param>
 /// <param name="key2">To key</param>
 /// <returns></returns>
 protected int CompareKey(byte[] key1, byte[] key2)
 => BytesComparer.Compare(key1, key2);
Пример #6
0
 public bool Mixed_NonZeroBytes() => BytesComparer.IsZero(nonZeroBytes);
Пример #7
0
 public bool Mixed_ZeroBytes() => BytesComparer.IsZero(zeroBytes);