BACnetStack_DecodeAs
uint32_t BACnetStack_DecodeAs( const uint8_t decodeType, const char * inMessageRaw, const uint16_t inMessageLength, char * outMessage, const uint32_t outMessageMaxLength, const uint8_t packetNetworkType);Decodes a raw BACnet message into a human-readable rendering of the packet, for debugging, logging, and client-side inspection of inbound messages.
Replaces the two older decode exports, one per format, which differed only in their renderer. Pass the format as the first argument:
BACnetStack_DecodeAs(BACnetDecodeType_JSON, raw, rawLen, out, sizeof(out), packetNetworkType);Sizing the output buffer: renderings are much larger than the wire message. A ReadPropertyMultiple response can exceed 20 KB; 64 KB is a safe general-purpose buffer. If the rendering does not fit, NOTHING is written and the function returns 0 - it does not truncate, and the return value does not tell you how much space would have been needed.
Compile-time gating: XML requires STACK_OPTION_DECODE_AS_XML, JSON requires STACK_OPTION_DECODE_AS_JSON, and BOTH require STACK_OPTION_STRING_LITERALS. The two format options remain independent, so a build can include one renderer and not the other; asking for a format that was not compiled in returns 0 and logs.
Parameters
Section titled “Parameters”| Parameter | Direction | Description |
|---|---|---|
decodeType |
in | The output format. See BACnetDecodeType. |
inMessageRaw |
in | The raw BACnet message. |
inMessageLength |
in | The length of the BACnet message. |
outMessage |
out | The resulting rendered output. Not null-terminated; use the return value as the length. |
outMessageMaxLength |
in | The maximum buffer length for the rendered output. |
packetNetworkType |
in | The BACnet network type the raw message came from: 0 = BACnet/IP, 1 = MS/TP, 2 = BACnet/SC, 3 = BACnet/IPv6 (a build with STACK_OPTION_DATA_LINK_LAYER_IPV6; the raw message is then the NPDU and APDU, as for MS/TP, without the BVLL header) (the stack’s packet network types, as BACnetStack_AddRouterPort() takes; not BACnetNetworkType, where IPv4 is 5). This is the one deliberate exception to the Network Port instance convention every other Send/Receive export follows: DecodeAs is a pure decoder that can be handed bytes captured from a transport this device does not itself have a Network Port object for (e.g. a packet capture from another device), so it takes the 3-valued transport-type enum directly rather than resolving a claimed instance. |
Returns
Section titled “Returns”The number of bytes written to outMessage, or 0 on any failure (unknown decodeType, format not compiled in, invalid packetNetworkType, undecodable message, or buffer too small).
Topic: Client requests. Declared in CASBACnetStackDLL.h.