1 /* 2 * Copyright 2017 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.internal; 18 19 import io.grpc.Decompressor; 20 21 /** Interface for deframing gRPC messages. */ 22 public interface Deframer { 23 setMaxInboundMessageSize(int messageSize)24 void setMaxInboundMessageSize(int messageSize); 25 26 /** 27 * Sets the decompressor available to use. The message encoding for the stream comes later in 28 * time, and thus will not be available at the time of construction. This should only be set once, 29 * since the compression codec cannot change after the headers have been sent. 30 * 31 * @param decompressor the decompressing wrapper. 32 */ setDecompressor(Decompressor decompressor)33 void setDecompressor(Decompressor decompressor); 34 35 /** 36 * Sets the decompressor used for full-stream decompression. Full-stream decompression disables 37 * any per-message decompressor set by {@link #setDecompressor}. 38 * 39 * @param fullStreamDecompressor the decompressing wrapper 40 */ setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)41 void setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor); 42 43 /** 44 * Requests up to the given number of messages from the call. No additional messages will be 45 * delivered. 46 * 47 * <p>If {@link #close()} has been called, this method will have no effect. 48 * 49 * @param numMessages the requested number of messages to be delivered to the listener. 50 */ request(int numMessages)51 void request(int numMessages); 52 53 /** 54 * Adds the given data to this deframer and attempts delivery to the listener. 55 * 56 * @param data the raw data read from the remote endpoint. Must be non-null. 57 */ deframe(ReadableBuffer data)58 void deframe(ReadableBuffer data); 59 60 /** Close when any messages currently queued have been requested and delivered. */ closeWhenComplete()61 void closeWhenComplete(); 62 63 /** 64 * Closes this deframer and frees any resources. After this method is called, additional calls 65 * will have no effect. 66 */ close()67 void close(); 68 } 69