使用Go结构体解析TCP抓包中的ASN.1十六进制编码数据
Let's break down your hex-encoded ASN.1 BER data step by step using the provided ConnectionEstablishedReply and MessageFields definitions:
First, note that the initial 18 00 1c bytes appear to be a TCP payload prefix (possibly a protocol-specific length header), since the ASN.1 sequence starts at 30.
Parsing the ASN.1 BER Data
Top-Level: ConnectionEstablishedReply (SEQUENCE)
- Tag:
30(Universal constructed sequence) - Length:
80(Indefinite length, meaning the sequence ends with00 00)
1. message (MessageFields SEQUENCE)
This is the first element, tagged as a0 (context-specific constructed tag 0):
- Tag:
a0 - Length:
80(indefinite length, ends with00 00) - Inner values:
messageSequence:80 01 06→ Context-specific primitive tag 0, length 1, value06= 6 (fits the1..65535constraint)bsId(optional):83 02 00 e2→ Context-specific primitive tag3, length2, value00 e2= 226 (valid integer in range)- Terminator:
00 00(closes theMessageFieldssequence)
2. nackReason (Optional)
Present here as a2 (context-specific constructed tag2):
- Tag:
a2 - Length:
80(indefinite length, ends with00 00) - Inner value:
80 01 01→ Context-specific primitive tag0, length1, value01= 1 (assumingNackReasonis an integer/enum type) - Terminator:
00 00(closes this sequence)
3. interfaceVersion
- Tag:
81(context-specific primitive tag1) - Length:
01 - Value:
0d= 13
4. mediatorId
- Tag:
83(context-specific primitive tag3) - Length:
01 - Value:
65= 101 (fits1..65535)
5. waitForCommit (Optional)
Not present in this encoding (no corresponding TLV found before the top-level terminator)
Final Decoded Structure
ConnectionEstablishedReply { message: { messageSequence: 6, bsId: 226 }, nackReason: 1, interfaceVersion: 13, mediatorId: 101 }
内容的提问来源于stack exchange,提问作者gvij
相关产品推荐
相关产品推荐

