 1Content-type: application/x-Unknown; charset=UTF8package nmc.common;

import java.io.DataOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;

public class ConfigurationReply extends Reply {
    int      channelNumber; // 4
    boolean  endOfData;     // 1
    int      subseqNo;      // 4
    long     timestamp;     // 8
    byte[]   data;          // varies

    public ConfigurationReply(DataInputStream dis) throws IOException {
	this.decerealize(dis);
    }

    public ConfigurationReply(Message m, TimestampedData configResults) {
	ConfigurationCmd origCmd = (ConfigurationCmd)m;
	this.channelNumber = origCmd.channelNumber;
    	this.len = 4+1+4+8+configResults.data.length;

    	this.seqNo = origCmd.seqNo;
	this.endOfData = true;
	this.subseqNo = 0;
        this.timestamp = configResults.timestamp;
	this.data = configResults.data; // no reason to copy it
    }

    public void decerealize(DataInputStream dis) throws IOException {
	super.decerealize(dis);
	this.channelNumber = dis.readInt();
	this.endOfData     = dis.readBoolean();
	this.subseqNo      = dis.readInt();
        this.timestamp     = dis.readLong();
	this.data     = new byte[this.len-4-1-4-8];
	dis.read(data);
    }

    public int getMessageType(){
	return CONFIGURATION_REPLY;
    }
    
    public byte[] getData() {
    	return data;
    }
    
    public void cerealize(DataOutputStream s) throws IOException {
    	super.cerealize(s);

	s.writeInt      (channelNumber);
	s.writeBoolean  (endOfData);
	s.writeInt      (subseqNo);
	s.writeLong     (timestamp);

	if (data != null) {
	    System.out.println("Cerealizing ConfigurationReply, data.length="
			       + data.length);
	} else {
	    System.out.println("Cerealizing ConfigurationReply, data is null");
	}
	s.write(data, 0, data.length);
    }

    public String toString(){
	
	return "%<%msgType=ConfigurationReply%seqNo="
            + this.seqNo
            + "%len="
            + this.len
            + "%channelNumber="
            + this.channelNumber
            + "%endOfData="
            + this.endOfData
            + "%subseqNo="
            + this.subseqNo
            + "%timestamp="
            + this.timestamp
            + "%data="
            + new String(this.data)
            + "%>%";
    }

}
