本文整理了Java中io.netty.buffer.ByteBuf.writeByte()
方法的一些代码示例,展示了ByteBuf.writeByte()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.writeByte()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:writeByte
[英]Sets the specified byte at the current writerIndexand increases the writerIndex by 1 in this buffer. The 24 high-order bits of the specified value are ignored.
[中]在当前writerIndex处设置指定字节,并在此缓冲区中将writerIndex增加1。指定值的24个高位将被忽略。
代码示例来源:origin: alibaba/Sentinel
private void encodeString(String param, ByteBuf target) {
target.writeByte(ClusterConstants.PARAM_TYPE_STRING);
byte[] tmpChars = param.getBytes();
target.writeInt(tmpChars.length);
target.writeBytes(tmpChars);
}
代码示例来源:origin: wildfly/wildfly
@Override
public void write(final ByteBuf buffer) {
buffer.writeByte(DataConstants.CHAR);
buffer.writeShort((short) val);
}
代码示例来源:origin: wildfly/wildfly
@Override
public void write(final ByteBuf buffer) {
buffer.writeByte(DataConstants.INT);
buffer.writeInt(val);
}
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(int type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte('S');
buf.writeByte('S');
buf.writeShort(2 + 2 + 2 + content.readableBytes() + 4 + 2 + 2);
buf.writeShort(type);
buf.writeBytes(content);
buf.writeInt(0x0B);
buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
return buf;
}
代码示例来源:origin: netty/netty
/**
* Writes any remaining bits to the output {@link ByteBuf},
* zero padding to a whole byte as required.
*/
void flush(ByteBuf out) {
final int bitCount = this.bitCount;
if (bitCount > 0) {
final long bitBuffer = this.bitBuffer;
final int shiftToRight = 64 - bitCount;
if (bitCount <= 8) {
out.writeByte((int) (bitBuffer >>> shiftToRight << 8 - bitCount));
} else if (bitCount <= 16) {
out.writeShort((int) (bitBuffer >>> shiftToRight << 16 - bitCount));
} else if (bitCount <= 24) {
out.writeMedium((int) (bitBuffer >>> shiftToRight << 24 - bitCount));
} else {
out.writeInt((int) (bitBuffer >>> shiftToRight << 32 - bitCount));
}
}
}
}
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(Command command, String content) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte('#');
buf.writeByte('#');
buf.writeByte(T800xProtocolDecoder.MSG_COMMAND);
buf.writeShort(7 + 8 + 1 + content.length());
buf.writeShort(1); // serial number
buf.writeBytes(DataConverter.parseHex("0" + getUniqueId(command.getDeviceId())));
buf.writeByte(MODE_SETTING);
buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
return buf;
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(GetFeaturesOutput message, ByteBuf outBuffer) {
ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
outBuffer.writeLong(message.getDatapathId().longValue());
outBuffer.writeInt(message.getBuffers().intValue());
outBuffer.writeByte(message.getTables().intValue());
outBuffer.writeByte(message.getAuxiliaryId().intValue());
outBuffer.writeZero(PADDING);
writeCapabilities(message.getCapabilities(), outBuffer);
outBuffer.writeInt(message.getReserved().intValue());
ByteBufUtils.updateOFHeaderLength(outBuffer);
}
代码示例来源:origin: qunarcorp/qmq
private void serializeMessage(BaseMessage message, ByteBuf out) {
int crcIndex = out.writerIndex();
out.writerIndex(crcIndex + 8);
final int messageStart = out.writerIndex();
flag = Flags.setTags(flag, hasTags(tags));
out.writeByte(flag);
out.writeInt(bodyLen);
代码示例来源:origin: traccar/traccar
private ByteBuf encodeContent(long deviceId, short type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer(0);
String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId();
buf.writeByte('@');
buf.writeByte('@');
buf.writeShortLE(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length
buf.writeByte(1); // protocol version
buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII));
buf.writeZero(20 - uniqueId.length());
buf.writeShort(type);
buf.writeBytes(content);
buf.writeShortLE(Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
return buf;
}
代码示例来源:origin: wildfly/wildfly
public void encodeHeadersAndProperties(final ByteBuf buffer) {
checkProperties();
messageIDPosition = buffer.writerIndex();
buffer.writeLong(messageID);
SimpleString.writeNullableSimpleString(buffer, address);
if (userID == null) {
buffer.writeByte(DataConstants.NULL);
} else {
buffer.writeByte(DataConstants.NOT_NULL);
buffer.writeBytes(userID.asBytes());
}
buffer.writeByte(type);
buffer.writeBoolean(durable);
buffer.writeLong(expiration);
buffer.writeLong(timestamp);
buffer.writeByte(priority);
properties.encode(buffer);
}
代码示例来源:origin: traccar/traccar
private static void sendResponse(Channel channel, ByteBuf buf) {
if (channel != null) {
ByteBuf response = Unpooled.buffer(4);
response.writeByte('*');
response.writeShort(buf.getUnsignedShort(buf.writerIndex() - 2));
response.writeByte(buf.getUnsignedByte(buf.writerIndex() - 3));
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
private static void writeNextTableRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property,
final byte code) {
int startIndex = output.writerIndex();
output.writeShort(code);
int lengthIndex = output.writerIndex();
output.writeShort(EncodeConstants.EMPTY_LENGTH);
List<NextTableIds> nextTableIds = property.getAugmentation(NextTableRelatedTableFeatureProperty.class)
.getNextTableIds();
if (nextTableIds != null) {
for (NextTableIds next : nextTableIds) {
output.writeByte(next.getTableId());
}
}
int length = output.writerIndex() - startIndex;
output.setShort(lengthIndex, length);
output.writeZero(paddingNeeded(length));
}
代码示例来源:origin: traccar/traccar
private void sendResponse(Channel channel) {
if (channel != null) {
ByteBuf response = Unpooled.buffer(2 * BLOCK_LENGTH);
response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT);
response.writeMedium(1);
response.writeByte(0x00); // success
response.writerIndex(2 * BLOCK_LENGTH);
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(Instruction instruction, ByteBuf outBuffer) {
outBuffer.writeShort(getType());
outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
outBuffer.writeByte(((GotoTableCase) instruction.getInstructionChoice())
.getGotoTable().getTableId());
outBuffer.writeZero(InstructionConstants.PADDING_IN_GOTO_TABLE);
}
代码示例来源:origin: org.opendaylight.bgpcep/bgp-linkstate
public static void serializePrefixAttributes(final Flags flags, final Algorithm algorithm, final SidLabelIndex sidLabelIndex, final ByteBuf buffer) {
final BitArray bitFlags = serializePrefixFlags(flags, sidLabelIndex);
bitFlags.toByteBuf(buffer);
buffer.writeByte(algorithm.getIntValue());
buffer.writeZero(RESERVED_PREFIX);
buffer.writeBytes(SidLabelIndexParser.serializeSidValue(sidLabelIndex));
}
代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl
@Override
public void serialize(Action action, ByteBuf outBuffer) {
super.serialize(action, outBuffer);
outBuffer.writeByte(((SetNwTosCase) action.getActionChoice()).getSetNwTosAction().getNwTos());
outBuffer.writeZero(ActionConstants.PADDING_IN_SET_NW_TOS_ACTION);
}
代码示例来源:origin: traccar/traccar
private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
if (channel != null) {
ByteBuf reply = Unpooled.buffer(28);
reply.writeByte('M');
reply.writeByte('C');
reply.writeByte('G');
reply.writeByte('P');
reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
reply.writeIntLE((int) deviceId);
reply.writeByte(commandCount++);
reply.writeIntLE(0); // authentication code
reply.writeByte(0);
reply.writeByte(packetNumber);
reply.writeZero(11);
byte checksum = 0;
for (int i = 4; i < 27; i++) {
checksum += reply.getByte(i);
}
reply.writeByte(checksum);
channel.writeAndFlush(new NetworkMessage(reply, remoteAddress));
}
}
代码示例来源:origin: mpusher/mpush
public static void encodePacket(Packet packet, ByteBuf out) {
if (packet.cmd == Command.HEARTBEAT.cmd) {
out.writeByte(Packet.HB_PACKET_BYTE);
} else {
out.writeInt(packet.getBodyLength());
out.writeByte(packet.cmd);
out.writeShort(packet.cc);
out.writeByte(packet.flags);
out.writeInt(packet.sessionId);
out.writeByte(packet.lrc);
if (packet.getBodyLength() > 0) {
out.writeBytes(packet.body);
}
}
packet.body = null;
}
代码示例来源:origin: mpusher/mpush
public byte calcLrc() {
byte[] data = Unpooled.buffer(HEADER_LEN - 1)
.writeInt(getBodyLength())
.writeByte(cmd)
.writeShort(cc)
.writeByte(flags)
.writeInt(sessionId)
.array();
byte lrc = 0;
for (int i = 0; i < data.length; i++) {
lrc ^= data[i];
}
return lrc;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void write(final ByteBuf buffer) {
buffer.writeByte(DataConstants.BYTES);
buffer.writeInt(val.length);
buffer.writeBytes(val);
}
内容来源于网络,如有侵权,请联系作者删除!