1/*
2 * Copyright (C) 2007 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
17package org.apache.harmony.dalvik.ddmc;
18
19import java.nio.ByteBuffer;
20
21/**
22 * A chunk of DDM data.  This is really just meant to hold a few pieces
23 * of data together.
24 *
25 * The "offset" and "length" fields are present so handlers can over-allocate
26 * or share byte buffers.
27 */
28public class Chunk {
29
30    /*
31     * Public members.  Do not rename without updating the VM.
32     */
33    public int type;                // chunk type
34    public byte[] data;             // chunk data
35    public int offset, length;      // position within "data"
36
37    /**
38     * Blank constructor.  Fill in your own fields.
39     */
40    public Chunk() {}
41
42    /**
43     * Constructor with all fields.
44     */
45    public Chunk(int type, byte[] data, int offset, int length) {
46        this.type = type;
47        this.data = data;
48        this.offset = offset;
49        this.length = length;
50    }
51
52    /**
53     * Construct from a ByteBuffer.  The chunk is assumed to start at
54     * offset 0 and continue to the current position.
55     */
56    public Chunk(int type, ByteBuffer buf) {
57        this.type = type;
58
59        this.data = buf.array();
60        this.offset = buf.arrayOffset();
61        this.length = buf.position();
62    }
63}
64
65