예제 #1
0
파일: SnmpOID.java 프로젝트: tiggi/dcache
  @Override
  public byte[] getSnmpBytes() {
    byte[] b = new byte[2 * _arrayLength];
    int x = _array[0] * 40 + _array[1];
    int off = 0;
    b[off++] = (byte) ((x > 127) ? (x - 256) : x);
    int y;
    boolean begin;
    for (int i = 2; i < _arrayLength; i++) {

      x = _array[i];
      begin = false;
      for (int j = 3; j >= 0; j--) {
        y = (x >> (j * 7)) & 0x7f;
        if ((!begin) && (y == 0)) {
          continue;
        }
        begin = true;
        if (j != 0) {
          y |= 0x80;
        }
        b[off++] = (byte) ((y > 127) ? (y - 256) : y);
      }
      if (!begin) {
        b[off++] = (byte) 0;
      }
    }
    //     System.out.println( SnmpObjectHeader._print(b,0,off));
    SnmpObjectHeader head = new SnmpObjectHeader(SnmpObjectHeader.OBJECT_IDENTIFIER, off);
    int headLen = head.getCodedLength();
    byte[] out = new byte[headLen + off];
    System.arraycopy(head.getSnmpBytes(), 0, out, 0, headLen);
    System.arraycopy(b, 0, out, headLen, off);
    return out;
  }
예제 #2
0
파일: SnmpOID.java 프로젝트: tiggi/dcache
  SnmpOID(SnmpObjectHeader head, byte[] b, int offIn, int maxLen) {
    int off = offIn + head.getCodedLength();
    int len = head.getLength();

    _array = new int[len + 1];

    int x = b[off++];
    int resPos = 0;
    x = (x < 0) ? (x + 256) : x;
    _array[resPos++] = (x / 40);
    _array[resPos++] = (x % 40);
    int res = 0;
    for (int i = 1; i < len; i++) {
      x = b[off++];
      x = (x < 0) ? (x + 256) : x;
      if ((x & 0x80) > 0) {
        res |= (x & 0x7f);
        res <<= 7;
      } else {
        res |= (x & 0x7f);
        _array[resPos++] = (res);
        res = 0;
      }
    }
    _arrayLength = resPos;
    setCodedLength(head.getCodedLength() + len);
  }
예제 #3
0
 SnmpSequence(SnmpObjectHeader head, byte[] b, int offIn, int maxLen) {
   int off = offIn + head.getCodedLength();
   int len = head.getLength();
   int rest = len;
   int cl;
   SnmpObject snmp;
   while (rest > 0) {
     snmp = SnmpObject.generate(b, off, rest);
     _vector.addElement(snmp);
     cl = snmp.getCodedLength();
     rest -= cl;
     off += cl;
   }
   setCodedLength(head.getCodedLength() + len);
 }
예제 #4
0
  protected byte[] getSnmpBytes(int type) {
    int s = _vector.size();
    byte[][] v = new byte[s][];
    int total = 0;

    for (int i = 0; i < s; i++) {
      v[i] = (_vector.elementAt(i)).getSnmpBytes();
      total += v[i].length;
    }
    SnmpObjectHeader head = new SnmpObjectHeader(type, total);
    int headLen = head.getCodedLength();
    byte[] out = new byte[headLen + total];

    System.arraycopy(head.getSnmpBytes(), 0, out, 0, headLen);
    int pos = headLen;
    for (int i = 0; i < s; i++) {
      System.arraycopy(v[i], 0, out, pos, v[i].length);
      pos += v[i].length;
    }
    return out;
  }