diff options
author | Jon Skeet <skeet@pobox.com> | 2015-06-17 15:03:47 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-06-17 15:03:47 +0100 |
commit | e2acd854250b449a3fdeef2ad52402c4c5d78259 (patch) | |
tree | a08126762b6c76d56fde8ce443f8dff36408b6e0 /javanano | |
parent | d9dc05e500807a6f0cd10d4637c599acc9a6aecf (diff) | |
parent | b36395b2bac88f70070544c325bc09234cb1f1a6 (diff) | |
download | protobuf-e2acd854250b449a3fdeef2ad52402c4c5d78259.tar.gz protobuf-e2acd854250b449a3fdeef2ad52402c4c5d78259.tar.bz2 protobuf-e2acd854250b449a3fdeef2ad52402c4c5d78259.zip |
Merged master
Diffstat (limited to 'javanano')
-rw-r--r-- | javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java index b1b0c53a..322ada8e 100644 --- a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java +++ b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java @@ -33,6 +33,7 @@ package com.google.protobuf.nano; import java.io.IOException; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.ReadOnlyBufferException; /** @@ -61,6 +62,7 @@ public final class CodedOutputByteBufferNano { private CodedOutputByteBufferNano(final ByteBuffer buffer) { this.buffer = buffer; + this.buffer.order(ByteOrder.LITTLE_ENDIAN); } /** @@ -1038,24 +1040,20 @@ public final class CodedOutputByteBufferNano { /** Write a little-endian 32-bit integer. */ public void writeRawLittleEndian32(final int value) throws IOException { - writeRawByte((value ) & 0xFF); - writeRawByte((value >> 8) & 0xFF); - writeRawByte((value >> 16) & 0xFF); - writeRawByte((value >> 24) & 0xFF); + if (buffer.remaining() < 4) { + throw new OutOfSpaceException(buffer.position(), buffer.limit()); + } + buffer.putInt(value); } public static final int LITTLE_ENDIAN_32_SIZE = 4; /** Write a little-endian 64-bit integer. */ public void writeRawLittleEndian64(final long value) throws IOException { - writeRawByte((int)(value ) & 0xFF); - writeRawByte((int)(value >> 8) & 0xFF); - writeRawByte((int)(value >> 16) & 0xFF); - writeRawByte((int)(value >> 24) & 0xFF); - writeRawByte((int)(value >> 32) & 0xFF); - writeRawByte((int)(value >> 40) & 0xFF); - writeRawByte((int)(value >> 48) & 0xFF); - writeRawByte((int)(value >> 56) & 0xFF); + if (buffer.remaining() < 8) { + throw new OutOfSpaceException(buffer.position(), buffer.limit()); + } + buffer.putLong(value); } public static final int LITTLE_ENDIAN_64_SIZE = 8; |