| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 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 com.android.tools.chunkio.reader; |
| 18 |
|
| 19 |
import com.android.tools.chunkio.processor.FieldChunk; |
| 20 |
import com.android.tools.chunkio.Chunk; |
| 21 |
import com.android.tools.chunkio.codegen.MethodDef; |
| 22 |
|
| 23 |
/** |
| 24 |
* A chunk reader can generate code to read a specific data type |
| 25 |
* into a class field. |
| 26 |
*/ |
| 27 |
public interface ChunkReader { |
| 28 |
/** |
| 29 |
* Invoked before {@link #emitRead(MethodDef.Builder, String, FieldChunk)} or |
| 30 |
* {@link #emitDynamicRead(MethodDef.Builder, String, FieldChunk)}. |
| 31 |
* |
| 32 |
* @param builder The method builder where to add the generated code |
| 33 |
* @param target The generated name of the instance holding the field to write to |
| 34 |
* @param chunk The field chunk describing the field to write to |
| 35 |
*/ |
| 36 |
void emitPrologue(MethodDef.Builder builder, String target, FieldChunk chunk); |
| 37 |
|
| 38 |
/** |
| 39 |
* Invoked after {@link #emitRead(MethodDef.Builder, String, FieldChunk)} or |
| 40 |
* {@link #emitDynamicRead(MethodDef.Builder, String, FieldChunk)}. |
| 41 |
* |
| 42 |
* @param builder The method builder where to add the generated code |
| 43 |
* @param target The generated name of the instance holding the field to write to |
| 44 |
* @param chunk The field chunk describing the field to write to |
| 45 |
*/ |
| 46 |
void emitEpilogue(MethodDef.Builder builder, String target, FieldChunk chunk); |
| 47 |
|
| 48 |
/** |
| 49 |
* Emits the code that will read a type into the target's field. |
| 50 |
* When this method is called, the byte count defined in the |
| 51 |
* field's chunk annotation is guaranteed to be constant. As such, |
| 52 |
* {@link Chunk#dynamicByteCount()} can be ignored. |
| 53 |
* |
| 54 |
* @param builder The method builder where to add the generated code |
| 55 |
* @param target The generated name of the instance holding the field to write to |
| 56 |
* @param chunk The field chunk describing the field to write to |
| 57 |
*/ |
| 58 |
void emitRead(MethodDef.Builder builder, String target, FieldChunk chunk); |
| 59 |
|
| 60 |
/** |
| 61 |
* Emits the code that will read a type into the target's field. |
| 62 |
* When this method is called, the byte count defined in the |
| 63 |
* field's chunk annotation is guaranteed to be dynamic. As such, |
| 64 |
* {@link Chunk#byteCount()} can be ignored. |
| 65 |
* |
| 66 |
* @param builder The method builder where to add the generated code |
| 67 |
* @param target The generated name of the instance holding the field to write to |
| 68 |
* @param chunk The field chunk describing the field to write to |
| 69 |
*/ |
| 70 |
void emitDynamicRead(MethodDef.Builder builder, String target, FieldChunk chunk); |
| 71 |
} |