Exemplo n.º 1
0
  @Test
  public void shouldEncodeAndDecodeClientMessageCorrectly_withPayLoadData_fromOffset()
      throws UnsupportedEncodingException {
    SafeBuffer byteBuffer = new SafeBuffer(new byte[150]);
    int offset = 100;

    ClientMessage cmEncode = TestClientMessage.createForEncode(byteBuffer, offset);

    cmEncode
        .setMessageType(7)
        .setVersion((short) 3)
        .addFlag(ClientMessage.BEGIN_AND_END_FLAGS)
        .setCorrelationId(66)
        .setPartitionId(77);

    byte[] bytes = VAR_DATA_STR_1.getBytes();
    final int calculatedFrameSize =
        ClientMessage.HEADER_SIZE
            + Bits.INT_SIZE_IN_BYTES
            + ParameterUtil.calculateByteArrayDataSize(bytes);
    cmEncode.set(1);
    cmEncode.set(bytes);
    cmEncode.updateFrameLength();

    ClientMessage cmDecode = ClientMessage.createForDecode(byteBuffer, offset);

    assertEquals(1, cmDecode.getInt());
    assertArrayEquals(bytes, cmDecode.getByteArray());

    assertEquals(calculatedFrameSize, cmDecode.getFrameLength());
  }
Exemplo n.º 2
0
  public static Member decode(ClientMessage clientMessage) {
    final Address address = AddressCodec.decode(clientMessage);
    String uuid = clientMessage.getStringUtf8();
    int attributeSize = clientMessage.getInt();
    Map<String, Object> attributes = new HashMap<String, Object>();
    for (int i = 0; i < attributeSize; i++) {
      String key = clientMessage.getStringUtf8();
      String value = clientMessage.getStringUtf8();
      attributes.put(key, value);
    }

    return new com.hazelcast.client.impl.MemberImpl(address, uuid, attributes);
  }