Created
June 5, 2012 18:11
-
-
Save firexel/2876639 to your computer and use it in GitHub Desktop.
Простота vs прозрачность
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UselessDTO | |
{ | |
public byte val1; | |
public int val2, val3; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public UselessDTO readFromByteArray(@NotNull byte[] array) | |
{ | |
if (array.length < 9) throw new IllegalArgumentException("Need 9 bytes to read"); | |
UselessDTO dto = new UselessDTO(); | |
dto.val1 = array[0]; | |
dto.val2 = (array[1] << 24) | (array[2] << 16) | (array[3] << 8) | array[4]; | |
dto.val3 = (array[5] << 24) | (array[6] << 16) | (array[7] << 8) | array[8]; | |
return dto; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public UselessDTO readFromByteDataSource(@NotNull ByteBufferDataSource source) | |
{ | |
UselessDTO dto = new UselessDTO(); | |
dto.val1 = source.readByte(); | |
dto.val2 = source.readInt(); | |
dto.val3 = source.readInt(); | |
return dto; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public UselessDTO readFromAbstractSource(@NotNull DataSource source) | |
{ | |
UselessDTO dto = new UselessDTO(); | |
dto.val1 = source.readByte(); | |
dto.val2 = source.readInt(); | |
dto.val3 = source.readInt(); | |
return dto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment