/** * Produces a string representation of the method currently being serviced * by this Handler. * @return A human-readable string representation of the method call. */ @Override public long getRPCPacketLength() { if (getState() != State.RUNNING || packet == null) { // no RPC is currently running, or we don't have an RPC's packet info return -1L; } return packet.getSerializedSize(); }
/** * @param m Message to get delimited pb serialization of (with pb magic prefix) */ public static byte [] toDelimitedByteArray(final Message m) throws IOException { // Allocate arbitrary big size so we avoid resizing. ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); baos.write(PB_MAGIC); m.writeDelimitedTo(baos); return baos.toByteArray(); }
@SuppressWarnings("unchecked") @Override public <M extends Message> M deserialize(Class<M> clazz) throws IOException { Parser<M> parser = (Parser<M>) Internal.getDefaultInstance(clazz).getParserForType(); try { return parser.parseDelimitedFrom(inputStream); } catch (InvalidProtocolBufferException e) { throw e.unwrapIOException(); } } }
Builder builder = call.responseDefaultType.newBuilderForType(); builder.mergeDelimitedFrom(in); value = builder.build();
Message.Builder destination, FieldMaskUtil.MergeOptions options) { if (source.getDescriptorForType() != destination.getDescriptorForType()) { throw new IllegalArgumentException( String.format( "source (%s) and destination (%s) descriptor must be equal", source.getDescriptorForType(), destination.getDescriptorForType())); Descriptor descriptor = source.getDescriptorForType(); for (Entry<String, Node> entry : node.children.entrySet()) { FieldDescriptor field = descriptor.findFieldByName(entry.getKey()); entry.getValue(), childPath, (Message) source.getField(field), destination.getFieldBuilder(field), options); destination.setField(field, source.getField(field)); } else { for (Object element : (List) source.getField(field)) { destination.addRepeatedField(field, element); if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (options.replaceMessageFields()) { if (!source.hasField(field)) { destination.clearField(field); } else { destination.setField(field, source.getField(field));
/** * Merges all fields specified by this FieldMaskTree from {@code source} to {@code destination}. */ void merge(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) { if (source.getDescriptorForType() != destination.getDescriptorForType()) { throw new IllegalArgumentException("Cannot merge messages of different types."); } if (root.children.isEmpty()) { return; } merge(root, "", source, destination, options); }
private ByteString toByteString(MessageOrBuilder message) { if (message instanceof Message) { return ((Message) message).toByteString(); } else { return ((Message.Builder) message).build().toByteString(); } }
Message value = null; if (call.responseDefaultType != null) { Builder builder = call.responseDefaultType.newBuilderForType(); ProtobufUtil.mergeDelimitedFrom(builder, in); value = builder.build();
/** * Checks whether a given field path is valid. */ public static boolean isValid(Class<? extends Message> type, String path) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); return isValid(descriptor, path); }
mergeMessage(json, contentBuilder, true); builder.setField(valueField, contentBuilder.build().toByteString());
private static int write(final OutputStream dos, final Message header, final Message param, final ByteBuffer cellBlock, final int totalSize) throws IOException { // I confirmed toBytes does same as DataOutputStream#writeInt. dos.write(Bytes.toBytes(totalSize)); // This allocates a buffer that is the size of the message internally. header.writeDelimitedTo(dos); if (param != null) { param.writeDelimitedTo(dos); } if (cellBlock != null) { dos.write(cellBlock.array(), 0, cellBlock.remaining()); } dos.flush(); return totalSize; }
if (md == null) throw new UnsupportedOperationException(header.getMethodName()); builder = this.service.getRequestPrototype(md).newBuilderForType(); cis.resetSizeCounter(); int paramSize = cis.readRawVarint32();
/** * @return Size on the wire when the two messages are written with writeDelimitedTo */ public static int getTotalSizeWhenWrittenDelimited(Message... messages) { int totalSize = 0; for (Message m : messages) { if (m == null) { continue; } totalSize += m.getSerializedSize(); totalSize += CodedOutputStream.computeRawVarint32Size(m.getSerializedSize()); } Preconditions.checkArgument(totalSize < Integer.MAX_VALUE); return totalSize; }
@SuppressWarnings("unchecked") @Override public <M extends Message> M deserialize(Class<M> clazz) throws IOException { Parser<M> parser = (Parser<M>) Internal.getDefaultInstance(clazz).getParserForType(); try { return parser.parseDelimitedFrom(inputStream); } catch (InvalidProtocolBufferException e) { throw e.unwrapIOException(); } } }
/** * Checks whether paths in a given fields mask are valid. */ public static boolean isValid(Class<? extends Message> type, FieldMask fieldMask) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); return isValid(descriptor, fieldMask); }
dos.writeInt(IPCUtil.getTotalSizeWhenWrittenDelimited(requestHeader, call.param)); requestHeader.writeDelimitedTo(dos); call.param.writeDelimitedTo(dos); dos.flush();
Builder builder = call.responseDefaultType.newBuilderForType(); builder.mergeDelimitedFrom(in); value = builder.build();
resultVintSize = 0; if (header != null) { headerSerializedSize = header.getSerializedSize(); headerVintSize = CodedOutputStream.computeUInt32SizeNoTag(headerSerializedSize); resultSerializedSize = result.getSerializedSize(); resultVintSize = CodedOutputStream.computeUInt32SizeNoTag(resultSerializedSize);
@SuppressWarnings("unchecked") @Override public <M extends Message> M deserialize(Class<M> clazz) throws IOException { Parser<M> parser = (Parser<M>) Internal.getDefaultInstance(clazz).getParserForType(); try { return parser.parseDelimitedFrom(inputStream); } catch (InvalidProtocolBufferException e) { throw e.unwrapIOException(); } } }