feat(proton): migrate highway.ts schemas + highway-client + group-file
Mirrors all 35 schemas in bridge/proto/highway.ts as proton interface
forms and switches the two non-OIDB-wrapped consumers
(highway/highway-client.ts and actions/group-file.ts) over to the new
compile-time API.
Migrated schemas (proton/highway.ts):
DataHighwayHead, SegHead, LoginSigHead, ReqDataHighwayHead,
RespDataHighwayHead, HighwayDomain, HighwayIPv4, HighwayNetwork,
HighwayHash, HighwayMsgInfoBody, NTV2RichMediaHighwayExt,
FileUploadUrl, FileUploadHost, FileUploadHostConfig,
FileUploadNameInfo, FileUploadClientInfo, FileUploadFileEntry,
FileUploadBusiInfo, FileUploadEntry, FileUploadExt,
EncodableMediaExtBizInfo, EncodableMediaMsgInfo, HttpConn,
HttpConn0x6FF501Request, ServerAddr, ServerInfo, HttpConnResponse,
HttpConn0x6FF501Response, NTV2FileType, NTV2FileInfo,
NTV2UploadInfo, NTV2ExtBizInfo, NTV2UploadReq, NTV2C2CUserInfo,
NTV2GroupInfo, NTV2UploadSceneInfo, NTV2CommonHead, NTV2ClientMeta,
NTV2UploadReqHead, NTV2UploadRichMediaReq, NTV2IPv4,
NTV2SubFileInfoResp, NTV2UploadRespMsgInfo, NTV2UploadRespBody,
NTV2UploadRespHead, NTV2UploadRichMediaResp
Consumer switches:
- highway/highway-client.ts: protobuf_encode/decode for HttpConn
session fetch, ReqDataHighwayHead frames, NTV2RichMediaHighwayExt
extend bytes, RespDataHighwayHead per-chunk responses
- actions/group-file.ts: protobuf_encode<FileUploadExt> for both
group + private file upload ext bytes
NOT migrated (depends on the OIDB factory pattern):
- highway/pipeline.ts — uses makeOidbBaseSchema(NTV2UploadRichMediaReqSchema)
to wrap the NTV2 upload in an OIDB envelope at runtime. Waits for
the oidb.ts migration to land a generic OidbBase<T> form.
Verification:
- 5 new parity tests for highway schemas (HttpConn0x6FF501 req+resp
with the high-numbered 0x501 tag, ReqDataHighwayHead with multiple
nested messages, NTV2RichMediaHighwayExt with repeated_bytes,
FileUploadExt with the 100/200/400/600/700 high-numbered tags)
- 602/602 core test suite passes — the existing image / ptt / video
upload tests implicitly validated wire format equivalence
- tsc --noEmit clean
This commit is contained in:
4 files changed
+471
-23
No files matched your search
@@ -6,7 +6,7 @@
|
||||
// stay as separate functions.
|
||||
|
||||
import type { Bridge } from '../bridge';
|
||||
import { protoEncode } from '../../protobuf/decode';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { runOidb } from '../bridge-oidb';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '../highway/highway-client';
|
||||
import { computeHashes, computeMd5, FILE_UPLOAD_MAX_BYTES, loadBinarySource } from '../highway/utils';
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
NTV2RichMediaReqSchema,
|
||||
NTV2RichMediaRespSchema,
|
||||
} from '../proto/oidb-action';
|
||||
import { FileUploadExtSchema } from '../proto/highway';
|
||||
import type { FileUploadExt } from '../proto/proton/highway';
|
||||
import { toHexUpper } from '../../utils/hex';
|
||||
import { ensureRetCodeZero, resolveSelfUid, toInt, type MediaIndexNode } from './shared';
|
||||
|
||||
@@ -104,7 +104,7 @@ function buildGroupFileUploadExt(
|
||||
uploadHost: string,
|
||||
uploadPort: number,
|
||||
): Uint8Array {
|
||||
return protoEncode({
|
||||
return protobuf_encode<FileUploadExt>({
|
||||
unknown1: 100,
|
||||
unknown2: 1,
|
||||
entry: {
|
||||
@@ -145,7 +145,7 @@ function buildGroupFileUploadExt(
|
||||
},
|
||||
},
|
||||
unknown200: 0,
|
||||
}, FileUploadExtSchema);
|
||||
});
|
||||
}
|
||||
|
||||
function buildPrivateFileUploadExt(
|
||||
@@ -159,7 +159,7 @@ function buildPrivateFileUploadExt(
|
||||
uploadHost: string,
|
||||
uploadPort: number,
|
||||
): Uint8Array {
|
||||
return protoEncode({
|
||||
return protobuf_encode<FileUploadExt>({
|
||||
unknown1: 100,
|
||||
unknown2: 1,
|
||||
entry: {
|
||||
@@ -201,7 +201,7 @@ function buildPrivateFileUploadExt(
|
||||
},
|
||||
unknown3: 0,
|
||||
unknown200: 1,
|
||||
}, FileUploadExtSchema);
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeMediaNode(node: MediaIndexNode): Record<string, unknown> {
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
|
||||
import net from 'net';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { protoEncode, protoDecode } from '../../protobuf/decode';
|
||||
import {
|
||||
HttpConn0x6FF501RequestSchema,
|
||||
HttpConn0x6FF501ResponseSchema,
|
||||
ReqDataHighwayHeadSchema,
|
||||
RespDataHighwayHeadSchema,
|
||||
NTV2RichMediaHighwayExtSchema,
|
||||
HighwayMsgInfoBodySchema,
|
||||
} from '../proto/highway';
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
import type {
|
||||
HttpConn0x6FF501Request,
|
||||
HttpConn0x6FF501Response,
|
||||
ReqDataHighwayHead,
|
||||
RespDataHighwayHead,
|
||||
NTV2RichMediaHighwayExt,
|
||||
} from '../proto/proton/highway';
|
||||
import { packHighwayFrame, unpackHighwayFrame, computeMd5 } from './utils';
|
||||
|
||||
const HIGHWAY_APP_ID = 1600001604;
|
||||
@@ -32,20 +31,20 @@ function ipv4ToString(value: number): string {
|
||||
}
|
||||
|
||||
export async function fetchHighwaySession(bridge: Bridge): Promise<HighwaySession> {
|
||||
const request = protoEncode({
|
||||
const request = protobuf_encode<HttpConn0x6FF501Request>({
|
||||
httpConn: {
|
||||
field1: 0, field2: 0, field3: 16, field4: 1, field6: 3,
|
||||
serviceTypes: [1, 5, 10, 21],
|
||||
field9: 2, field10: 9, field11: 8, ver: '1.0.1',
|
||||
},
|
||||
}, HttpConn0x6FF501RequestSchema);
|
||||
});
|
||||
|
||||
const result = await bridge.sendRawPacket('HttpConn.0x6ff_501', request);
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(result.errorMessage || 'HttpConn request failed');
|
||||
}
|
||||
|
||||
const resp = protoDecode(result.responseData, HttpConn0x6FF501ResponseSchema);
|
||||
const resp = protobuf_decode<HttpConn0x6FF501Response>(result.responseData);
|
||||
if (!resp?.httpConn) throw new Error('HttpConn response body missing');
|
||||
if (!resp.httpConn.sigSession || (resp.httpConn.sigSession as Uint8Array).length === 0) {
|
||||
throw new Error('HttpConn response missing sig_session');
|
||||
@@ -78,7 +77,7 @@ function makeHighwayHead(
|
||||
uin: string, commandId: number, fileSize: number, offset: number, length: number,
|
||||
chunkMd5: Uint8Array, fileMd5: Uint8Array, sigSession: Uint8Array, extend: Uint8Array,
|
||||
): Uint8Array {
|
||||
return protoEncode({
|
||||
return protobuf_encode<ReqDataHighwayHead>({
|
||||
msgBaseHead: {
|
||||
version: 1, uin, command: 'PicUp.DataUp', seq: 0, retryTimes: 0,
|
||||
appId: HIGHWAY_APP_ID, dataFlag: 16, commandId,
|
||||
@@ -90,7 +89,7 @@ function makeHighwayHead(
|
||||
bytesReqExtendInfo: extend,
|
||||
timestamp: 0n,
|
||||
msgLoginSigHead: { loginSigType: 8, appId: HIGHWAY_APP_ID },
|
||||
}, ReqDataHighwayHeadSchema);
|
||||
});
|
||||
}
|
||||
|
||||
export function buildHighwayExtend(
|
||||
@@ -113,7 +112,7 @@ export function buildHighwayExtend(
|
||||
}
|
||||
}
|
||||
|
||||
return protoEncode({
|
||||
return protobuf_encode<NTV2RichMediaHighwayExt>({
|
||||
fileUuid: selected?.index?.fileUuid ?? '',
|
||||
uKey,
|
||||
network: { ipv4s: networkIpv4s },
|
||||
@@ -122,7 +121,7 @@ export function buildHighwayExtend(
|
||||
})),
|
||||
blockSize: HIGHWAY_BLOCK_SIZE,
|
||||
hash: { fileSha1: Array.isArray(sha1) ? sha1 : [sha1] },
|
||||
}, NTV2RichMediaHighwayExtSchema);
|
||||
});
|
||||
}
|
||||
|
||||
// --- TCP-based HTTP highway upload ---
|
||||
@@ -241,7 +240,7 @@ export async function uploadHighwayHttp(
|
||||
const frame = packHighwayFrame(head, chunk);
|
||||
const responseBody = await httpPostFrame(socket, session.host, pathStr, frame);
|
||||
const { head: respHead } = unpackHighwayFrame(responseBody);
|
||||
const resp = protoDecode(respHead, RespDataHighwayHeadSchema);
|
||||
const resp = protobuf_decode<RespDataHighwayHead>(respHead);
|
||||
if (resp?.errorCode && resp.errorCode !== 0) {
|
||||
throw new Error(`highway upload error_code=${resp.errorCode}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
// Proton (compile-time) form of bridge/proto/highway.ts.
|
||||
// One-to-one mirror; legacy `*Schema` constants stay alongside for back-compat.
|
||||
|
||||
import type { pb, pb_repeated, int_32, uint_32, uint_64, bool, bytes } from '@snowluma/proton';
|
||||
import type {
|
||||
IndexNode,
|
||||
PictureInfo,
|
||||
HashSum,
|
||||
PicExtBizInfo,
|
||||
VideoExtBizInfo,
|
||||
PttExtBizInfo,
|
||||
} from './element';
|
||||
|
||||
// ── DataHighwayHead ─────────────────────────────────────────────────
|
||||
|
||||
export interface DataHighwayHead {
|
||||
version?: pb<1, uint_32>;
|
||||
uin?: pb<2, string>;
|
||||
command?: pb<3, string>;
|
||||
seq?: pb<4, uint_32>;
|
||||
retryTimes?: pb<5, uint_32>;
|
||||
appId?: pb<6, uint_32>;
|
||||
dataFlag?: pb<7, uint_32>;
|
||||
commandId?: pb<8, uint_32>;
|
||||
}
|
||||
|
||||
export interface SegHead {
|
||||
serviceId?: pb<1, uint_32>;
|
||||
filesize?: pb<2, uint_64>;
|
||||
dataOffset?: pb<3, uint_64>;
|
||||
dataLength?: pb<4, uint_32>;
|
||||
retCode?: pb<5, uint_32>;
|
||||
serviceTicket?: pb<6, bytes>;
|
||||
flag?: pb<7, uint_32>;
|
||||
md5?: pb<8, bytes>;
|
||||
fileMd5?: pb<9, bytes>;
|
||||
cacheAddr?: pb<10, uint_32>;
|
||||
cachePort?: pb<13, uint_32>;
|
||||
}
|
||||
|
||||
export interface LoginSigHead {
|
||||
loginSigType?: pb<1, uint_32>;
|
||||
appId?: pb<3, uint_32>;
|
||||
}
|
||||
|
||||
export interface ReqDataHighwayHead {
|
||||
msgBaseHead?: pb<1, DataHighwayHead>;
|
||||
msgSegHead?: pb<2, SegHead>;
|
||||
bytesReqExtendInfo?: pb<3, bytes>;
|
||||
timestamp?: pb<4, uint_64>;
|
||||
msgLoginSigHead?: pb<5, LoginSigHead>;
|
||||
}
|
||||
|
||||
export interface RespDataHighwayHead {
|
||||
msgBaseHead?: pb<1, DataHighwayHead>;
|
||||
msgSegHead?: pb<2, SegHead>;
|
||||
errorCode?: pb<3, uint_32>;
|
||||
}
|
||||
|
||||
// ── Highway extend (NTV2RichMediaHighwayExt) ────────────────────────
|
||||
|
||||
export interface HighwayDomain {
|
||||
isEnable?: pb<1, bool>;
|
||||
ip?: pb<2, string>;
|
||||
}
|
||||
|
||||
export interface HighwayIPv4 {
|
||||
domain?: pb<1, HighwayDomain>;
|
||||
port?: pb<2, uint_32>;
|
||||
}
|
||||
|
||||
export interface HighwayNetwork {
|
||||
ipv4s?: pb_repeated<1, HighwayIPv4>;
|
||||
}
|
||||
|
||||
export interface HighwayHash {
|
||||
fileSha1?: pb_repeated<1, bytes>;
|
||||
}
|
||||
|
||||
export interface HighwayMsgInfoBody {
|
||||
index?: pb<1, IndexNode>;
|
||||
picture?: pb<2, PictureInfo>;
|
||||
fileExist?: pb<5, bool>;
|
||||
hashSum?: pb<6, HashSum>;
|
||||
}
|
||||
|
||||
export interface NTV2RichMediaHighwayExt {
|
||||
fileUuid?: pb<1, string>;
|
||||
uKey?: pb<2, string>;
|
||||
network?: pb<5, HighwayNetwork>;
|
||||
msgInfoBody?: pb_repeated<6, HighwayMsgInfoBody>;
|
||||
blockSize?: pb<10, uint_32>;
|
||||
hash?: pb<11, HighwayHash>;
|
||||
}
|
||||
|
||||
// ── File upload extend (group/private file highway) ─────────────────
|
||||
|
||||
export interface FileUploadUrl {
|
||||
unknown?: pb<1, int_32>;
|
||||
host?: pb<2, string>;
|
||||
}
|
||||
|
||||
export interface FileUploadHost {
|
||||
url?: pb<1, FileUploadUrl>;
|
||||
port?: pb<2, uint_32>;
|
||||
}
|
||||
|
||||
export interface FileUploadHostConfig {
|
||||
hosts?: pb_repeated<200, FileUploadHost>;
|
||||
}
|
||||
|
||||
export interface FileUploadNameInfo {
|
||||
fileName?: pb<100, string>;
|
||||
}
|
||||
|
||||
export interface FileUploadClientInfo {
|
||||
clientType?: pb<100, int_32>;
|
||||
appId?: pb<200, string>;
|
||||
terminalType?: pb<300, int_32>;
|
||||
clientVer?: pb<400, string>;
|
||||
unknown?: pb<600, int_32>;
|
||||
}
|
||||
|
||||
export interface FileUploadFileEntry {
|
||||
fileSize?: pb<100, uint_64>;
|
||||
md5?: pb<200, bytes>;
|
||||
checkKey?: pb<300, bytes>;
|
||||
md5S2?: pb<400, bytes>;
|
||||
fileId?: pb<600, string>;
|
||||
uploadKey?: pb<700, bytes>;
|
||||
}
|
||||
|
||||
export interface FileUploadBusiInfo {
|
||||
busId?: pb<1, int_32>;
|
||||
senderUin?: pb<100, uint_64>;
|
||||
receiverUin?: pb<200, uint_64>;
|
||||
groupCode?: pb<400, uint_64>;
|
||||
}
|
||||
|
||||
export interface FileUploadEntry {
|
||||
busiBuff?: pb<100, FileUploadBusiInfo>;
|
||||
fileEntry?: pb<200, FileUploadFileEntry>;
|
||||
clientInfo?: pb<300, FileUploadClientInfo>;
|
||||
fileNameInfo?: pb<400, FileUploadNameInfo>;
|
||||
host?: pb<500, FileUploadHostConfig>;
|
||||
}
|
||||
|
||||
export interface FileUploadExt {
|
||||
unknown1?: pb<1, int_32>;
|
||||
unknown2?: pb<2, int_32>;
|
||||
unknown3?: pb<3, int_32>;
|
||||
entry?: pb<100, FileUploadEntry>;
|
||||
unknown200?: pb<200, int_32>;
|
||||
}
|
||||
|
||||
// ── Encodable MsgInfo (for embedding in message element) ────────────
|
||||
|
||||
export interface EncodableMediaExtBizInfo {
|
||||
pic?: pb<1, PicExtBizInfo>;
|
||||
video?: pb<2, VideoExtBizInfo>;
|
||||
ptt?: pb<3, PttExtBizInfo>;
|
||||
busiType?: pb<10, uint_32>;
|
||||
}
|
||||
|
||||
export interface EncodableMediaMsgInfo {
|
||||
msgInfoBody?: pb_repeated<1, HighwayMsgInfoBody>;
|
||||
extBizInfo?: pb<2, EncodableMediaExtBizInfo>;
|
||||
}
|
||||
|
||||
// ── HttpConn.0x6ff_501 (highway session) ────────────────────────────
|
||||
|
||||
export interface HttpConn {
|
||||
field1?: pb<1, int_32>;
|
||||
field2?: pb<2, int_32>;
|
||||
field3?: pb<3, int_32>;
|
||||
field4?: pb<4, int_32>;
|
||||
field6?: pb<6, int_32>;
|
||||
serviceTypes?: pb_repeated<7, uint_32>;
|
||||
field9?: pb<9, int_32>;
|
||||
field10?: pb<10, int_32>;
|
||||
field11?: pb<11, int_32>;
|
||||
ver?: pb<15, string>;
|
||||
}
|
||||
|
||||
export interface HttpConn0x6FF501Request {
|
||||
httpConn?: pb<0x501, HttpConn>;
|
||||
}
|
||||
|
||||
export interface ServerAddr {
|
||||
type?: pb<1, uint_32>;
|
||||
ip?: pb<2, uint_32>;
|
||||
port?: pb<3, uint_32>;
|
||||
area?: pb<4, uint_32>;
|
||||
}
|
||||
|
||||
export interface ServerInfo {
|
||||
serviceType?: pb<1, uint_32>;
|
||||
serverAddrs?: pb_repeated<2, ServerAddr>;
|
||||
}
|
||||
|
||||
export interface HttpConnResponse {
|
||||
sigSession?: pb<1, bytes>;
|
||||
sessionKey?: pb<2, bytes>;
|
||||
serverInfos?: pb_repeated<3, ServerInfo>;
|
||||
}
|
||||
|
||||
export interface HttpConn0x6FF501Response {
|
||||
httpConn?: pb<0x501, HttpConnResponse>;
|
||||
}
|
||||
|
||||
// ── NTV2 Upload Request (for OIDB 0x11C4/0x11C5) ────────────────────
|
||||
|
||||
export interface NTV2FileType {
|
||||
type?: pb<1, uint_32>;
|
||||
picFormat?: pb<2, uint_32>;
|
||||
videoFormat?: pb<3, uint_32>;
|
||||
voiceFormat?: pb<4, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2FileInfo {
|
||||
fileSize?: pb<1, uint_32>;
|
||||
fileHash?: pb<2, string>;
|
||||
fileSha1?: pb<3, string>;
|
||||
fileName?: pb<4, string>;
|
||||
type?: pb<5, NTV2FileType>;
|
||||
width?: pb<6, uint_32>;
|
||||
height?: pb<7, uint_32>;
|
||||
time?: pb<8, uint_32>;
|
||||
original?: pb<9, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadInfo {
|
||||
fileInfo?: pb<1, NTV2FileInfo>;
|
||||
subFileType?: pb<2, uint_32>;
|
||||
}
|
||||
|
||||
// The NTV2 upload request + response carry the same ExtBizInfo shape that
|
||||
// element-side incoming-message decoding uses. See bridge/proto/highway.ts
|
||||
// for the rationale (the video fromScene/toScene drop was responsible for
|
||||
// c2c result=79 rejections on send_private_msg [{type:'video'}]).
|
||||
export interface NTV2ExtBizInfo {
|
||||
pic?: pb<1, PicExtBizInfo>;
|
||||
video?: pb<2, VideoExtBizInfo>;
|
||||
ptt?: pb<3, PttExtBizInfo>;
|
||||
busiType?: pb<10, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadReq {
|
||||
uploadInfo?: pb_repeated<1, NTV2UploadInfo>;
|
||||
tryFastUploadCompleted?: pb<2, bool>;
|
||||
srvSendMsg?: pb<3, bool>;
|
||||
clientRandomId?: pb<4, uint_64>;
|
||||
compatQmsgSceneType?: pb<5, uint_32>;
|
||||
extBizInfo?: pb<6, NTV2ExtBizInfo>;
|
||||
clientSeq?: pb<7, uint_32>;
|
||||
noNeedCompatMsg?: pb<8, bool>;
|
||||
}
|
||||
|
||||
export interface NTV2C2CUserInfo {
|
||||
accountType?: pb<1, uint_32>;
|
||||
targetUid?: pb<2, string>;
|
||||
}
|
||||
|
||||
export interface NTV2GroupInfo {
|
||||
groupUin?: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadSceneInfo {
|
||||
requestType?: pb<101, uint_32>;
|
||||
businessType?: pb<102, uint_32>;
|
||||
sceneType?: pb<200, uint_32>;
|
||||
c2c?: pb<201, NTV2C2CUserInfo>;
|
||||
group?: pb<202, NTV2GroupInfo>;
|
||||
}
|
||||
|
||||
export interface NTV2CommonHead {
|
||||
requestId?: pb<1, uint_32>;
|
||||
command?: pb<2, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2ClientMeta {
|
||||
agentType?: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadReqHead {
|
||||
common?: pb<1, NTV2CommonHead>;
|
||||
scene?: pb<2, NTV2UploadSceneInfo>;
|
||||
client?: pb<3, NTV2ClientMeta>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadRichMediaReq {
|
||||
reqHead?: pb<1, NTV2UploadReqHead>;
|
||||
upload?: pb<2, NTV2UploadReq>;
|
||||
}
|
||||
|
||||
// ── NTV2 Upload Response ────────────────────────────────────────────
|
||||
|
||||
export interface NTV2IPv4 {
|
||||
outIp?: pb<1, uint_32>;
|
||||
outPort?: pb<2, uint_32>;
|
||||
}
|
||||
|
||||
export interface NTV2SubFileInfoResp {
|
||||
subType?: pb<1, uint_32>;
|
||||
uKey?: pb<2, string>;
|
||||
uKeyTtl?: pb<3, uint_32>;
|
||||
ipv4s?: pb_repeated<4, NTV2IPv4>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadRespMsgInfo {
|
||||
msgInfoBody?: pb_repeated<1, HighwayMsgInfoBody>;
|
||||
extBizInfo?: pb<2, NTV2ExtBizInfo>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadRespBody {
|
||||
uKey?: pb<1, string>;
|
||||
uKeyTtl?: pb<2, uint_32>;
|
||||
ipv4s?: pb_repeated<3, NTV2IPv4>;
|
||||
msgSeq?: pb<5, uint_64>;
|
||||
msgInfo?: pb<6, NTV2UploadRespMsgInfo>;
|
||||
subFileInfos?: pb_repeated<10, NTV2SubFileInfoResp>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadRespHead {
|
||||
common?: pb<1, NTV2CommonHead>;
|
||||
retCode?: pb<2, uint_32>;
|
||||
message?: pb<3, string>;
|
||||
}
|
||||
|
||||
export interface NTV2UploadRichMediaResp {
|
||||
respHead?: pb<1, NTV2UploadRespHead>;
|
||||
upload?: pb<2, NTV2UploadRespBody>;
|
||||
}
|
||||
@@ -43,6 +43,13 @@ import {
|
||||
MentionExtraSendSchema,
|
||||
MarkdownDataSchema,
|
||||
} from '../src/bridge/proto/action';
|
||||
import {
|
||||
HttpConn0x6FF501RequestSchema,
|
||||
HttpConn0x6FF501ResponseSchema,
|
||||
ReqDataHighwayHeadSchema,
|
||||
NTV2RichMediaHighwayExtSchema,
|
||||
FileUploadExtSchema,
|
||||
} from '../src/bridge/proto/highway';
|
||||
|
||||
import type {
|
||||
SendLongMsgResp,
|
||||
@@ -80,6 +87,13 @@ import type {
|
||||
MentionExtraSend,
|
||||
MarkdownData,
|
||||
} from '../src/bridge/proto/proton/action';
|
||||
import type {
|
||||
HttpConn0x6FF501Request,
|
||||
HttpConn0x6FF501Response,
|
||||
ReqDataHighwayHead,
|
||||
NTV2RichMediaHighwayExt,
|
||||
FileUploadExt,
|
||||
} from '../src/bridge/proto/proton/highway';
|
||||
|
||||
function hex(buf: Uint8Array): string {
|
||||
return Buffer.from(buf).toString('hex');
|
||||
@@ -463,6 +477,108 @@ describe('proton ↔ legacy parity (longmsg subset)', () => {
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── highway.ts coverage ────────────────────────────────────────────
|
||||
|
||||
it('encodes HttpConn0x6FF501Request (high-numbered field tag 0x501) identically', () => {
|
||||
const data: HttpConn0x6FF501Request = {
|
||||
httpConn: {
|
||||
field1: 1, field2: 2, field3: 16, field4: 1, field6: 3,
|
||||
serviceTypes: [1, 5, 10, 21],
|
||||
field9: 2, field10: 9, field11: 8, ver: '1.0.1',
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, HttpConn0x6FF501RequestSchema);
|
||||
const proton = protobuf_encode<HttpConn0x6FF501Request>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes HttpConn0x6FF501Response (with repeated server infos) identically', () => {
|
||||
const data: HttpConn0x6FF501Response = {
|
||||
httpConn: {
|
||||
sigSession: new Uint8Array([1, 2, 3]),
|
||||
sessionKey: new Uint8Array([4, 5, 6]),
|
||||
serverInfos: [
|
||||
{ serviceType: 1, serverAddrs: [{ type: 1, ip: 0x01020304, port: 8080, area: 1 }] },
|
||||
{ serviceType: 2, serverAddrs: [{ type: 1, ip: 0x05060708, port: 8081, area: 2 }] },
|
||||
],
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, HttpConn0x6FF501ResponseSchema);
|
||||
const proton = protobuf_encode<HttpConn0x6FF501Response>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes ReqDataHighwayHead (multiple nested messages) identically', () => {
|
||||
const data: ReqDataHighwayHead = {
|
||||
msgBaseHead: {
|
||||
version: 1, uin: '10001', command: 'PicUp.DataUp', seq: 1, retryTimes: 1,
|
||||
appId: 1600001604, dataFlag: 16, commandId: 1003,
|
||||
},
|
||||
msgSegHead: {
|
||||
serviceId: 1, filesize: 100n, dataOffset: 50n, dataLength: 100,
|
||||
retCode: 1, serviceTicket: new Uint8Array([1, 2, 3]), flag: 1,
|
||||
md5: new Uint8Array([4, 5, 6]), fileMd5: new Uint8Array([7, 8, 9]),
|
||||
cacheAddr: 1, cachePort: 80,
|
||||
},
|
||||
bytesReqExtendInfo: new Uint8Array([0xab, 0xcd]),
|
||||
timestamp: 1234567890n,
|
||||
msgLoginSigHead: { loginSigType: 8, appId: 1600001604 },
|
||||
};
|
||||
const legacy = protoEncode(data as any, ReqDataHighwayHeadSchema);
|
||||
const proton = protobuf_encode<ReqDataHighwayHead>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes NTV2RichMediaHighwayExt (repeated_bytes hash) identically', () => {
|
||||
const data: NTV2RichMediaHighwayExt = {
|
||||
fileUuid: 'uuid-1',
|
||||
uKey: 'key-1',
|
||||
network: { ipv4s: [{ domain: { isEnable: true, ip: '127.0.0.1' }, port: 80 }] },
|
||||
blockSize: 1048576,
|
||||
hash: { fileSha1: [new Uint8Array([1, 2]), new Uint8Array([3, 4])] },
|
||||
};
|
||||
const legacy = protoEncode(data as any, NTV2RichMediaHighwayExtSchema);
|
||||
const proton = protobuf_encode<NTV2RichMediaHighwayExt>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes FileUploadExt (high-numbered tags 100/200/400/600/700) identically', () => {
|
||||
const data: FileUploadExt = {
|
||||
unknown1: 100,
|
||||
unknown2: 1,
|
||||
unknown3: 1,
|
||||
entry: {
|
||||
busiBuff: {
|
||||
busId: 102,
|
||||
senderUin: 10001n,
|
||||
receiverUin: 555n,
|
||||
groupCode: 555n,
|
||||
},
|
||||
fileEntry: {
|
||||
fileSize: 12345n,
|
||||
md5: new Uint8Array([0x11, 0x22]),
|
||||
checkKey: new Uint8Array([0x33, 0x44]),
|
||||
md5S2: new Uint8Array([0x55]),
|
||||
fileId: 'file-1',
|
||||
uploadKey: new Uint8Array([0x66]),
|
||||
},
|
||||
clientInfo: {
|
||||
clientType: 3, appId: '100', terminalType: 3, clientVer: '1.1.1', unknown: 4,
|
||||
},
|
||||
fileNameInfo: { fileName: 'a.bin' },
|
||||
host: {
|
||||
hosts: [
|
||||
{ url: { unknown: 1, host: 'upload.qq.com' }, port: 80 },
|
||||
],
|
||||
},
|
||||
},
|
||||
unknown200: 1,
|
||||
};
|
||||
const legacy = protoEncode(data as any, FileUploadExtSchema);
|
||||
const proton = protobuf_encode<FileUploadExt>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── Documented divergence: proto3 default-value omission ────────────
|
||||
|
||||
it('proton omits default-valued numeric fields (legacy emits them)', () => {
|
||||
|
||||
Reference in new issue
Block a user