예제 #1
0
  public static boolean unpack(MsgItem item, UnpackContext context) {
    int pos = context.pos, pos2;
    byte[] SOH = {1};

    // colCount
    pos2 = ByteArrayUtils.IndexOf(context.bytes, SOH, pos);
    String colCountStr =
        new String(ByteArrayUtils.SubArray(context.bytes, pos, pos2 - pos), context.spec.encoding);
    pos = pos2 + 1;
    int colCount = Integer.parseInt(colCountStr);

    // rowCount
    pos2 = ByteArrayUtils.IndexOf(context.bytes, SOH, pos);
    String rowCountStr =
        new String(ByteArrayUtils.SubArray(context.bytes, pos, pos2 - pos), context.spec.encoding);
    pos = pos2 + 1;
    int rowCount = Integer.parseInt(rowCountStr);

    // title
    String[] title = new String[colCount];
    for (int i = 0; i < colCount; i++) {
      pos2 = ByteArrayUtils.IndexOf(context.bytes, SOH, pos);
      title[i] =
          new String(
              ByteArrayUtils.SubArray(context.bytes, pos, pos2 - pos), context.spec.encoding);
      pos = pos2 + 1;
    }

    // body
    MsgDocument doc = (MsgDocument) item;
    MsgArray root = new MsgArray();
    doc.put("root", root);

    for (int i = 0; i < rowCount; i++) {
      MsgStruct stru = new MsgStruct();
      stru.setAttribute("name", "root");
      stru.setAttribute("isarray", true);

      for (int j = 0; j < colCount; j++) {
        pos2 = ByteArrayUtils.IndexOf(context.bytes, SOH, pos);
        String data =
            new String(
                ByteArrayUtils.SubArray(context.bytes, pos, pos2 - pos), context.spec.encoding);
        pos = pos2 + 1;

        MsgField field = new MsgField();
        field.setAttribute("name", title[j]);
        field.set(data);
        stru.put(title[j], field);
      }
      root.add(stru);
    }

    context.length = context.bytes.length - context.pos;
    return true;
  }
예제 #2
0
  @Override
  protected Value calculate(MsgItem item, PackContext context) {
    MsgField field;

    // 如果v参数带有后缀 则取由后缀指定的节点
    if (context.param.postfix == null) field = (MsgField) item;
    else {
      field = item.SelectSingleField(context.param.postfix);
      if (field == null)
        throw new TESException(
            MsgErr.Pack.VTargetNull, "target: " + context.param.postfix + " item: " + item);
    }

    // 将域本身的属性添加到Processor的参数列表 Processor原有的参数的优先级为高
    for (String k : item.getAttributes().keySet())
      if (!context.processorParams.containsKey(k))
        context.processorParams.put(k, item.getAttribute(k).str);

    return new Value(field.value());
  }