Example #1
0
        /// <summary>
        /// Type設定
        /// </summary>
        /// <param name="tnf">TNF</param>
        /// <param name="type">タイプデータ</param>
        public void setType(TNF_TYPE tnf, byte[] type)
        {
            mTnf  = tnf;
            mType = type;

            mHead &= 0xf8;
            switch (mTnf)
            {
            case TNF_TYPE.WKS:
                mHead |= 0x01;
                break;

            case TNF_TYPE.MIME:
                mHead |= 0x02;
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Type設定
        /// </summary>
        /// <param name="tnf">TNF</param>
        /// <param name="type">タイプデータ</param>
        public void setType(TNF_TYPE tnf, byte[] type)
        {
            mTnf = tnf;
            mType = type;

            mHead &= 0xf8;
            switch(mTnf) {
            case TNF_TYPE.WKS:
                mHead |= 0x01;
                break;
            case TNF_TYPE.MIME:
                mHead |= 0x02;
                break;
            }
        }
Example #3
0
        /// <summary>
        /// NDEFレコードからNdefRecordを構築
        /// </summary>
        /// <param name="rec"></param>
        public void setRecord(byte[] rec)
        {
            mTnf = TNF_TYPE.EMPTY;
            mType = null;
            mID = null;
            mPayload = null;

            if((rec == null) || (rec.Length < 3)) {
                //足りない
                return;
            }
            if(((rec[0] & 0x20) == 0) || ((rec[0] & 0x10) == 0)) {
                //Chunkなし、Short Recordのみにする
                return;
            }
            if(((rec[0] & 0x08) != 0) && (rec.Length < 4)) {
                //IL=1なら4byteは必要
                return;
            }

            //長さチェック
            if((rec[0] & 0x08) != 0) {
                //IL=1
                if(4 + rec[1] + rec[2] + rec[3] > rec.Length) {
                    //HEAD+TypeLen+PayloadLen+IDLen+Type+ID+Payloadが全長よりも長いことはない
                    return;
                }
            }
            else {
                //IL=0
                if(3 + rec[1] + rec[2] > rec.Length) {
                    //HEAD+TypeLen+PayloadLen+Type+Payloadが全長よりも長いことはない
                    return;
                }
            }

            switch(rec[0] & 0x07) {
            case 0x01:
                mTnf = TNF_TYPE.WKS;
                break;
            case 0x02:
                mTnf = TNF_TYPE.MIME;
                break;
            default:
                //WKSかMIMEのみにする
                return;
            }

            mHead = rec[0];

            int pos = 1;

            //Type Length
            if(rec[pos] > 0) {
                mType = new byte[rec[1]];
            }
            pos++;

            //Payload Length
            if(rec[pos] > 0) {
                mPayload = new byte[rec[2]];
            }
            pos++;

            //ID Length(存在する場合)
            if((mHead & 0x08) != 0) {
                //IL=1
                if(rec[pos] > 0) {
                    mID = new byte[rec[3]];
                    mHead |= 0x80;
                }
                pos++;
            }

            if(mType.Length > 0) {
                Buffer.BlockCopy(rec, pos, mType, 0, mType.Length);
                pos += mType.Length;
            }
            if(mID.Length > 0) {
                Buffer.BlockCopy(rec, pos, mID, 0, mID.Length);
                pos += mID.Length;
            }
            if(mPayload.Length > 0) {
                Buffer.BlockCopy(rec, pos, mPayload, 0, mPayload.Length);
                pos += mPayload.Length;
            }
        }
Example #4
0
        /// <summary>
        /// NDEFレコードからNdefRecordを構築
        /// </summary>
        /// <param name="rec"></param>
        public void setRecord(byte[] rec)
        {
            mTnf     = TNF_TYPE.EMPTY;
            mType    = null;
            mID      = null;
            mPayload = null;

            if ((rec == null) || (rec.Length < 3))
            {
                //足りない
                return;
            }
            if (((rec[0] & 0x20) == 0) || ((rec[0] & 0x10) == 0))
            {
                //Chunkなし、Short Recordのみにする
                return;
            }
            if (((rec[0] & 0x08) != 0) && (rec.Length < 4))
            {
                //IL=1なら4byteは必要
                return;
            }

            //長さチェック
            if ((rec[0] & 0x08) != 0)
            {
                //IL=1
                if (4 + rec[1] + rec[2] + rec[3] > rec.Length)
                {
                    //HEAD+TypeLen+PayloadLen+IDLen+Type+ID+Payloadが全長よりも長いことはない
                    return;
                }
            }
            else
            {
                //IL=0
                if (3 + rec[1] + rec[2] > rec.Length)
                {
                    //HEAD+TypeLen+PayloadLen+Type+Payloadが全長よりも長いことはない
                    return;
                }
            }

            switch (rec[0] & 0x07)
            {
            case 0x01:
                mTnf = TNF_TYPE.WKS;
                break;

            case 0x02:
                mTnf = TNF_TYPE.MIME;
                break;

            default:
                //WKSかMIMEのみにする
                return;
            }

            mHead = rec[0];

            int pos = 1;

            //Type Length
            if (rec[pos] > 0)
            {
                mType = new byte[rec[1]];
            }
            pos++;

            //Payload Length
            if (rec[pos] > 0)
            {
                mPayload = new byte[rec[2]];
            }
            pos++;

            //ID Length(存在する場合)
            if ((mHead & 0x08) != 0)
            {
                //IL=1
                if (rec[pos] > 0)
                {
                    mID    = new byte[rec[3]];
                    mHead |= 0x80;
                }
                pos++;
            }

            if (mType.Length > 0)
            {
                Buffer.BlockCopy(rec, pos, mType, 0, mType.Length);
                pos += mType.Length;
            }
            if (mID.Length > 0)
            {
                Buffer.BlockCopy(rec, pos, mID, 0, mID.Length);
                pos += mID.Length;
            }
            if (mPayload.Length > 0)
            {
                Buffer.BlockCopy(rec, pos, mPayload, 0, mPayload.Length);
                pos += mPayload.Length;
            }
        }