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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public FileChunk readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception public override FileChunk ReadChunk(ByteBufAllocator allocator) { if (_state == FINISHED) { return(null); } else if (_state == PRE_INIT) { _channel = _resource.open(); _nextBytes = Prefetch(); if (_nextBytes == null) { _state = FINISHED; return(FileChunk.Create(new sbyte[0], true)); } else { _state = _nextBytes.Length < MAX_SIZE ? LAST_PENDING : FULL_PENDING; } } if (_state == FULL_PENDING) { sbyte[] toSend = _nextBytes; _nextBytes = Prefetch(); if (_nextBytes == null) { _state = FINISHED; return(FileChunk.Create(toSend, true)); } else if (_nextBytes.Length < MAX_SIZE) { _state = LAST_PENDING; return(FileChunk.Create(toSend, false)); } else { return(FileChunk.Create(toSend, false)); } } else if (_state == LAST_PENDING) { _state = FINISHED; return(FileChunk.Create(_nextBytes, true)); } else { throw new System.InvalidOperationException(); } }
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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public io.netty.buffer.ByteBuf readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception public override ByteBuf ReadChunk(ByteBufAllocator allocator) { ByteBuf byteBuf = _chunkedInput.readChunk(allocator); if (byteBuf != null) { int additionalBytes = byteBuf.readableBytes(); this._totalSize += additionalBytes; if (this._totalSize > _maxSize) { throw new MessageTooBigException(format("Size limit exceeded. Limit is %d, wanted to write %d, written so far %d", _maxSize, additionalBytes, _totalSize - additionalBytes)); } } return(byteBuf); }