コード例 #1
0
        internal static ByteBuf SerializeTerms(RaftLogEntry[] raftLogEntries, ByteBufAllocator byteBufAllocator)
        {
            int     capacity = (sizeof(sbyte) * 8) + (sizeof(int) * 8) + (sizeof(long) * 8) * raftLogEntries.Length;
            ByteBuf buffer   = byteBufAllocator.buffer(capacity, capacity);

            buffer.writeByte(ContentType.RaftLogEntryTerms.get());
            buffer.writeInt(raftLogEntries.Length);
            foreach (RaftLogEntry raftLogEntry in raftLogEntries)
            {
                buffer.writeLong(raftLogEntry.Term());
            }
            return(buffer);
        }
コード例 #2
0
            public override ByteBuf ReadChunk(ByteBufAllocator allocator)
            {
                if (Count == 3)
                {
                    return(null);
                }
                ByteBuf buffer = allocator.buffer(ChunkSize, ChunkSize);

                Count++;
                int toWrite = min(LeftTowWrite, buffer.writableBytes());

                LeftTowWrite -= toWrite;
                buffer.writerIndex(buffer.writerIndex() + toWrite);
                return(buffer);
            }