In SNMP (SMI) there is no data type string nor there is any hex-string. Instead there is OCTET-STRING, which is a plain 8bit/element Byte string.
Said that. I guess you have put a hexadecimal string as string into the SNMP4J OctetString type. That’s why the resulting value does not match your expectations.
Instead, simply put the bytes represented by the original hex-string into the OctetString using the setValue method for example.
Thanks Frank. I have resolve my issue.
I have another issue that relates to this. I have some byte arrays, each represent string “09”, “0a”, “0b”, “0c”, “0d”. I did new OctetString(byte[]), but I found something quite interesting. Whenever I have “09”, the agent displays as followed. It seems like they are replaced by numbers of spaces. I checked ascii table 9 is a TAB, A is LF, etc. Is there a way to escape them and display the correct value?
There is no “escaping” in the agent, as I wrote before, in the agent and on the wire there is plain OCTET-STRING only. That means, you have two options:
Create a MIB specification for your OBJECT-TYPE that defines how your OCTET-STRING should be displayed using a DISPLAY-HINT clause.
Configure your client to print the OCTET-STRING as a hex-string,
Of course, the first option is the preferred one because others could benefit from that too