io.vertx.core.buffer.Buffer.setShort()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中io.vertx.core.buffer.Buffer.setShort()方法的一些代码示例,展示了Buffer.setShort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.setShort()方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:setShort

Buffer.setShort介绍

[英]Sets the short at position pos in the Buffer to the value s.

The buffer will expand as necessary to accommodate any value written.
[中]将缓冲器中位置pos处的短路设置为值s。
缓冲区将根据需要扩展以容纳任何写入的值。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

private void testSetShort(Buffer buff) throws Exception {
 for (int i = 0; i < numSets; i++) {
  buff.setShort(i * 2, (short) i);
 }
 for (int i = 0; i < numSets; i++) {
  assertEquals(i, buff.getShort(i * 2));
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

private void testGetSetShort(boolean isLE) throws Exception {
 int numShorts = 100;
 Buffer b = Buffer.buffer(numShorts * 2);
 for (short i = 0; i < numShorts; i++) {
  if (isLE) {
   b.setShortLE(i * 2, i);
  } else {
   b.setShort(i * 2, i);
  }
 }
 for (short i = 0; i < numShorts; i++) {
  if (isLE) {
   assertEquals(i, b.getShortLE(i * 2));
  } else {
   assertEquals(i, b.getShort(i * 2));
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testSetOutOfBounds() throws Exception {
 Buffer b = Buffer.buffer(numSets);
 assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0));
 assertIndexOutOfBoundsException(() -> b.setInt(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setLong(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1)));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1));
 assertIndexOutOfBoundsException(() -> b.setString(-1, ""));
 assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8"));
}

代码示例来源:origin: io.vertx/vertx-core

private void testGetSetShort(boolean isLE) throws Exception {
 int numShorts = 100;
 Buffer b = Buffer.buffer(numShorts * 2);
 for (short i = 0; i < numShorts; i++) {
  if (isLE) {
   b.setShortLE(i * 2, i);
  } else {
   b.setShort(i * 2, i);
  }
 }
 for (short i = 0; i < numShorts; i++) {
  if (isLE) {
   assertEquals(i, b.getShortLE(i * 2));
  } else {
   assertEquals(i, b.getShort(i * 2));
  }
 }
}

代码示例来源:origin: io.vertx/vertx-core

private void testSetShort(Buffer buff) throws Exception {
 for (int i = 0; i < numSets; i++) {
  buff.setShort(i * 2, (short) i);
 }
 for (int i = 0; i < numSets; i++) {
  assertEquals(i, buff.getShort(i * 2));
 }
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Sets the <code>short</code> at position <code>pos</code> in the Buffer to the value <code>s</code>.<p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param s 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setShort(int pos, short s) { 
 delegate.setShort(pos, s);
 return this;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Sets the <code>short</code> at position <code>pos</code> in the Buffer to the value <code>s</code>.<p>
 * The buffer will expand as necessary to accommodate any value written.
 * @param pos 
 * @param s 
 * @return 
 */
public io.vertx.rxjava.core.buffer.Buffer setShort(int pos, short s) { 
 delegate.setShort(pos, s);
 return this;
}

代码示例来源:origin: pmlopes/vertx-bson-codec

public static void setShort(Buffer buffer, int pos, short value) {
 buffer.setShort(pos, Short.reverseBytes(value));
}

代码示例来源:origin: com.jukusoft/vertx-binary-serializer

public static final Buffer serialize (SerializableObject obj) {
  Buffer buf = Buffer.buffer();
  if (obj.getClass().getAnnotation(MessageType.class) == null) {
    throw new NoMessageTypeException("No message type annotation was found in class '" + obj.getClass().getCanonicalName() + "'!");
  }
  if (obj.getClass().getAnnotation(ProtocolVersion.class) == null) {
    throw new NoProtocolVersionException("No protocol version annotation was found in class '" + obj.getClass().getCanonicalName() + "'!");
  }
  int _pos = 0;
  MessageType msgType = obj.getClass().getAnnotation(MessageType.class);
  if (msgType.type() == 0x00) {
    throw new IllegalStateException("message type cannot 0x00, please correct annotation @MessageType in class '" + obj.getClass().getCanonicalName()+ "'!");
  }
  //add message type
  buf.setByte(_pos, msgType.type());
  _pos += 1;
  //add message extended type
  buf.setByte(_pos, msgType.extendedType());
  _pos += 1;
  //add protocol version
  ProtocolVersion version = obj.getClass().getAnnotation(ProtocolVersion.class);
  buf.setShort(_pos, version.value());
  _pos += 2;
  final int pos = _pos;
  ExceptionUtils.executeWithoutIllegalAccessException(() -> serializeFields(buf, obj, pos));
  return buf;
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testSetOutOfBounds() throws Exception {
 Buffer b = Buffer.buffer(numSets);
 assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0));
 assertIndexOutOfBoundsException(() -> b.setInt(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setLong(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0));
 assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1)));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0));
 assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1));
 assertIndexOutOfBoundsException(() -> b.setString(-1, ""));
 assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8"));
}

代码示例来源:origin: com.jukusoft/vertx-binary-serializer

buf.setShort(_pos, (short) character);
  _pos += 2;
} else if (clazz == SByte.class) {
  buf.setShort(_pos, s);
  _pos += 2;
} else if (clazz == SLong.class) {

相关文章

微信公众号

最新文章

更多