@@ -576,7 +576,7 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
576
576
}
577
577
}
578
578
579
- static CHIP_ERROR MTREncodeTLVFromDataValueDictionary (id object, chip::TLV::TLVWriter & writer, chip::TLV::Tag tag)
579
+ static CHIP_ERROR MTREncodeTLVFromDataValueDictionaryInternal (id object, chip::TLV::TLVWriter & writer, chip::TLV::Tag tag)
580
580
{
581
581
if (![object isKindOfClass: [NSDictionary class ]]) {
582
582
MTR_LOG_ERROR (" Error: Unsupported object to encode: %@" , [object class ]);
@@ -585,7 +585,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
585
585
NSString * typeName = ((NSDictionary *) object)[MTRTypeKey];
586
586
id value = ((NSDictionary *) object)[MTRValueKey];
587
587
if (![typeName isKindOfClass: [NSString class ]]) {
588
- MTR_LOG_ERROR (" Error: Object to encode is corrupt " );
588
+ MTR_LOG_ERROR (" Error: Object to encode has no MTRTypeKey: %@ " , object );
589
589
return CHIP_ERROR_INVALID_ARGUMENT;
590
590
}
591
591
@@ -632,14 +632,14 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
632
632
MTR_LOG_ERROR (" Error: Object to encode has corrupt UTF8 string type: %@" , [value class ]);
633
633
return CHIP_ERROR_INVALID_ARGUMENT;
634
634
}
635
- return writer.PutString (tag, [ value UTF8String ] );
635
+ return writer.PutString (tag, AsCharSpan ( value) );
636
636
}
637
637
if ([typeName isEqualToString: MTROctetStringValueType]) {
638
638
if (![value isKindOfClass: [NSData class ]]) {
639
639
MTR_LOG_ERROR (" Error: Object to encode has corrupt octet string type: %@" , [value class ]);
640
640
return CHIP_ERROR_INVALID_ARGUMENT;
641
641
}
642
- return writer.Put (tag, chip::ByteSpan ( static_cast < const uint8_t *>([ value bytes ]), [value length ] ));
642
+ return writer.Put (tag, AsByteSpan ( value));
643
643
}
644
644
if ([typeName isEqualToString: MTRStructureValueType]) {
645
645
if (![value isKindOfClass: [NSArray class ]]) {
@@ -674,7 +674,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
674
674
tag = TLV::ContextTag (static_cast <uint8_t >(tagValue));
675
675
}
676
676
ReturnErrorOnFailure (
677
- MTREncodeTLVFromDataValueDictionary (elementValue, writer, tag));
677
+ MTREncodeTLVFromDataValueDictionaryInternal (elementValue, writer, tag));
678
678
}
679
679
ReturnErrorOnFailure (writer.EndContainer (outer));
680
680
return CHIP_NO_ERROR;
@@ -696,7 +696,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
696
696
MTR_LOG_ERROR (" Error: Array element to encode has corrupt value: %@" , element);
697
697
return CHIP_ERROR_INVALID_ARGUMENT;
698
698
}
699
- ReturnErrorOnFailure (MTREncodeTLVFromDataValueDictionary (elementValue, writer, chip::TLV::AnonymousTag ()));
699
+ ReturnErrorOnFailure (MTREncodeTLVFromDataValueDictionaryInternal (elementValue, writer, chip::TLV::AnonymousTag ()));
700
700
}
701
701
ReturnErrorOnFailure (writer.EndContainer (outer));
702
702
return CHIP_NO_ERROR;
@@ -705,6 +705,15 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW
705
705
return CHIP_ERROR_INVALID_ARGUMENT;
706
706
}
707
707
708
+ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary (id object, chip::TLV::TLVWriter & writer, chip::TLV::Tag tag)
709
+ {
710
+ CHIP_ERROR err = MTREncodeTLVFromDataValueDictionaryInternal (object, writer, tag);
711
+ if (err != CHIP_NO_ERROR) {
712
+ MTR_LOG_ERROR (" Failed to encode to TLV: %@" , object);
713
+ }
714
+ return err;
715
+ }
716
+
708
717
NSData * _Nullable MTREncodeTLVFromDataValueDictionary (NSDictionary <NSString *, id > * value, NSError * __autoreleasing * error)
709
718
{
710
719
// A single data item cannot be bigger than a packet, so just use 1200 bytes
0 commit comments