List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:com.digitalpetri.opcua.stack.core.channel.headers.AsymmetricSecurityHeader.java
License:Apache License
public static void encode(AsymmetricSecurityHeader header, ByteBuf buffer) { String securityPolicy = header.getSecurityPolicyUri(); buffer.writeInt(securityPolicy.length()); buffer.writeBytes(securityPolicy.getBytes(Charset.forName("UTF-8"))); ByteString senderCertificate = header.getSenderCertificate(); if (senderCertificate.isNull()) { buffer.writeInt(-1);//from www.j ava 2 s . co m } else { buffer.writeInt(senderCertificate.length()); buffer.writeBytes(senderCertificate.bytes()); } ByteString receiverThumbprint = header.getReceiverThumbprint(); if (receiverThumbprint.isNull()) { buffer.writeInt(-1); } else { buffer.writeInt(receiverThumbprint.length()); buffer.writeBytes(receiverThumbprint.bytes()); } }
From source file:com.digitalpetri.opcua.stack.core.channel.headers.SecureMessageHeader.java
License:Apache License
public static void encode(SecureMessageHeader header, ByteBuf buffer) throws UaException { buffer.writeMedium(MessageType.toMediumInt(header.getMessageType())); buffer.writeByte(header.getChunkType()); buffer.writeInt((int) header.getMessageSize()); buffer.writeInt((int) header.getSecureChannelId()); }
From source file:com.digitalpetri.opcua.stack.core.channel.headers.SequenceHeader.java
License:Apache License
public static ByteBuf encode(SequenceHeader header, ByteBuf buffer) { buffer.writeInt((int) header.getSequenceNumber()); buffer.writeInt((int) header.getRequestId()); return buffer; }
From source file:com.digitalpetri.opcua.stack.core.channel.headers.SymmetricSecurityHeader.java
License:Apache License
public static ByteBuf encode(SymmetricSecurityHeader header, ByteBuf buffer) { buffer.writeInt((int) header.getTokenId()); return buffer; }
From source file:com.digitalpetri.opcua.stack.core.channel.messages.AcknowledgeMessage.java
License:Apache License
public static void encode(AcknowledgeMessage message, ByteBuf buffer) { buffer.writeInt((int) message.getProtocolVersion()); buffer.writeInt((int) message.getReceiveBufferSize()); buffer.writeInt((int) message.getSendBufferSize()); buffer.writeInt((int) message.getMaxMessageSize()); buffer.writeInt((int) message.getMaxChunkCount()); }
From source file:com.digitalpetri.opcua.stack.core.channel.messages.ErrorMessage.java
License:Apache License
public static void encode(ErrorMessage message, ByteBuf buffer) { buffer.writeInt((int) message.getError().getValue()); encodeString(message.getReason(), buffer); }
From source file:com.digitalpetri.opcua.stack.core.channel.messages.HelloMessage.java
License:Apache License
public static void encode(HelloMessage message, ByteBuf buffer) { buffer.writeInt((int) message.getProtocolVersion()); buffer.writeInt((int) message.getReceiveBufferSize()); buffer.writeInt((int) message.getSendBufferSize()); buffer.writeInt((int) message.getMaxMessageSize()); buffer.writeInt((int) message.getMaxChunkCount()); encodeString(message.getEndpointUrl(), buffer); }
From source file:com.digitalpetri.opcua.stack.core.channel.messages.TcpMessageEncoder.java
License:Apache License
/** * Encode a simple UA TCP message./* w w w . ja v a 2 s. com*/ * * @param messageType {@link MessageType#Hello}, {@link MessageType#Acknowledge}, or {@link MessageType#Error}. * @param messageEncoder a function that encodes the message payload. * @param buffer the {@link ByteBuf} to encode into. */ private static ByteBuf encode(MessageType messageType, Consumer<ByteBuf> messageEncoder, ByteBuf buffer) throws UaException { buffer.writeMedium(MessageType.toMediumInt(messageType)); buffer.writeByte('F'); int lengthIndex = buffer.writerIndex(); buffer.writeInt(0); int indexBefore = buffer.writerIndex(); messageEncoder.accept(buffer); int indexAfter = buffer.writerIndex(); int bytesWritten = indexAfter - indexBefore; buffer.writerIndex(lengthIndex); buffer.writeInt(8 + bytesWritten); buffer.writerIndex(indexAfter); return buffer; }
From source file:com.dingwang.netty.encoder.TimeEncoder.java
License:Open Source License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { System.out.println("2222222222222"); System.out.println(msg.toString()); msg = new UnixTime(); UnixTime m = (UnixTime) msg;//from w w w. j ava2s. co m ByteBuf encoded = ctx.alloc().buffer(4); encoded.writeInt(m.getValue()); ctx.write(encoded, promise); }
From source file:com.dingwang.rpc.encode.RpcEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, Object in, ByteBuf out) throws Exception { if (genericClass.isInstance(in)) { byte[] data = SerializationUtil.serialize(in); out.writeInt(data.length); out.writeBytes(data);//from ww w . j a v a 2 s. co m } }