title: Eclipse Milo: Reading and decoding a custom data type node from a Simatic S7-1500
body: <p><strong>The problem and what I suspect goes wrong:</strong>
  I am trying to read a custom data type node from a Siemens Simatic S7-1500 and decoding fails with:</p>
  <pre><code>Error running client example: max string length exceeded (length=1819042152, max=2097152)
  org.eclipse.milo.opcua.stack.core.UaSerializationException: max string length exceeded (length=1819042152, max=2097152)
  </code></pre>
  <p><strong>What I did so far:</strong>
  First of all, I've read and tried out the ReadWriteCustomDataTypeNodeExample from the client examples module. I've basically copied this example and replaced CustomStructType for a new custom type called Status containing 10 booleans. Like in the CustomStructType class, I've added a static codec to Status that reads the boolean values from the ByteString by using decoder.readBoolean(). This works perfectly. I have managed to read nodes, modify them and write them back to the OPC UA server. So far so good.</p>
  <pre><code>    NodeId binaryEncodingId = new NodeId(3, &quot;TE_\&quot;DB_FUNCTION_STATUS\&quot;.\&quot;TEST\&quot;&quot;);
  // Register codec with the client DataTypeManager instance
  client.getDataTypeManager().registerCodec(
          binaryEncodingId,
          new TestNode.Codec().asBinaryCodec()
  );
  
  // synchronous read request via VariableNode
  NodeId nodeId = new NodeId(3, &quot;\&quot;DB_FUNCTION_STATUS\&quot;.\&quot;TEST\&quot;&quot;);
  UaVariableNode node = client.getAddressSpace().getVariableNode(nodeId);
  DataValue value = node.readValue();
  
  logger.info(&quot;====== Reading value from OPC UA Server =======&quot;);
  logger.info(&quot;Value={}&quot;, value);
  
  Variant variant = value.getValue();
  ExtensionObject xo = (ExtensionObject) variant.getValue();
  
  TestNode decoded = (TestNode) xo.decode(
          client.getSerializationContext()
  );
  logger.info(&quot;Decoded={}&quot;, decoded);
  </code></pre>
  <p>Next up, I want to do the same as above, but with another custom type TestNode containing a String and an integer. I created the class with a codec that uses decoder.readString() and decoder.readInt16(). When I try to read and decode the ByteString for this node, two issues appear:</p>
  <ul>
  <li>readInt16() reads a different value than the value I see when I read this node with UaExpert.</li>
  <li>readString() throws the exception stated above.</li>
  </ul>
  <p>At this moment, I started doing research and found the following:</p>
  <ul>
  <li>I assume readString() uses the OPC UA String type node ns0;i=12, while, according to
  <a href="https://support.industry.siemens.com/cs/document/109780313/under-which-node-ids-do-you-find-the-type-descriptions-of-the-simatic-data-types-in-the-opc-ua-server-of-a-simatic-s7-1200-s7-1500-?dti=0&amp;lc=en-GB" rel="nofollow noreferrer">https://support.industry.siemens.com/cs/document/109780313/under-which-node-ids-do-you-find-the-type-descriptions-of-the-simatic-data-types-in-the-opc-ua-server-of-a-simatic-s7-1200-s7-1500-?dti=0&amp;lc=en-GB</a>, the Siemens OPC UA server uses ns=3;i=3014. This is probably where it goes wrong, but I'm not sure.</li>
  <li>Also, I don't understand why readInt16() reads a different value than the actual value. I have added a screenshot that show the node in UaExpert with the value and data types. <a href="https://i.stack.imgur.com/h5S6b.png" rel="nofollow noreferrer">Image: TestNode in UaExpert</a></li>
  </ul>
  <p>What are my options in this situation?</p>