Esempio n. 1
0
 /** Encodes an array of {@link Handle}. */
 public void encode(Handle[] v, int offset, int arrayNullability, int expectedLength) {
   if (v == null) {
     encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
     return;
   }
   Encoder e =
       encoderForArray(BindingsHelper.SERIALIZED_HANDLE_SIZE, v.length, offset, expectedLength);
   for (int i = 0; i < v.length; ++i) {
     e.encode(
         v[i],
         DataHeader.HEADER_SIZE + BindingsHelper.SERIALIZED_HANDLE_SIZE * i,
         BindingsHelper.isElementNullable(arrayNullability));
   }
 }
Esempio n. 2
0
 /** Encodes an array of doubles. */
 public void encode(double[] v, int offset, int arrayNullability, int expectedLength) {
   if (v == null) {
     encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
     return;
   }
   encoderForArray(8, v.length, offset, expectedLength).append(v);
 }
Esempio n. 3
0
 /** Encodes an array of bytes. */
 public void encode(byte[] v, int offset, int arrayNullability, int expectedLength) {
   if (v == null) {
     encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
     return;
   }
   if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH && expectedLength != v.length) {
     throw new SerializationException("Trying to encode a fixed array of incorrect length.");
   }
   encodeByteArray(v, v.length, offset);
 }
Esempio n. 4
0
 /** Encodes an array of {@link Interface}. */
 public <T extends Interface> void encode(
     T[] v,
     int offset,
     int arrayNullability,
     int expectedLength,
     Interface.Manager<T, ?> manager) {
   if (v == null) {
     encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
     return;
   }
   Encoder e =
       encoderForArray(BindingsHelper.SERIALIZED_INTERFACE_SIZE, v.length, offset, expectedLength);
   for (int i = 0; i < v.length; ++i) {
     e.encode(
         v[i],
         DataHeader.HEADER_SIZE + BindingsHelper.SERIALIZED_INTERFACE_SIZE * i,
         BindingsHelper.isElementNullable(arrayNullability),
         manager);
   }
 }
Esempio n. 5
0
 /** Encodes an array of booleans. */
 public void encode(boolean[] v, int offset, int arrayNullability, int expectedLength) {
   if (v == null) {
     encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
     return;
   }
   if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH && expectedLength != v.length) {
     throw new SerializationException("Trying to encode a fixed array of incorrect length.");
   }
   byte[] bytes = new byte[(v.length + 7) / BindingsHelper.ALIGNMENT];
   for (int i = 0; i < bytes.length; ++i) {
     for (int j = 0; j < BindingsHelper.ALIGNMENT; ++j) {
       int booleanIndex = BindingsHelper.ALIGNMENT * i + j;
       if (booleanIndex < v.length && v[booleanIndex]) {
         bytes[i] |= (byte) (1 << j);
       }
     }
   }
   encodeByteArray(bytes, v.length, offset);
 }
Esempio n. 6
0
 /** Claim the given amount of memory at the end of the buffer, resizing it if needed. */
 void claimMemory(int size) {
   mEncoderState.claimMemory(BindingsHelper.align(size));
 }
Esempio n. 7
0
 /**
  * Encode a {@link DataHeader} and claim the amount of memory required for the data section
  * (resizing the buffer if required).
  */
 public void encode(DataHeader s) {
   mEncoderState.claimMemory(BindingsHelper.align(s.size));
   encode(s.size, DataHeader.SIZE_OFFSET);
   encode(s.elementsOrVersion, DataHeader.ELEMENTS_OR_VERSION_OFFSET);
 }