Example #1
0
 /**
  * 从ByteBuffer解析得到PropertyBag
  *
  * @param buf 采用mina的ByteBuffer,因为这个支持自动增长
  * @return
  */
 public static PropertyBag readBuffer(ByteBuffer buf) {
   PropertyBag bag = new PropertyBag();
   short fieldCount = buf.getShort();
   for (int i = 0; i < fieldCount; i++) {
     int property = buf.getInt();
     ValueType type = getTypeCode(buf.get());
     Object val = ProtocolUtils.readValueFromPkt(buf, type);
     bag.put(property, val);
   }
   return bag;
 }
Example #2
0
 public void putPropertyBag(int property, PropertyBag value) {
   if (value == null) {
     value = EMPTY_PROPERTYBAG;
   }
   Value<?> v = new Value<PropertyBag>(ValueType.PropertyBag, value, value.countSize());
   valueMap.put(property, v);
 }
Example #3
0
  public static void main(String[] args) {

    PropertyBag bag = new PropertyBag();
    bag.putByte(0, (byte) 1);
    bag.putShort(1, (short) 2);
    bag.putInt(2, (int) 3);
    bag.putLong(3, (long) 4);
    bag.putFloat(4, (float) 1.1);
    bag.putDouble(5, (double) 2.2);
    bag.putBytes(6, new byte[] {0, 1, 2, 3});
    bag.putString(7, "1234");
    bag.putBoolean(8, true);
    bag.putNull(9);

    PropertyBag bag2 = new PropertyBag();
    bag2.put(0, (byte) 1);
    bag2.put(1, (short) 2);
    bag2.put(2, (int) 3);
    bag2.put(3, (long) 4);
    bag2.put(4, (float) 1.1);
    bag2.put(5, (double) 2.2);
    bag2.put(6, new byte[] {0, 1, 2, 3});
    bag2.put(7, "1234");
    bag2.put(8, bag);
    bag2.putBoolean(9, true);
    bag2.putNull(10);

    bag2.put(11, bag);

    PropertyBag test = PropertyBag.valueOfByties(bag2.getByties());

    System.out.println(test.toString());
  }
Example #4
0
 public void union(PropertyBag bag) {
   for (Map.Entry<Integer, Value<?>> entry : bag.getValueMap().entrySet()) {
     this.put(entry.getKey(), entry.getValue().getValue());
   }
 }