OpenHarmony源码分析之分布式软总线:trans_service/message.c文件分析

一、概述

trans_service模块基于系统内核提供的socket通信,向authmanager模块提供设备认证通道管理和设备认证数据的传输;向业务模块提供session管理和基于session的数据收发功能,并且通过GCM模块的加密功能提供收发报文的加解密保护。 本文主要是对message.c文件进行分析,该文件的主要功能是提供与cjson库相关的接口,这些接口用于设备间传输的json格式数据的封装或者解析。

DD一下: 欢迎大家关注公众号<程序猿百晓生>,可以了解到一下知识点。

erlang 复制代码
1.OpenHarmony开发基础
2.OpenHarmony北向开发环境搭建
3.鸿蒙南向开发环境的搭建
4.鸿蒙生态应用开发白皮书V2.0 & V3.0
5.鸿蒙开发面试真题(含参考答案) 
6.TypeScript入门学习手册
7.OpenHarmony 经典面试题(含参考答案)
8.OpenHarmony设备开发入门【最新版】
9.沉浸式剖析OpenHarmony源代码
10.系统定制指南
11.【OpenHarmony】Uboot 驱动加载流程
12.OpenHarmony构建系统--GN与子系统、部件、模块详解
13.ohos开机init启动流程
14.鸿蒙版性能优化指南
.......

二、源码分析

arduino 复制代码
/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "message.h"
/*
函数功能:根据指定键获取int类型的json成员,然后将int类型的值保存在result中
函数参数:
    root:根json对象
    name:指定的键
    result:目标结果地址
函数返回值:
    成功:返回0
    失败:返回-1
*/
int GetJsonInt(const cJSON *root, const char *name, int *result)
{
    if (root == NULL || name == NULL || result == NULL) {//健壮性检查
        return -1;
    }
    cJSON *item = cJSON_GetObjectItem(root, name);//获取字段名为name的json成员
    if ((item == NULL) || (!cJSON_IsNumber(item))) {//判断item是否是number类型
        return -1;
    }
    *result = item->valueint;
    return 0;
}
/*
函数功能:根据指定键获取string类型的json成员,然后将string类型的值返回
函数参数:
    root:根json对象
    name:指定的键
函数返回值:
    成功:返回字符串value
    失败:返回NULL
*/
char* GetJsonString(const cJSON *root, const char *name)
{
    if (root == NULL || name == NULL) {//健壮性检查
        return NULL;
    }
    cJSON *item = cJSON_GetObjectItem(root, name);//获取字段名为name的json成员
    if ((item == NULL) || (!cJSON_IsString(item))) {//判断item是否是string类型
        return NULL;
    }
    return item->valuestring;
}
相关推荐
星释7 分钟前
鸿蒙智能体开发实战:26.Skill 与插件协同开发
microsoft·华为·ai·harmonyos·鸿蒙·智能体
charlie11451419138 分钟前
RK3506B: buildroot:出一份正规的最小 rootfs
开发语言·嵌入式·开源项目·rk3506b
星释42 分钟前
鸿蒙智能体开发实战:32.鸿蒙壁纸大师 - API认证与会话管理
华为·ai·harmonyos·智能体
花开彼岸天~44 分钟前
鸿蒙实战:导航栏与顶部栏设计规范 HmTitleBar
华为·harmonyos·鸿蒙系统·设计规范
星释1 小时前
鸿蒙智能体开发实战:33.鸿蒙壁纸大师 - 多轮交互工作流设计
华为·交互·harmonyos·鸿蒙
●VON1 小时前
HarmonyKit | 鸿蒙新特性:router 导航 API 从 pushUrl 到 UIContext 的演进
算法·华为·交互·harmonyos
星释1 小时前
鸿蒙智能体开发实战:31.鸿蒙壁纸大师 - 环境搭建与基础配置
算法·华为·ai·harmonyos·鸿蒙
Helen_cai1 小时前
OpenHarmony 相册图片选择封装全场景开发(API Version23 + 适配版)
华为·harmonyos
特立独行的猫a2 小时前
鸿蒙PC开源软件迁移与多语言三方库移植实战课程讲稿(三、命令行工具移植实战——以OpenSSH为主线)
华为·harmonyos·三方库移植·鸿蒙pc
程序员黑豆2 小时前
鸿蒙应用开发之全局状态管理:AppStorageV2轻松实现登录到个人中心数据共享
华为·harmonyos·鸿蒙