Esempio n. 1
0
        public int ReadBinHex(byte[] buffer, int offset, int length)
        {
            if (offset < 0)
            {
                throw new ArgumentException(
                          "Offset must be non-negative integer.");
            }
            else if (length < 0)
            {
                throw new ArgumentException(
                          "Length must be non-negative integer.");
            }
            else if (buffer.Length < offset + length)
            {
                throw new ArgumentException(
                          "buffer length is smaller than the sum of offset and length.");
            }
            if (length == 0)
            {
                return(0);
            }
            char[] chars       = new char[length * 2];
            int    charsLength = ReadValueChunk(chars, 0, length * 2);

            return(Base64Coder.FromBinHexString(chars, offset, charsLength, buffer));
        }
Esempio n. 2
0
 public string GetBase64()
 {
     byte[] buffer = Base64Coder.Encode(bytes);
     try {
         return(StringUtils.GetString(buffer));
     } catch (IOException) {
         return(StringUtils.GetString(buffer));
     }
 }
Esempio n. 3
0
 public NSData(byte[] b)
 {
     if (Base64Coder.IsArrayByteBase64(b))
     {
         bytes = Base64Coder.Decode(b);
     }
     else
     {
         this.bytes = b;
     }
 }
Esempio n. 4
0
        public override string ToString()
        {
            if (_bytes.IsEmpty)
            {
                return(string.Empty);
            }

            var resultLenght = Base64Coder.ComputeBase64EncodedLength(_bytes.Span);
            var result       = new string('\0', resultLenght);
            var memory       = MemoryMarshal.AsMemory(result.AsMemory());

            var writtenMemory = Base64Coder.ToBase64Chars(_bytes.Span, memory.Span);

            Assert(writtenMemory.Length == resultLenght);

            return(result);
        }
Esempio n. 5
0
        public NSData(string base64)
        {
            string data = "";

            if (Base64Coder.IsBase64(base64))
            {
                foreach (string line  in  Loon.Utils.StringUtils.Split(base64, "\n"))
                {
                    data += line.Trim();
                }
                char[] enc = data.ToCharArray();
                bytes = Base64Coder.DecodeBase64(enc);
            }
            else
            {
                this.bytes = Loon.Utils.StringUtils.GetBytes(base64);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 根据TMX地图描述创建一个新层
        /// </summary>
        ///
        /// <param name="map"></param>
        /// <param name="element"></param>
        /// <exception cref="System.Exception"></exception>
        public TMXLayer(TMXTiledMap map, XMLElement element)
        {
            this.tmx    = map;
            this.name   = element.GetAttribute("name", "");
            this.width  = element.GetIntAttribute("width", 0);
            this.height = element.GetIntAttribute("height", 0);
            this.data   = new int[width, height, 3];
            this.MaxLightSize(width, height);

            // 获得当前图层属性
            XMLElement propsElement = element.GetChildrenByName("properties");

            if (propsElement != null)
            {
                props = new TMXProperty();
                List <XMLElement> properties = propsElement.List("property");
                for (int i = 0; i < properties.Count; i++)
                {
                    XMLElement propElement = properties[i];
                    string     name_0      = propElement.GetAttribute("name", null);
                    string     value_ren   = propElement.GetAttribute("value", null);
                    props.SetProperty(name_0, value_ren);
                }
            }

            XMLElement dataNode    = element.GetChildrenByName("data");
            string     encoding    = dataNode.GetAttribute("encoding", null);
            string     compression = dataNode.GetAttribute("compression", null);

            // 进行base64的压缩解码
            if ("base64".Equals(encoding) && "gzip".Equals(compression))
            {
                try
                {
                    byte[] sdec = Base64Coder.DecodeBase64(dataNode.GetContents().Trim().ToCharArray());

                    ByteArrayInputStream mask0 = new ByteArrayInputStream(sdec);

                    GZipInputStream dis = new GZipInputStream(mask0);

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            int tileId = 0;

                            tileId |= dis.ReadByte();
                            tileId |= dis.ReadByte() << 8;
                            tileId |= dis.ReadByte() << 16;
                            tileId |= dis.ReadByte() << 24;

                            if (tileId == 0)
                            {
                                data[x, y, 0] = -1;
                                data[x, y, 1] = 0;
                                data[x, y, 2] = 0;
                            }
                            else
                            {
                                TMXTileSet set = map.FindTileSet(tileId);

                                if (set != null)
                                {
                                    data[x, y, 0] = set.index;
                                    data[x, y, 1] = tileId - set.firstGID;
                                }
                                data[x, y, 2] = tileId;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Loon.Utils.Debug.Log.Exception(e);
                    throw new Exception("Unable to decode base64 !");
                }
            }
            else
            {
                throw new Exception("Unsupport tiled map type " + encoding
                                    + "," + compression + " only gzip base64 Support !");
            }
        }