cocos creator 2.4.5 protobuf 6.11编码解码

这篇博客介绍了如何在客户端向HTTP服务器发起登录请求时,利用protobuf进行消息的编码和解码。示例代码展示了如何创建登录消息结构,包括登录类型、第三方标识等字段,并演示了使用protobuf库进行编码和解码的过程。
摘要由CSDN通过智能技术生成
syntax = "proto3";
package com.panda.message.login;
// 客户端向http服务器登录请求消息
message CS_LoginMsg{
    // 登录方式,1第三方登录,2快速进入。自有账号登录也算作第三方登录
    sint32 loginType = 1;
    // 第三方uid,如果没有拿到,填0
    string treeUID = 2;
    // 第三方登录识别码(用于向第三方登录服务器验证玩家有效登录)
    string session = 3;
    // 手机设备识别码(必须为设备唯一编码)
    string identity = 4;
    // 设备mac码
    string mac = 5;
    // 发行方id
    sint32 bigChannelID = 6;
    // 渠道名称
    string channelName = 7;
    // 玩家id
    sint32 idLogin = 8;
    // md5密码
    string password = 9;
}
import { com } from "../proto/login/proto";
import CS_LoginMsg = com.panda.message.login.CS_LoginMsg;

const { ccclass, property } = cc._decorator;

@ccclass
export default class MyProtobuf extends cc.Component {

    onLoad() {
        let msg = CS_LoginMsg.create({ loginType: 1, treeUID: "test", session: "test", identity: "test", mac: "test", bigChannelID: 1, channelName: "ios", idLogin: 1034, password: "test" });
        let buffer = CS_LoginMsg.encode(msg).finish();//编码

        let decodeMsg = CS_LoginMsg.decode(buffer);//解码
        console.log(decodeMsg.channelName);

    }

}

参考:https://blog.csdn.net/kenkao/article/details/108048636

源码下载地址:https://download.csdn.net/download/LANGZI7758521/20416114

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

VCHH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值