private void CanDecode(int iNumberOfEntries) { // Add entries to pending RailPackedListOutgoing <Foo> list = new RailPackedListOutgoing <Foo>(); for (int i = 0; i < iNumberOfEntries; ++i) { list.AddPending(poolMock.Object.Allocate()); } Assert.Equal(iNumberOfEntries, elementsCreated); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never); // Encode RailBitBuffer buffer = new RailBitBuffer(); list.Encode( buffer, RailConfig.PACKCAP_COMMANDS, RailConfig.MAXSIZE_COMMANDUPDATE, (foo, buf) => foo.WriteData(buf)); Assert.False(buffer.Empty); poolMock.Verify(p => p.Allocate(), Times.Exactly(iNumberOfEntries)); poolMock.Verify(p => p.Deallocate(It.IsAny <Foo>()), Times.Never); Assert.Equal(iNumberOfEntries, list.Sent.Count()); RailPackedListIncoming <Foo> incoming = new RailPackedListIncoming <Foo>(); incoming.Decode( buffer, b => { Foo foo = poolMock.Object.Allocate(); foo.ReadData(b); return(foo); }); Assert.Equal(iNumberOfEntries, incoming.Received.Count()); }
private void DecodeCommands(IRailCommandConstruction commandCreator, RailBitBuffer buffer) { commandUpdates.Decode(buffer, buf => RailCommandUpdate.Decode(commandCreator, buf)); }
private void DecodeDeltas(IRailStateConstruction stateCreator, RailBitBuffer buffer) { deltas.Decode( buffer, buf => RailStateDeltaSerializer.DecodeDelta(stateCreator, buf, SenderTick)); }