// 将本节点以及所有子节点编码为BER包 // parameters: // nMaxBytes 限制产生包的最大尺寸。如果为 -1,表示不限定 public void EncodeBERPackage(ref byte[] baPackage, int nMaxBytes = -1) { // 1.得到全部子节点的BER包 BerNode node = null; byte[] baTempPackage = null; // nMax = m_ChildArray.GetSize(); if (this.ChildrenCollection.Count != 0) { for (int i = 0; i < this.ChildrenCollection.Count; i++) { node = this.ChildrenCollection[i]; Debug.Assert(node != null); // 递归 baTempPackage = null; node.EncodeBERPackage(ref baTempPackage, nMaxBytes); if (baTempPackage == null) { // 是否有问题? continue; // 2008/12/17 } Debug.Assert(baTempPackage != null, ""); // 2008/12/17 baPackage = ByteArray.SafeAdd(baPackage, baTempPackage, nMaxBytes); } } else { Debug.Assert(this.m_baData != null, ""); // 2007/7/20 baPackage = ByteArray.SafeAdd(baPackage, this.m_baData, nMaxBytes); } // 2.根据1.步得到的包长度,最终加入本节点需要的识别信息 if (baPackage == null) { throw new ArgumentException("MakeHeadPart() 之前 baPackage 为 null"); } MakeHeadPart(ref baTempPackage, baPackage.Length); baPackage = ByteArray.SafeAdd(baTempPackage, baPackage, nMaxBytes); }
// 将本结点以及所有子结点编码为BER包 public void EncodeBERPackage(ref byte[] baPackage) { // 1.得到全部子结点的BER包 BerNode node = null; byte[] baTempPackage = null; // nMax = m_ChildArray.GetSize(); if (this.ChildrenCollection.Count != 0) { for (int i = 0; i < this.ChildrenCollection.Count; i++) { node = this.ChildrenCollection[i]; Debug.Assert(node != null); // 递归 baTempPackage = null; node.EncodeBERPackage(ref baTempPackage); if (baTempPackage == null) { // 是否有问题? continue; // 2008/12/17 } Debug.Assert(baTempPackage != null, ""); // 2008/12/17 baPackage = ByteArray.Add(baPackage, baTempPackage); } } else { Debug.Assert(this.m_baData != null, ""); // 2007/7/20 baPackage = ByteArray.Add(baPackage, this.m_baData); } // 2.根据1.步得到的包长度,最终加入本结点需要的识别信息 MakeHeadPart(ref baTempPackage, baPackage.Length); baPackage = ByteArray.Add(baTempPackage, baPackage); }