use of org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder in project milo by eclipse.
the class BinarySerializationFixture method setUp.
@BeforeMethod
public void setUp() {
buffer = Unpooled.buffer();
writer = new OpcUaBinaryStreamEncoder(new TestSerializationContext()).setBuffer(buffer);
reader = new OpcUaBinaryStreamDecoder(new TestSerializationContext()).setBuffer(buffer);
}
use of org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder in project milo by eclipse.
the class BsdParserTest method assertRoundTrip.
protected void assertRoundTrip(String type, Object originalValue, OpcUaBinaryDataTypeCodec<Object> codec) {
System.out.printf("--- assertRoundTrip Type: %s ---\n", type);
System.out.println("originalValue:\t" + originalValue);
ByteBuf buffer = Unpooled.buffer();
codec.encode(context, new OpcUaBinaryStreamEncoder(context).setBuffer(buffer), originalValue);
ByteBuf encodedValue = buffer.copy();
System.out.println("encodedValue:\t" + ByteBufUtil.hexDump(encodedValue));
Object decodedValue = codec.decode(context, new OpcUaBinaryStreamDecoder(context).setBuffer(buffer));
assertEquals(decodedValue, originalValue);
System.out.println("decodedValue:\t" + decodedValue);
}
use of org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder in project milo by eclipse.
the class BsdParserTest method assertRoundTripUsingToString.
/**
* A weaker version of {@link #assertRoundTrip(String, Object, OpcUaBinaryDataTypeCodec)} for values that don't
* implement equals and hashcode or values that contain members not implementing equals and hashcode.
* <p>
* Relies on toString() values to be implemented at all levels instead... not great, but since the built-in structs
* don't implement equals/hashcode it's what we have.
*/
protected void assertRoundTripUsingToString(String type, Object originalValue, OpcUaBinaryDataTypeCodec<Object> codec) {
System.out.printf("--- assertRoundTrip Type: %s ---\n", type);
System.out.println("originalValue:\t" + originalValue);
ByteBuf buffer = Unpooled.buffer();
codec.encode(context, new OpcUaBinaryStreamEncoder(context).setBuffer(buffer), originalValue);
ByteBuf encodedValue = buffer.copy();
System.out.println("encodedValue:\t" + ByteBufUtil.hexDump(encodedValue));
Object decodedValue = codec.decode(context, new OpcUaBinaryStreamDecoder(context).setBuffer(buffer));
assertEquals(decodedValue.toString(), originalValue.toString());
System.out.println("decodedValue:\t" + decodedValue);
}
use of org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder in project milo by eclipse.
the class OpcClientHttpCodec method encode.
@Override
protected void encode(ChannelHandlerContext ctx, UaTransportRequest transportRequest, List<Object> out) throws Exception {
logger.debug("encoding: " + transportRequest.getRequest());
ctx.channel().attr(KEY_PENDING_REQUEST).set(transportRequest);
ByteBuf content = Unpooled.buffer();
switch(transportProfile) {
case HTTPS_UABINARY:
{
OpcUaBinaryStreamEncoder encoder = new OpcUaBinaryStreamEncoder(client.getStaticSerializationContext());
encoder.setBuffer(content);
encoder.writeMessage(null, transportRequest.getRequest());
break;
}
case HTTPS_UAXML:
{
// TODO put document into a SOAP message.
throw new UaException(StatusCodes.Bad_InternalError, "no encoder for transport: " + transportProfile);
}
default:
throw new UaException(StatusCodes.Bad_InternalError, "no encoder for transport: " + transportProfile);
}
String endpointUrl = endpoint.getEndpointUrl();
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, EndpointUtil.getPath(endpointUrl), content);
httpRequest.headers().set(HttpHeaderNames.HOST, EndpointUtil.getHost(endpointUrl));
httpRequest.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
httpRequest.headers().set(HttpHeaderNames.CONTENT_TYPE, UABINARY_CONTENT_TYPE);
httpRequest.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes());
httpRequest.headers().set("OPCUA-SecurityPolicy", config.getEndpoint().getSecurityPolicyUri());
out.add(httpRequest);
}
use of org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder in project milo by eclipse.
the class OpcServerHttpRequestHandler method sendServiceResponse.
private void sendServiceResponse(ChannelHandlerContext ctx, UaRequestMessage request, UaResponseMessage response) {
ByteBuf contentBuffer = BufferUtil.pooledBuffer();
// TODO switch on transport profile for binary vs xml encoding
OpcUaBinaryStreamEncoder binaryEncoder = new OpcUaBinaryStreamEncoder(stackServer.getSerializationContext());
binaryEncoder.setBuffer(contentBuffer);
binaryEncoder.writeMessage(null, response);
FullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, contentBuffer);
httpResponse.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, UABINARY_CONTENT_TYPE);
httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, contentBuffer.readableBytes());
ctx.writeAndFlush(httpResponse);
}
Aggregations