hp socket 网络库如何构造 extra 用户数据包含不定长字符串的方法

By terrorist at 2022-06-30 • 0人收藏 • 688人看过

如何装一个不定长的字符串? 就是指针, 并且要控制指针的释放,所以要用动态指针

import util.metaProperty;

namespace aaz.libhpsocket.app.userData;
class str{
    
ctor(s){
        
this@ = _metaProperty;
        
if(s){
            
if(type(s) != type.string){
                
error("参数@1必须是字符串",2)
            }
            
this.value = s; 
        }
    }
    pointer pValue; 
}
namespace str{
    _metaProperty = ..util.metaProperty(
        value = {
            _get = 
function(){
                
if(owner.pValue){
                    
return ..raw.str(owner.pValue); 
                }
            }
            
            _set = 
function(v){
                
if(v===null){
                    
if(owner.pValue){
                        
owner.pValue = ..raw.realloc(0, owner.pValue)
                    }
                    
return ; 
                }
                
owner.pValue = ..raw.realloc(#v, owner.pValue, v);
            }   
        };
    )   
}


使用:

import aaz.libhpsocket.app.userData;
import aaz.libhpsocket.app.userData.str;

namespace aaz.libhpsocket.app.websocket.client;
class userData{
    
ctor(wsPath, wsOrigin){
        
this = ..aaz.libhpsocket.app.userData();
    }
    free = 
function(){
        
this.wsKey.value = null;
        
this.wsPath.value = null;
        
this.wsOrigin.value = null
    }
    struct wsKey = ..aaz.libhpsocket.app.userData.str();
    struct wsPath = ..aaz.libhpsocket.app.userData.str(wsPath);
    struct wsOrigin = ..aaz.libhpsocket.app.userData.str(wsOrigin);
}


具体案列请看 https://chengxu.xyz/t/21357

1 个回复 | 最后更新于 2022-07-02
2022-07-02   #1

感谢分享,请问您的

hp socket 网络库

是包含了全部hpsocket的内容吗,还是只有部分

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...