{"id":19735983,"url":"https://github.com/play175/bytebuffer","last_synced_at":"2025-04-30T04:31:50.166Z","repository":{"id":3587670,"uuid":"4651046","full_name":"play175/ByteBuffer","owner":"play175","description":"nodejs版本的ByteBuffer和C++通信的利器！","archived":false,"fork":false,"pushed_at":"2018-11-11T09:50:14.000Z","size":50,"stargazers_count":71,"open_issues_count":1,"forks_count":21,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-16T17:18:41.465Z","etag":null,"topics":["bytebuffer","cplusplus","javascript","nodejs","protocol"],"latest_commit_sha":null,"homepage":"https://play175.com/ByteBuffer/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/play175.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-13T13:17:35.000Z","updated_at":"2025-04-09T14:24:50.000Z","dependencies_parsed_at":"2022-08-20T07:31:37.790Z","dependency_job_id":null,"html_url":"https://github.com/play175/ByteBuffer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/play175%2FByteBuffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/play175%2FByteBuffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/play175%2FByteBuffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/play175%2FByteBuffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/play175","download_url":"https://codeload.github.com/play175/ByteBuffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251642932,"owners_count":21620394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytebuffer","cplusplus","javascript","nodejs","protocol"],"created_at":"2024-11-12T01:04:36.344Z","updated_at":"2025-04-30T04:31:49.904Z","avatar_url":"https://github.com/play175.png","language":"HTML","readme":"nodejs版本的ByteBuffer和C++通信的利器！\r\n\r\n推荐结合ExBuffer来实现网络协议：https://github.com/play175/ExBuffer\r\n\r\n```javascript\r\nvar ByteBuffer = require('./ByteBuffer');\r\n\r\n/*************************基本操作****************************/\r\n\r\n//压包操作\r\nvar sbuf = new ByteBuffer();\r\nvar buffer = sbuf.string('abc123你好')//变长字符串，前两个字节表示长度\r\n                       .int32(-999).uint32(999).float(-0.5)\r\n                       .int64(9999999).double(-0.000005).short(32767).ushort(65535)\r\n                       .byte(255)\r\n                       .vstring('abcd',5)//定长字符串,不足的字节补0x00\r\n                       .byteArray([65,66,67,68,69],5)//字节数组，不足字节补0x00\r\n                       .pack();//结尾调用打包方法\r\n\r\nconsole.log(buffer);\r\n\r\n//解包操作\r\nvar rbuf = new ByteBuffer(buffer);\r\n//解包出来是一个数组\r\nvar arr = rbuf.string()//变长字符串，前两个字节表示长度\r\n                    .int32().uint32().float()\r\n                    .int64().double().short().ushort()\r\n                    .byte()\r\n                    .vstring(null,5)//定长字符串,不足的字节补0x00\r\n                    .byteArray(null,5)//字节数组，不足字节补0x00\r\n                    .unpack();//结尾调用解包方法\r\n\r\nconsole.log(arr);\r\n\r\n\r\n/*************************更多操作****************************/\r\n\r\n//指定字符编码(默认：utf8):utf8/ascii/\r\nvar sbuf = new ByteBuffer().encoding('ascii');\r\n\r\n//指定字节序(默认：BigEndian)\r\nvar sbuf = new ByteBuffer().littleEndian();\r\n\r\n//指定数据在二进制的初始位置 默认是0\r\nvar sbuf = new ByteBuffer(buffer,2);\r\n\r\n//插入数据到指定位置\r\nvar sbuf = new ByteBuffer();\r\nsbuf.int32(9999,0);//把这个int32数据插入到ByteBuffer的第一个位置\r\n\r\n//在打包的时候在开始位置插入一个short型表示包长(通信层中的包头)\r\nvar buffer = sbuf.packWithHead();\r\n\r\n```\r\n\r\ninstall\r\n```javascript\r\nnpm install ByteBuffer -g\r\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplay175%2Fbytebuffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplay175%2Fbytebuffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplay175%2Fbytebuffer/lists"}