示例#1
0
 public bool isValidTLVPack(byte[] apcBuf, int aiUsedSize, int offset)
 {
     if (apcBuf != null)
     {
         if (aiUsedSize < this.m_ptHeader.getSize())
         {
             return(false);
         }
         TLVPackHeader header = new TLVPackHeader {
             h_pcBuf = apcBuf,
             offset  = offset
         };
         if (header.getMagic() != 0x81)
         {
             return(false);
         }
         int aiSize = aiUsedSize - header.getSize();
         if (header.getUsedSize() != aiSize)
         {
             return(false);
         }
         byte[] buffer  = TLVUtil.getCheckSum(apcBuf, offset + header.getSize(), aiSize);
         byte[] buffer2 = header.getCheckSum();
         if ((buffer[0] != buffer2[0]) || (buffer[1] != buffer2[1]))
         {
             return(false);
         }
         if (aiSize == 0)
         {
             return(true);
         }
         FixedSizeTLVBody     body = new FixedSizeTLVBody();
         tVariableSizeTLVItem item = new tVariableSizeTLVItem();
         TLVBody body2             = null;
         if (header.getMode() == 0)
         {
             body2 = body;
         }
         else if (header.getMode() == 1)
         {
             body2 = item;
         }
         else
         {
             return(false);
         }
         if (body2.MapTo(apcBuf, offset + aiUsedSize, offset + header.getSize()))
         {
             while (body2.iNextOffset != 0)
             {
                 if (!body2.MapTo(apcBuf, offset + aiUsedSize, body2.iNextOffset))
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
示例#2
0
 public TLVPack(int aiInitBufSize, int mode)
 {
     this.m_eDefaultMode = mode;
     this.m_pcBuf        = null;
     this.m_iAllocSize   = 0;
     this.m_iUsedSize    = 0;
     this.m_ptHeader     = new TLVPackHeader();
 }
示例#3
0
 private void clear()
 {
     if (this.m_pcBuf == null)
     {
         this.m_iAllocSize = 0;
         this.m_iUsedSize  = 0;
         this.m_ptHeader   = null;
     }
     else if (this.m_iAllocSize < this.m_ptHeader.getSize())
     {
         this.m_ptHeader  = null;
         this.m_iUsedSize = 0;
     }
     else
     {
         TLVUtil.fillByteArray(this.m_pcBuf, 0);
         this.m_iUsedSize        = this.m_ptHeader.getSize();
         this.m_ptHeader.h_pcBuf = this.m_pcBuf;
         this.m_ptHeader.offset  = 0;
         this.m_ptHeader.setMagic(0x81).setCheckSum(new byte[2]).setUsedSize(0).setMode((byte)this.m_eDefaultMode);
     }
 }