@@ -154,6 +154,39 @@ func (c *base) IsGNack() bool {
154154 return c .CommandID == data .GENERIC_NACK
155155}
156156
157+ // GetSARConcatInfo checks optional TLV params for SAR fields and returns concatenation info.
158+ func (c * base ) GetSARConcatInfo () (totalParts , partNum byte , mref uint16 , found bool ) {
159+ var foundRef , foundTot , foundSeq bool
160+ // Iterate over all optional TLV fields attached to this PDU
161+ for _ , tlv := range c .OptionalParameters { // (Assume c.OptionalParams holds the list of TLV Field structs)
162+ switch tlv .Tag {
163+ case TagSarMsgRefNum : // SAR reference number (should be 2 bytes)
164+ if len (tlv .Data ) == 2 {
165+ // Combine two bytes into a 16-bit reference (big-endian as per SMPP spec)
166+ mref = uint16 (tlv .Data [0 ])<< 8 | uint16 (tlv .Data [1 ])
167+ foundRef = true
168+ }
169+ case TagSarTotalSegments : // Total number of segments (1 byte)
170+ if len (tlv .Data ) == 1 {
171+ totalParts = tlv .Data [0 ]
172+ foundTot = true
173+ }
174+ case TagSarSegmentSeqnum : // Segment sequence number (1 byte)
175+ if len (tlv .Data ) == 1 {
176+ partNum = tlv .Data [0 ]
177+ foundSeq = true
178+ }
179+ }
180+ }
181+ // All three must be found to consider the data complete
182+ found = foundRef && foundTot && foundSeq
183+ if ! found {
184+ // If any part is missing or lengths were incorrect, return with 'found' = false and zeros
185+ totalParts , partNum , mref = 0 , 0 , 0
186+ }
187+ return
188+ }
189+
157190// Parse PDU from reader.
158191func Parse (r io.Reader ) (pdu PDU , err error ) {
159192 var headerBytes [16 ]byte
0 commit comments