MCPcopy Create free account
hub / github.com/defold/defold / BuildTxtRData

Function BuildTxtRData

engine/dlib/src/dlib/mdns.cpp:762–788  ·  view source on GitHub ↗

Encodes the TXT payload exactly as it will appear on the wire so probe authority claims and incoming tiebreak records can be compared bytewise.

Source from the content-addressed store, hash-verified

760 // Encodes the TXT payload exactly as it will appear on the wire so probe
761 // authority claims and incoming tiebreak records can be compared bytewise.
762 static bool BuildTxtRData(const RegisteredService& service, uint8_t* data, uint32_t data_size, uint16_t* data_length)
763 {
764 uint32_t data_offset = 0;
765
766 for (uint32_t i = 0; i < service.m_TxtCount; ++i)
767 {
768 char kv[320];
769 dmSnPrintf(kv, sizeof(kv), "%s=%s", service.m_Txt[i].m_Key, service.m_Txt[i].m_Value);
770 uint32_t len = (uint32_t) strlen(kv);
771 if (len > 255 || data_offset + 1 + len > data_size)
772 return false;
773
774 data[data_offset++] = (uint8_t) len;
775 memcpy(data + data_offset, kv, len);
776 data_offset += len;
777 }
778
779 if (data_offset == 0)
780 {
781 if (data_offset + 1 > data_size)
782 return false;
783 data[data_offset++] = 0;
784 }
785
786 *data_length = (uint16_t) data_offset;
787 return true;
788 }
789
790 // Produces canonical IPv4 A-record rdata for host probing and announcements.
791 static bool BuildARData(const dmSocket::Address& host_address, uint8_t* data, uint32_t data_size, uint16_t* data_length)

Callers 1

BuildProbeRecordFunction · 0.85

Calls 1

dmSnPrintfFunction · 0.85

Tested by

no test coverage detected