Exemple #1
0
  @Override
  public int lengthOf(Object value) {
    Byte code = typeCode.get(value.getClass());
    if (code == null) throw new UnsupportedTypeException(value.toString());

    List<Object> datas = getDatas(code, (Function) value);
    int contentLength = 0;
    for (Object data : datas) {
      if (data instanceof String)
        contentLength += EncodedStringCache.getEncodedString((String) data).length();
      else contentLength += EncodingRule.lengthOf(data);
    }

    return 1 + EncodingRule.lengthOfRawNumber(int.class, contentLength) + contentLength;
  }
Exemple #2
0
  @Override
  public void encode(ByteBuffer bb, Object value) {
    Byte code = typeCode.get(value.getClass());
    if (code == null) throw new UnsupportedTypeException(value.toString());

    List<Object> datas = getDatas(code, (Function) value);
    int contentLength = 0;
    for (Object data : datas) {
      if (data instanceof String)
        contentLength += EncodedStringCache.getEncodedString((String) data).length();
      else contentLength += EncodingRule.lengthOf(data, SortCodec.instance);
    }

    bb.put(code.byteValue());
    EncodingRule.encodeRawNumber(bb, int.class, contentLength);
    for (Object data : datas) {
      if (data instanceof String) {
        EncodedStringCache c = EncodedStringCache.getEncodedString((String) data);
        bb.put(EncodingRule.STRING_TYPE);
        EncodingRule.encodeRawNumber(bb, int.class, c.value().length);
        bb.put(c.value());
      } else EncodingRule.encode(bb, data);
    }
  }
Exemple #3
0
  @Override
  public Object decode(ByteBuffer bb) {
    int beginPosition = bb.position();
    byte code = bb.get();

    int length = (int) EncodingRule.decodeRawNumber(bb);
    int limit = bb.limit();
    bb.limit(bb.position() + length);
    String name = (String) EncodingRule.decode(bb);
    String target = (String) EncodingRule.decode(bb);
    String keyName = (String) EncodingRule.decode(bb);
    Function func = Function.getFunction(name, target, keyName, Timechart.func);

    if (typeCode.get(func.getClass()) != code)
      throw new TypeMismatchException(typeCode.get(func.getClass()), code, beginPosition);

    if (code == (byte) 128) {
      ((Function.Average) func).setD((Double) EncodingRule.decode(bb));
      ((Function.Average) func).setCount((Integer) EncodingRule.decode(bb));
    } else if (code == (byte) 129) {
      ((Function.Count) func).setResult((Long) EncodingRule.decode(bb));
    } else if (code == (byte) 130) {
      // ((Function.DistinctCount) func).setObjs((List<Object>)
      // EncodingRule.decode(bb));
    } else if (code == (byte) 131) {
      ((Function.First) func).setFirst(EncodingRule.decode(bb));
    } else if (code == (byte) 132) {
      ((Function.Last) func).setLast(EncodingRule.decode(bb));
    } else if (code == (byte) 133) {
      // ((Function.ValueList) func).setObjs((List<Object>)
      // EncodingRule.decode(bb));
    } else if (code == (byte) 134) {
      ((Function.Max) func).setMax(EncodingRule.decode(bb));
    } else if (code == (byte) 135) {
      ((Function.Min) func).setMin(EncodingRule.decode(bb));
    } else if (code == (byte) 136) {
      // ((Function.Mode) func).setResult(EncodingRule.decode(bb));
      // ((Function.Mode) func).setMaxCount((Integer)
      // EncodingRule.decode(bb));
      // ((Function.Mode) func).setNowCount((Integer)
      // EncodingRule.decode(bb));
    } else if (code == (byte) 137) {
      ((Function.Range) func).setMax((Number) EncodingRule.decode(bb));
      ((Function.Range) func).setMin((Number) EncodingRule.decode(bb));
    } else if (code == (byte) 138) {
      ((Function.Sum) func).setSum((Number) EncodingRule.decode(bb));
    } else if (code == (byte) 139) {
      // ((Function.SumSquare) func).setSum((Number)
      // EncodingRule.decode(bb));
    } else if (code == (byte) 140) {
      // ((Function.Values) func).setObjs((List<Object>)
      // EncodingRule.decode(bb));
    } else if (code == (byte) 141
        || code == (byte) 142
        || code == (byte) 143
        || code == (byte) 144) {
      ((Timechart.PerTime) func).setAmount((Long) EncodingRule.decode(bb));
    }

    bb.limit(limit);

    return func;
  }