Java Code Examples for org.msgpack.core.MessageBufferPacker#packInt()

The following examples show how to use org.msgpack.core.MessageBufferPacker#packInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogResponse.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    try {
        packer.packInt(locationType.getCode());
        SerializationUtils.pack(packer, this.locationTypeInfo);
        packer.packString(fileName);
        packer.packInt(index);
        packer.packInt(total);

        packer.packLong(fileSize);
        packer.packString(fileHash);

        packData(packer);
    } catch (Exception e) {
        packer.close();

        throw e;
    }

    return packer;
}
 
Example 2
Source File: MaestroData.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 3
Source File: InternalError.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packInt(errorCode.getCode());
    packer.packString(message);

    return packer;
}
 
Example 4
Source File: LogRequest.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packInt(this.locationType.getCode());

    if (locationType == LocationType.ANY) {
        packer.packString(this.typeName);
    }

    return packer;
}
 
Example 5
Source File: MaestroResponse.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 6
Source File: RoleAssign.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packInt(role.getCode());

    return packer;
}
 
Example 7
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final Test test) throws IOException {
    packer.packInt(test.getTestNumber());
    packer.packInt(test.getTestIteration());
    packer.packString(test.getTestName());
    packer.packString(test.getScriptName());

    pack(packer, test.getTestDetails());
}
 
Example 8
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final SutDetails sutDetails) throws IOException {
    packer.packInt(sutDetails.getSutId());
    packer.packString(sutDetails.getSutName());
    packer.packString(sutDetails.getSutVersion());
    packer.packString(sutDetails.getSutJvmVersion());
    packer.packString(sutDetails.getSutOtherInfo());
    packer.packString(sutDetails.getSutTags());
    packer.packString(sutDetails.getLabName());
    packer.packString(sutDetails.getTestTags());
}
 
Example 9
Source File: AbstractMaestroNotification.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 10
Source File: MaestroNotification.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 11
Source File: Serializer.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * format: `[ValueType.id, value]`
 */
private void packPropertyValue(final MessageBufferPacker packer, final Object value) throws IOException {
  packer.packArrayHeader(2);
  if (value instanceof Boolean) {
    packer.packByte(ValueTypes.BOOLEAN.id);
    packer.packBoolean((Boolean) value);
  } else if (value instanceof String) {
    packer.packByte(ValueTypes.STRING.id);
    packer.packString((String) value);
  } else if (value instanceof Byte) {
    packer.packByte(ValueTypes.BYTE.id);
    packer.packByte((byte) value);
  } else if (value instanceof Short) {
    packer.packByte(ValueTypes.SHORT.id);
    packer.packShort((short) value);
  } else if (value instanceof Integer) {
    packer.packByte(ValueTypes.INTEGER.id);
    packer.packInt((int) value);
  } else if (value instanceof Long) {
    packer.packByte(ValueTypes.LONG.id);
    packer.packLong((long) value);
  } else if (value instanceof Float) {
    packer.packByte(ValueTypes.FLOAT.id);
    packer.packFloat((float) value);
  } else if (value instanceof Double) {
    packer.packByte(ValueTypes.DOUBLE.id);
    packer.packFloat((float) value); //msgpack doesn't support double, but we still want to deserialize it as a double later
  } else if (value instanceof List) {
    packer.packByte(ValueTypes.LIST.id);
    List listValue = (List) value;
    packer.packArrayHeader(listValue.size());
    final Iterator listIter = listValue.iterator();
    while (listIter.hasNext()) {
      packPropertyValue(packer, listIter.next());
    }
  } else {
    throw new NotImplementedException("id type `" + value.getClass() + "` not yet supported");
  }
}
 
Example 12
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final LocationTypeInfo locationTypeInfo) throws IOException {
    packer.packInt(locationTypeInfo.getFileCount());
    packer.packInt(locationTypeInfo.getIndex());
}
 
Example 13
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final ErrorCode errorCode) throws IOException {
    packer.packInt(errorCode.getCode());
}
 
Example 14
Source File: DataDstMsgPack.java    From xresloader with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void writeData(MessageBufferPacker packer, Object data) throws IOException {
    // null
    if (null == data) {
        packer.packNil();
        return;
    }

    // 字符串&二进制
    if (data instanceof String) {
        packer.packString((String) data);
        return;
    }

    // 数字
    // 枚举值已被转为Java Long,会在这里执行
    if (data instanceof Integer) {
        packer.packInt((Integer) data);
        return;
    }
    if (data instanceof Long) {
        packer.packLong((long) data);
        return;
    }
    if (data instanceof Short) {
        packer.packLong((short) data);
        return;
    }
    if (data instanceof Float) {
        packer.packFloat((float) data);
        return;
    }
    if (data instanceof Double) {
        packer.packDouble((double) data);
        return;
    }
    if (data instanceof Byte) {
        packer.packByte((byte) data);
        return;
    }
    if (data instanceof java.math.BigInteger) {
        packer.packBigInteger((java.math.BigInteger) data);
        return;
    }

    // 布尔
    if (data instanceof Boolean) {
        packer.packBoolean((Boolean) data);
        return;
    }

    // 列表
    if (data instanceof List<?>) {
        packer.packArrayHeader(((List<?>) data).size());
        for (Object subobj : (List<?>) data) {
            writeData(packer, subobj);
        }
        return;
    }

    // Hashmap
    if (data instanceof Map<?, ?>) {
        Map<?, ?> mp = (Map<?, ?>) data;

        ArrayList<Map.Entry<?, ?>> sorted_array = new ArrayList<Map.Entry<?, ?>>();
        sorted_array.ensureCapacity(mp.size());
        sorted_array.addAll(mp.entrySet());
        sorted_array.sort((l, r) -> {
            if (l.getValue() instanceof Integer && r.getValue() instanceof Integer) {
                return ((Integer) l.getValue()).compareTo((Integer) r.getValue());
            }

            if (l.getKey() instanceof Integer && r.getKey() instanceof Integer) {
                return ((Integer) l.getKey()).compareTo((Integer) r.getKey());
            } else if (l.getKey() instanceof Long && r.getKey() instanceof Long) {
                return ((Long) l.getKey()).compareTo((Long) r.getKey());
            } else {
                return l.getKey().toString().compareTo(r.getKey().toString());
            }
        });

        packer.packMapHeader(sorted_array.size());
        for (Map.Entry<?, ?> item : sorted_array) {
            writeData(packer, item.getKey());
            writeData(packer, item.getValue());
        }

        return;
    }

    packer.packString(data.toString());
}