Skip to content

Commit b9e3eba

Browse files
committed
Actually add the file this time
1 parent f9c8373 commit b9e3eba

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @file
21+
* Support for JsonTlv.
22+
*
23+
*/
24+
25+
#include <lib/support/jsontlv/JsonToTlv.h>
26+
#include <string>
27+
28+
using namespace chip;
29+
30+
extern "C" {
31+
// Returns the number of TLV encoded bytes extracted from the json string
32+
// Input:
33+
// json - JSON string containing the MatterTLVJson style json for one cluster
34+
// buf - output buffer
35+
// size - output buffer size
36+
// Returns:
37+
// Number of TLV bytes encoded. If this fails, 0 will be returned.
38+
size_t pychip_JsonToTlv(const char* json, uint8_t* buf, size_t size) {
39+
MutableByteSpan tlvSpan(buf, size);
40+
CHIP_ERROR err = JsonToTlv(json, tlvSpan);
41+
if (err != CHIP_NO_ERROR) {
42+
return 0;
43+
}
44+
return tlvSpan.size();
45+
}
46+
} // extern "C"

0 commit comments

Comments
 (0)