示例#1
0
        public byte[] PackNodes()
        {
            int count = 0;

            using (var packer = new Packer())
            {
                packer.Pack(count);
                packer.Pack(Time.Timestamp);
                lock (_buckets)
                {
                    foreach (var list in _buckets)
                    {
                        foreach (var nodeInfo in list)
                        {
                            nodeInfo.Pack(packer);
                            count++;
                        }
                    }
                }

                var p = packer.Position;
                packer.Position = 0;
                packer.Pack(count);
                packer.Position = p;

                return(packer.ToByteArray());
            }
        }
示例#2
0
 public byte[] ToArray()
 {
     using (var packer = new Packer())
     {
         Pack(packer);
         return(packer.ToByteArray());
     }
 }
示例#3
0
        public static string ToHex(Action <Packer> action)
        {
            try
            {
                using (var packer = new Packer())
                {
                    action.Invoke(packer);
                    return(Hex.ToString(packer.ToByteArray()));
                }
            }
            catch (Exception ex)
            {
                Log.IgnoreException(ex);
            }

            return(null);
        }
示例#4
0
        public static byte[] Write(params Action <ChunkWriter>[] chunkedPackable)
        {
            try
            {
                using (var packWriter = new Packer())
                {
                    if (Write(packWriter, chunkedPackable))
                    {
                        return(packWriter.ToByteArray());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.IgnoreException(ex);
            }

            return(null);
        }