public <T> void mergeTo(T message, Schema<T> schema) { final MCInput input = new MCInput(this); try { schema.mergeFrom(input, message); } catch (IOException e) { throw new RuntimeException("Should not happen.", e); } }
public void mergeFrom(Input input, final Object message) throws IOException { final Schema<Object> schema = lastSchema; // merge using this input. schema.mergeFrom(this, message); if(!schema.isInitialized(message)) throw new UninitializedMessageException(message, schema); // restore lastSchema = schema; }
/** * Merges the {@code message} from the {@link InputStream} with the supplied * {@code buf} to use. */ static <T> void mergeFrom(InputStream in, byte[] buf, T message, Schema<T> schema, boolean decodeNestedMessageAsGroup) throws IOException { final CodedInput input = new CodedInput(in, buf, decodeNestedMessageAsGroup); schema.mergeFrom(input, message); input.checkLastTagWas(0); }
/** * Merges the {@code message} from the {@link InputStream} using the given {@code schema}. */ static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, boolean decodeNestedMessageAsGroup) throws IOException { final CodedInput input = new CodedInput(in, decodeNestedMessageAsGroup); schema.mergeFrom(input, message); input.checkLastTagWas(0); }
public void mergeFrom(Input input, final Object message) throws IOException { final Schema<Object> schema = lastSchema; // merge using this input. schema.mergeFrom(this, message); if(!schema.isInitialized(message)) throw new UninitializedMessageException(message, schema); // restore lastSchema = schema; }
/** * Fill the message with the data. */ public <T> void mergeFrom(byte[] data, int offset, int len, T message, Schema<T> schema) { final DSByteArrayInput input = dsPipe.input.reset(data, offset, len); try { schema.mergeFrom(input, message); input.checkLastTagWas(0); } catch(ArrayIndexOutOfBoundsException ae) { throw new RuntimeException("Truncated.", ae); } catch (IOException e) { throw new RuntimeException("Reading from a byte array threw an IOException (should " + "never happen).",e); } finally { input.clear(); } }
/** * 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} from the {@link InputStream} using * the given {@code schema}. */ public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema) throws IOException { final CodedInput input = new CodedInput(in, true); final GraphCodedInput graphInput = new GraphCodedInput(input); schema.mergeFrom(graphInput, message); input.checkLastTagWas(0); }
/** * Parses the {@code messages} (delimited) from the {@link InputStream} * using the given {@code schema}. * * @return the list containing the messages. */ public static <T> List<T> parseListFrom(final InputStream in, final Schema<T> schema) throws IOException { int size = in.read(); if(size == -1) return Collections.emptyList(); if(size > 0x7f) size = CodedInput.readRawVarint32(in, size); final ArrayList<T> list = new ArrayList<T>(size); final CodedInput input = new CodedInput(in, true); for(int i = 0; i < size; i++) { final T message = schema.newMessage(); list.add(message); schema.mergeFrom(input, message); input.checkLastTagWas(0); } assert in.read() == -1; return list; }
/** * Merges the {@code message} from the {@link XMLStreamReader} * using the given {@code schema}. */ public static <T> void mergeFrom(XMLStreamReader parser, T message, Schema<T> schema) throws IOException, XMLStreamException, XmlInputException { //final String simpleName = schema.messageName(); if(parser.nextTag() != START_ELEMENT || !schema.messageName().equals(parser.getLocalName())) { throw new XmlInputException("Expected token START_ELEMENT: " + schema.messageName()); } if(parser.nextTag() == END_ELEMENT) { //if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName); // empty message; return; } schema.mergeFrom(new XmlInput(parser), message); //if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName); }
/** * Merges the {@code message} from the {@link InputStream} using * the given {@code schema}. * * The {@code buffer}'s internal byte array will be used for reading the message. */ public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { final CodedInput input = new CodedInput(in, buffer.buffer, true); final GraphCodedInput graphInput = new GraphCodedInput(input); schema.mergeFrom(graphInput, message); input.checkLastTagWas(0); }
/** * 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; }
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 { emptyMessage = nextTag() == END_ELEMENT; if(value == null) value = schema.newMessage(); schema.mergeFrom(this, value); if(!schema.isInitialized(value)) throw new UninitializedMessageException(value, schema); // onto the next nextTag(); return value; }
/** Reads a message field value from the stream (using the {@code group} encoding). */ private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException { //if (recursionDepth >= recursionLimit) { // throw ProtobufException.recursionLimitExceeded(); //} //++recursionDepth; 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); //--recursionDepth; 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; }
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; }
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException { if(decodeNestedMessageAsGroup) return mergeObjectEncodedAsGroup(value, schema); final int length = readRawVarint32(); //if (recursionDepth >= recursionLimit) { // throw ProtobufException.recursionLimitExceeded(); //} final int oldLimit = pushLimit(length); //++recursionDepth; if(value == null) { value = schema.newMessage(); } schema.mergeFrom(this, value); if(!schema.isInitialized(value)) { throw new UninitializedMessageException(value, schema); } checkLastTagWas(0); //--recursionDepth; popLimit(oldLimit); return value; }
/** * Merges the {@code message} from the JsonParser using the given {@code schema}. */ public static <T> void mergeFrom(JsonParser parser, T message, Schema<T> schema, boolean numeric) throws IOException { if(parser.nextToken() != JsonToken.START_OBJECT) { throw new JsonInputException("Expected token: { but was " + parser.getCurrentToken() + " on message " + schema.messageFullName()); } schema.mergeFrom(new JsonInput(parser, numeric), message); if(parser.getCurrentToken() != JsonToken.END_OBJECT) { throw new JsonInputException("Expected token: } but was " + parser.getCurrentToken() + " on message " + schema.messageFullName()); } }