コード例 #1
0
        /// <summary>
        /// Returns the Uuid from a series of bytes
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static string BytesToUuid(AppendableByteArray bytes, int offset)
        {
            byte[] uuid = bytes.GetSubarray(offset, UUID_LEN);

            ASCIIEncoding encoding = new ASCIIEncoding();

            return(encoding.GetString(uuid));
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new asset object with the given data
        /// </summary>
        /// <param name="dataSize"></param>
        public Asset(AppendableByteArray data)
        {
            _uuid       = Util.BytesToUuid(data, 0);
            _type       = data.data[TYPE_TAG_LOC];
            _local      = data.data[LOCAL_TAG_LOC] == 1;
            _temporary  = data.data[TEMPORARY_TAG_LOC] == 1;
            _createTime = Util.NTOHL(data.data, CREATE_TIME_TAG_LOC);

            //now the dynamic sized fields
            UTF8Encoding encoding = new UTF8Encoding();

            //the name field
            byte nameFieldSize = data.data[NAME_SIZE_TAG_LOC];

            if (nameFieldSize > 0)
            {
                _name = encoding.GetString(data.data, NAME_SIZE_TAG_LOC + 1, nameFieldSize);
            }
            else
            {
                _name = String.Empty;
            }

            //the description field
            int  descSizeFieldLoc = NAME_SIZE_TAG_LOC + nameFieldSize + 1;
            byte descFieldSize    = data.data[descSizeFieldLoc];

            if (descFieldSize > 0)
            {
                _description = encoding.GetString(data.data, descSizeFieldLoc + 1, descFieldSize);
            }
            else
            {
                _description = String.Empty;
            }

            //finally, get the location of the data and it's size
            int dataSizeFieldLoc = descSizeFieldLoc + descFieldSize + 1;
            int dataSize         = Util.NTOHL(data.data, dataSizeFieldLoc);
            int dataLoc          = dataSizeFieldLoc + 4;

            //create the array now so that it will be shared between all reqestors
            if (dataSize > 0)
            {
                _data = data.GetSubarray(dataLoc, dataSize);
            }
            else
            {
                _data = new byte[0];
            }
        }