/** * Merges the {@code message} with the byte array using the given {@code schema}. */ static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema, boolean decodeNestedMessageAsGroup) { try { final ByteArrayInput input = new ByteArrayInput(data, offset, length, decodeNestedMessageAsGroup); schema.mergeFrom(input, message); input.checkLastTagWas(0); } catch(ArrayIndexOutOfBoundsException ae) { throw new RuntimeException("Truncated.", ProtobufException.truncatedMessage(ae)); } catch (IOException e) { throw new RuntimeException("Reading from a byte array threw an IOException (should " + "never happen).",e); } }
/** * Merges the {@code message} with the byte array using the given {@code schema}. */ public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema) { try { final ByteArrayInput input = new ByteArrayInput(data, offset, length, true); final GraphByteArrayInput graphInput = new GraphByteArrayInput(input); schema.mergeFrom(graphInput, message); input.checkLastTagWas(0); } catch(ArrayIndexOutOfBoundsException ae) { throw new RuntimeException("Truncated.", ProtobufException.truncatedMessage(ae)); } catch (IOException e) { throw new RuntimeException("Reading from a byte array threw an IOException (should " + "never happen).",e); } }
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException { if(value == null) value = schema.newMessage(); schema.mergeFrom(this, value); if(!schema.isInitialized(value)) throw new UninitializedMessageException(value, schema); // handling is in #readFieldNumber checkLastTagWas(0); return value; }
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException { if(decodeNestedMessageAsGroup) return mergeObjectEncodedAsGroup(value, schema); final int length = readRawVarint32(); if(length < 0) throw ProtobufException.negativeSize(); // save old limit final int oldLimit = this.limit; this.limit = offset + length; if(value == null) value = schema.newMessage(); schema.mergeFrom(this, value); if(!schema.isInitialized(value)) throw new UninitializedMessageException(value, schema); checkLastTagWas(0); // restore old limit this.limit = oldLimit; return value; }
case WIRETYPE_START_GROUP: skipMessage(); checkLastTagWas(makeTag(getTagFieldNumber(tag), WIRETYPE_END_GROUP)); return true; case WIRETYPE_END_GROUP: