1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 Vicente Fernando - www.alfersoft.com.ar - Initial implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.internal.debug.core;
13 import java.util.Vector;
15 public class PHPDBGFrame {
17 public static final int FRAME_HEADER_SIZE = 8; // Header consist of 4 byte frame type and 4 byte frame length
18 private char[] frameType = new char[4];
19 private Vector frameData = new Vector ();
20 private int frameSize = 0;
23 * Construct a new frame.
25 * @param frameType The type of the frame which is created.
27 public PHPDBGFrame (int frameType) {
28 this.frameType = PHPDBGBase.IntToChar4 (frameType);
29 frameSize += FRAME_HEADER_SIZE;
33 * Add an integer to the frame.
37 public void addInt (int num) {
38 char[] newData = PHPDBGBase.IntToChar4 (num); // Convert the integer to four bytes big endian
39 frameData.add (newData); // Add the four bytes to the frame data
40 frameSize += 4; // Calculate the new fram size
44 * Add a character to the frame.
46 * @param ch The character which is to add to the frame.
48 public void addChar (char ch) {
49 char[] newData = new char[1];
52 frameData.add (newData); // Add the character to the frame data
53 frameSize += 1; // Calculate the new fram size
59 public void addString (String str) {
61 frameSize += str.length ();
65 * Get the size of the frame, including the frame header.
67 * @return The size of the entire frame.
69 public int getSize () {
74 * Return the size of the frame, which is the number of all bytes
75 * without the 8 byte from frame header.
77 * @return The size of the frame (without the frame header).
79 public int getSizeOfData () {
80 return frameSize - FRAME_HEADER_SIZE;
84 * Get the header of this frame.
86 * @return The eight char array which forms the header of this frame.
88 public char[] getHeader () {
89 char[] ret = new char[FRAME_HEADER_SIZE]; // Allocate 8 chars for the header
91 PHPDBGBase.copyChars (ret, frameType, 4); // The first four chars are the frame type
92 PHPDBGBase.copyCharsTo (ret, PHPDBGBase.IntToChar4 (getSizeOfData ()), 4, 4); // The second four chars is for the size of the data area
94 return ret; // Return the header
98 * Get the data array of this frame
100 * TODO Finish commenting
102 * @return The char array which holds the data of this frame.
104 public char[] getFrameData () {
105 char[] ret = new char[getSizeOfData ()]; // The frame data (data without the frame header)
106 int pos = 0; // The current position for the 'ret' array
107 int i; // The current position for the frame data list
109 for (i = 0; i < frameData.size (); i++) { // For frame data entries within the list
110 if (frameData.get (i).getClass ().getName ().equals ("[C")) { // What kind of type is the frame data
111 char[] conv = (char[]) frameData.get (i); //
113 PHPDBGBase.copyCharsTo (ret, conv, conv.length, pos); //
116 if (frameData.get (i).getClass ().getName ().equals ("java.lang.String")) { //
117 String conv = (String) frameData.get (i); //
119 PHPDBGBase.copyCharsTo (ret, conv.toCharArray (), conv.length (), pos); //
120 pos += conv.length (); //
125 return ret; // Return the data frame array