⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msghead.java

📁 联通的SGIP协议Java实现
💻 JAVA
字号:
package spApi;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

public class MsgHead
{
  public byte[] Head;
  private int TotalLength;
  private int CommandID;
  private long Seq_1;
  private int Seq_2;
  private int Seq_3;
  private byte[] tempbytes;

  public MsgHead(byte[] paramArrayOfByte)
  {
    int i = 0;

    this.Head = new byte[20];
    for (i = 0; i < 20; ++i) {
      this.Head[i] = paramArrayOfByte[i];
    }

    this.TotalLength = SGIP_Command.Bytes4ToInt(this.Head);

    this.tempbytes =new byte[] { this.Head[4], this.Head[5], this.Head[6], this.Head[7] };
    this.CommandID = SGIP_Command.Bytes4ToInt(this.tempbytes);

    tempbytes =new byte[] { Head[8], Head[9], Head[10], Head[11] };
    this.Seq_1 = SGIP_Command.Bytes4ToLong(this.tempbytes);
    this.tempbytes = new byte[]{ this.Head[12], this.Head[13], this.Head[14], this.Head[15] };
    this.Seq_2 = SGIP_Command.Bytes4ToInt(this.tempbytes);
    this.tempbytes = new byte[]{ this.Head[16], this.Head[17], this.Head[18], this.Head[19] };
    this.Seq_3 = SGIP_Command.Bytes4ToInt(this.tempbytes);
  }

  public MsgHead() {
    this.Head = new byte[20];
  }

  public MsgHead(int paramInt1, int paramInt2, long paramLong, int paramInt3, int paramInt4)
  {
    int i = 0;
    this.Head = new byte[20];

    this.TotalLength = paramInt1;
    this.CommandID = paramInt2;
    this.Seq_1 = paramLong;
    this.Seq_2 = paramInt3;
    this.Seq_3 = paramInt4;
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt1), this.Head, 0, 3, 0);
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt2), this.Head, 0, 3, 4);
    SGIP_Command.BytesCopy(SGIP_Command.LongToBytes4(paramLong), this.Head, 0, 3, 8);
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt3), this.Head, 0, 3, 12);
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt4), this.Head, 0, 3, 16);
  }

  public void setTotalLength(int paramInt)
  {
    this.TotalLength = paramInt;
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt), this.Head, 0, 3, 0);
  }

  public void setCommandID(int paramInt)
  {
    this.CommandID = paramInt;
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt), this.Head, 0, 3, 4);
  }

  public void setSeq_1(long paramLong)
  {
    this.Seq_1 = paramLong;
    SGIP_Command.BytesCopy(SGIP_Command.LongToBytes4(paramLong), this.Head, 0, 3, 8);
  }

  public void setSeq_2(int paramInt)
  {
    this.Seq_2 = paramInt;
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt), this.Head, 0, 3, 12);
  }

  public void setSeq_3(int paramInt)
  {
    this.Seq_3 = paramInt;
    SGIP_Command.BytesCopy(SGIP_Command.IntToBytes4(paramInt), this.Head, 0, 3, 16);
  }

  public int getTotalLength()
  {
    return this.TotalLength;
  }

  public int getCommandID()
  {
    return this.CommandID;
  }

  public long getSeq_1()
  {
    return this.Seq_1;
  }

  public int getSeq_2()
  {
    return this.Seq_2;
  }

  public int getSeq_3()
  {
    return this.Seq_3;
  }

  public int write(OutputStream paramOutputStream)
  {
    int i = 0;
    try {
      paramOutputStream.write(this.Head);
    } catch (Exception localException) {
      System.out.println(localException.toString());
      return -1;
    }
    return 0;
  }

  public int read(InputStream paramInputStream)
  {
    byte[] arrayOfByte = new byte[4];
    try {
      paramInputStream.read(arrayOfByte);
      SGIP_Command.BytesCopy(arrayOfByte, this.Head, 0, 3, 0);
      this.TotalLength = SGIP_Command.Bytes4ToInt(arrayOfByte);

      paramInputStream.read(arrayOfByte);
      SGIP_Command.BytesCopy(arrayOfByte, this.Head, 0, 3, 4);
      this.CommandID = SGIP_Command.Bytes4ToInt(arrayOfByte);

      paramInputStream.read(arrayOfByte);
      SGIP_Command.BytesCopy(arrayOfByte, this.Head, 0, 3, 8);
      this.Seq_1 = SGIP_Command.Bytes4ToLong(arrayOfByte);

      paramInputStream.read(arrayOfByte);
      SGIP_Command.BytesCopy(arrayOfByte, this.Head, 0, 3, 12);
      this.Seq_2 = SGIP_Command.Bytes4ToInt(arrayOfByte);

      paramInputStream.read(arrayOfByte);
      SGIP_Command.BytesCopy(arrayOfByte, this.Head, 0, 3, 16);
      this.Seq_3 = SGIP_Command.Bytes4ToInt(arrayOfByte);
    } catch (Exception localException) {
      System.out.println(localException.toString());
      return -1;
    }
    return 0;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -