当前位置: 首页>>代码示例>>C#>>正文


C# Core.PhpBytes类代码示例

本文整理汇总了C#中PHP.Core.PhpBytes的典型用法代码示例。如果您正苦于以下问题:C# PhpBytes类的具体用法?C# PhpBytes怎么用?C# PhpBytes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PhpBytes类属于PHP.Core命名空间,在下文中一共展示了PhpBytes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Concat

        static void Concat()
        {
            PhpBytes a = new PhpBytes(new byte[] { 61, 62, 63 });
            string b = "-hello-";
            PhpBytes c = new PhpBytes(new byte[] { 61, 61, 61 });
            string d = "-bye-";

            object result = Operators.Concat(a, b, c, d);
            Assert.IsTrue(Operators.StrictEquality(result, "=>?-hello-===-bye-"));
        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:10,代码来源:OperatorsTests.cs

示例2: Unpack

		public static PhpArray Unpack(string format, PhpBytes data)
		{
			if (format == null) return null;
			byte[] buffer = (data != null) ? data.ReadonlyData : ArrayUtils.EmptyBytes;

			Encoding encoding = Configuration.Application.Globalization.PageEncoding;
			byte[] reversed = new byte[4]; // used for reversing the order of bytes in buffer

			int i = 0;
			int pos = 0;
			PhpArray result = new PhpArray();

			while (i < format.Length)
			{
				string name;
				int repeater;
				char specifier;

				// parses specifier, repeater, and name from the format string:
				ParseFormatToken(format, ref i, out specifier, out repeater, out name);

				int remains = buffer.Length - pos;          // the number of bytes remaining in the buffer
				int size;                                   // a size of data to be extracted corresponding to the specifier  

				// repeater of '@' specifier has a special meaning:
				if (specifier == '@')
				{
					if (repeater > buffer.Length || repeater == InfiniteRepeater)
						PhpException.Throw(PhpError.Warning, LibResources.GetString("outside_string", specifier));
					else
						pos = repeater;

					continue;
				}

				// number of operations:
				int op_count;

				// gets the size of the data to read and adjust repeater:
				if (!GetSizeToUnpack(specifier, remains, repeater, out op_count, out size))
				{
					PhpException.Throw(PhpError.Warning, LibResources.GetString("unknown_format_code", specifier));
					return null;
				}

				// repeats operation determined by specifier "op_count" times;
				// if op_count is infinite then stops when the number of remaining characters is zero:
				for (int j = 0; j < op_count || op_count == InfiniteRepeater; j++)
				{
					if (size > remains)
					{
						// infinite means "while data are available":
						if (op_count == InfiniteRepeater) break;

						PhpException.Throw(PhpError.Warning, LibResources.GetString("not_enought_input", specifier, size, remains));
						return null;
					}

					object item;
					switch (specifier)
					{
						case 'X': // decreases position, no value stored:
							if (pos == 0)
								PhpException.Throw(PhpError.Warning, LibResources.GetString("outside_string", specifier));
							else
								pos--;
							continue;

						case 'x': // advances position, no value stored
							pos++;
							continue;

						case 'a': // NUL-padded string
						case 'A': // SPACE-padded string 
							{
								byte pad = (byte)(specifier == 'a' ? 0x00 : 0x20);

								int last = pos + size - 1;
								while (last >= pos && buffer[last] == pad)
									last--;

								item = encoding.GetString(buffer, pos, last - pos + 1);
								break;
							}

						case 'h': // Hex string, low/high nibble first - converts to a string, takes n hex digits from string:
						case 'H':
							{
								int p = pos;
								int nibble_shift = (specifier == 'h') ? 0 : 4;

								StringBuilder sb = new StringBuilder(size);
								for (int k = 0; k < size; k++)
								{
									const string hex_digits = "0123456789ABCDEF";

									sb.Append(hex_digits[(buffer[p] >> nibble_shift) & 0x0f]);

									// beware of odd repeaters!
									if (repeater == InfiniteRepeater || repeater > sb.Length)
//.........这里部分代码省略.........
开发者ID:Ashod,项目名称:Phalanger,代码行数:101,代码来源:BitConverter.cs

示例3: Deserialize

		/// <summary>
		/// Deserializes a graph of connected object from a byte array using a given formatter.
		/// </summary>
		/// <param name="bytes">The byte array to deserialize the graph from.</param>
        /// <param name="caller">DTypeDesc of the caller's class context if it is known or UnknownTypeDesc if it should be determined lazily.</param>
        /// <returns>
		/// The deserialized object graph or an instance of <see cref="PhpReference"/> containing <B>false</B> on error.
		/// </returns>
		/// <exception cref="PhpException">Deserialization failed (Notice).</exception>
        public PhpReference Deserialize(PhpBytes bytes, DTypeDesc caller)
		{
            MemoryStream stream = new MemoryStream(bytes.ReadonlyData);
			object result = null;

			try
			{
				try
				{
					// deserialize the data
                    result = GetFormatter(caller).Deserialize(stream);
				}
				catch (System.Reflection.TargetInvocationException e)
				{
					throw e.InnerException;
				}
			}
			catch (SerializationException e)
			{
				PhpException.Throw(PhpError.Notice, LibResources.GetString("deserialization_failed",
				  e.Message, stream.Position, stream.Length));
				return new PhpReference(false);
			}

			return PhpVariable.MakeReference(result);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:35,代码来源:Serializers.CLR.cs

示例4: Unserialize

        public static PhpReference Unserialize(PHP.Core.Reflection.DTypeDesc caller, PhpBytes bytes)
		{
            if (bytes == null || bytes.Length == 0)
                return new PhpReference(false);

            LibraryConfiguration config = LibraryConfiguration.GetLocal(ScriptContext.CurrentContext);

            return config.Serialization.DefaultSerializer.Deserialize(bytes, caller);
		}
开发者ID:hansdude,项目名称:Phalanger,代码行数:9,代码来源:Variables.cs

示例5: Unserialize

        public static PhpReference Unserialize(PHP.Core.Reflection.DTypeDesc caller, PhpBytes bytes)
		{
            LibraryConfiguration config = LibraryConfiguration.GetLocal(ScriptContext.CurrentContext);

            return config.Serialization.DefaultSerializer.Deserialize(bytes, caller);
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:6,代码来源:Variables.cs

示例6: ReadFiltered

		/// <summary>
		/// Fills the <see cref="readBuffers"/> with more data from the underlying stream
		/// passed through all the stream filters. 
		/// </summary>
		/// <param name="chunkSize">Maximum number of bytes to be read from the stream.</param>
		/// <returns>A <see cref="string"/> or <see cref="PhpBytes"/> containing the 
		/// data as returned from the last stream filter or <b>null</b> in case of an error or <c>EOF</c>.</returns>
		protected object ReadFiltered(int chunkSize)
		{
			byte[] chunk = new byte[chunkSize];
			object filtered = null;

			while (filtered == null)
			{
				// Read data until there is an output or error or EOF.
				if (RawEof) return null;
				int read = RawRead(chunk, 0, chunkSize);
				if (read <= 0)
				{
					// Error or EOF.
					return null;
				}

				if (read < chunkSize)
				{
					byte[] sub = new byte[read];
					Array.Copy(chunk, 0, sub, 0, read);
					chunk = sub;
				}
				filtered = new PhpBytes(chunk);

				bool closing = RawEof;

				if (textReadFilter != null)
				{
					// First use the text-input filter if any.
					filtered = textReadFilter.Filter(filtered, closing);
				}

				if (readFilters != null)
				{
					// After that apply the user-filters.
					foreach (IFilter f in readFilters)
					{
						if (filtered == null)
						{
							// This is the last chance to output something. Give chance to all filters.
							if (closing) filtered = PhpBytes.Empty;
							else break; // Continue with next RawRead()
						}
						filtered = f.Filter(filtered, closing);
					} // foreach
				} // if
			} // while 

			return filtered;
		}
开发者ID:kripper,项目名称:Phalanger,代码行数:57,代码来源:PhpStream.cs

示例7: WriteBytes

		/// <summary>
		/// Apppends the binary data to the output buffer passing through the output filter-chain. 
		/// When the buffer is full or buffering is disabled, pass the data to the low-level stream.
		/// </summary>
		/// <param name="data">The <see cref="PhpBytes"/> to store.</param>
		/// <returns>Number of bytes successfully written or <c>-1</c> on an error.</returns>
		public int WriteBytes(PhpBytes data)
		{
			Debug.Assert(this.IsBinary);
			return WriteData(data, false);
		}
开发者ID:kripper,项目名称:Phalanger,代码行数:11,代码来源:PhpStream.cs

示例8: Callback

			private void Callback(IAsyncResult ar)
			{
				if (access == StreamAccessOptions.Read)
				{
					int count = stream.EndRead(ar);
					if (count > 0)
					{
						if (count != buffer.Length)
						{
							// TODO: improve streams
							var buf = new byte[count];
							Buffer.BlockCopy(buffer.ReadonlyData, 0, buf, 0, count);
							phpStream.WriteBytes(new PhpBytes(buf));
						}
						else
						{
							phpStream.WriteBytes(buffer);
						}

						stream.BeginRead(buffer.Data, 0, buffer.Length, callback, ar.AsyncState);
					}
					else
					{
						stream.Close();
					}
				}
				else
				{
					buffer = phpStream.ReadBytes(BufferSize);
					if (buffer != null)
					{
                        stream.BeginWrite(buffer.ReadonlyData, 0, buffer.Length, callback, ar.AsyncState);
					}
					else
					{
						stream.EndWrite(ar);
						stream.Close();
					}
				}
			}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:40,代码来源:Process.CLR.cs

示例9: Concat

		public static PhpBytes Concat(PhpBytes/*!*/x, PhpBytes/*!*/y)
		{
			if (x == null) throw new ArgumentNullException("x");
			if (y == null) throw new ArgumentNullException("y");

			int lx = x.Length;
			int ly = y.Length;

            byte[] result = new byte[lx + ly];
			
			Buffer.BlockCopy(x.ReadonlyData, 0, result, 0, lx);
            Buffer.BlockCopy(y.ReadonlyData, 0, result, lx, ly);

			return new PhpBytes(result);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:15,代码来源:PhpBytes.cs

示例10: PhpBytes

 /// <summary>
 /// Creates a new instance of the <see cref="PhpBytes"/> class that shares internal byte array
 /// with another <see cref="PhpBytes"/> instance.
 /// </summary>
 /// <param name="data">The original bytes array.</param>
 public PhpBytes(PhpBytes/*!*/data)
 {
     if (data == null) throw new ArgumentNullException("data");
     this._data = data._data.Share();
 }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:10,代码来源:PhpBytes.cs

示例11: SaveSerializedVariables

		/// <summary>
		/// Stores serialized variables.
		/// </summary>
		/// <param name="savePath">A path where session files can be stored in.</param>
		/// <param name="sid">A session ID.</param>
		/// <param name="data">Variables in serialized form.</param>
		protected abstract void SaveSerializedVariables(string savePath, string sid, PhpBytes data);
开发者ID:hansdude,项目名称:Phalanger,代码行数:7,代码来源:Session.CLR.cs

示例12: DecodeVariables

		public static bool DecodeVariables(PhpBytes data)
		{
			RequestContext request_context;
			if (!Web.EnsureRequestContext(out request_context)) return false;

			if (!request_context.SessionExists)
			{
				PhpException.Throw(PhpError.Notice, LibResources.GetString("session_not_exists"));
				return false;
			}

			ScriptContext context = request_context.ScriptContext;
			LibraryConfiguration config = LibraryConfiguration.GetLocal(context);
			GlobalConfiguration global = Configuration.Global;

            PhpReference php_ref = config.Session.Serializer.Deserialize(data, UnknownTypeDesc.Singleton);
			if (php_ref == null) return false;

			context.AutoGlobals.Session = php_ref;

			// copies session variables to $GLOBALS array if necessary:
			if (global.GlobalVariables.RegisterGlobals)
				context.RegisterSessionGlobals();

			return true;
		}
开发者ID:hansdude,项目名称:Phalanger,代码行数:26,代码来源:Session.CLR.cs

示例13: exif_thumbnail

        public static PhpBytes exif_thumbnail(string filename, PhpReference width, PhpReference height, PhpReference imagetype)
        {
            if (string.IsNullOrEmpty(filename))
            {
                PhpException.Throw(PhpError.Warning, Utils.Resources.GetString("filename_cannot_be_empty"));
                return null;
            }

            if (imagetype != null)
            {
                PhpException.ArgumentValueNotSupported("imagetype", "!=null");
            }

            Bitmap thumbnail = null;
            PhpBytes bytes, result;

            bytes = Utils.ReadPhpBytes(filename);

            if (bytes == null)
                return null;

            // get thumbnail from <filename>'s content:
            using (MemoryStream ms = new MemoryStream(bytes.ReadonlyData))
            {
                try
                {
                    using (Bitmap image = (Bitmap)Image.FromStream(ms))
                    {
                        thumbnail = (Bitmap)image.GetThumbnailImage(0, 0, () => true, IntPtr.Zero);
                    }
                }
                catch
                {
                    return null;
                }
            }

            if (thumbnail == null)
                return null;

            //
            if (width != null)
                width.Value = thumbnail.Width;
            
            if (height != null)
                height.Value = thumbnail.Height;
            
            using (MemoryStream ms2 = new MemoryStream())
            {
                thumbnail.Save(ms2, ImageFormat.Png);
                result = new PhpBytes(ms2.GetBuffer());
            }

            thumbnail.Dispose();

            return result;
        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:57,代码来源:PhpExif.cs

示例14: iptcparse

        public static PhpArray iptcparse(PhpBytes iptcblock)
        {
            // validate arguments:
            if (iptcblock == null)
                return null;

            // parse IPTC block:
            uint inx = 0, len;
            var buffer = iptcblock.ReadonlyData;

            // find 1st tag:
            for (; inx < buffer.Length; ++inx)
            {
                if ((buffer[inx] == 0x1c) && ((buffer[inx + 1] == 0x01) || (buffer[inx + 1] == 0x02)))
                    break;
            }

            PhpArray result = null;

            // search for IPTC items:
            while (inx < buffer.Length)
            {
                if (buffer[inx++] != 0x1c)
                    break;   // we ran against some data which does not conform to IPTC - stop parsing!

                if ((inx + 4) >= buffer.Length)
                    break;

                // data, recnum:
                byte dataset = buffer[inx++];
                byte recnum = buffer[inx++];

                // len:
                if ((buffer[inx] & (byte)0x80) != 0)
                { // long tag
                    len = (((uint)buffer[inx + 2]) << 24) | (((uint)buffer[inx + 3]) << 16) |
                          (((uint)buffer[inx + 4]) << 8) | (((uint)buffer[inx + 5]));
                    inx += 6;
                }
                else
                { // short tag
                    len = (((uint)buffer[inx + 0]) << 8) | (((uint)buffer[inx + 1]));
                    inx += 2;
                }

                if ((len > buffer.Length) || (inx + len) > buffer.Length)
                    break;

                // snprintf(key, sizeof(key), "%d#%03d", (unsigned int) dataset, (unsigned int) recnum);
                string key = string.Format("{0}#{1}", dataset, recnum.ToString("D3"));

                // create result array lazily:
                if (result == null)
                    result = new PhpArray();

                // parse out the data (buffer+inx)[len]:
                var data = new PhpBytes(new byte[len]);
                Buffer.BlockCopy(buffer, (int)inx, data.Data, 0, (int)len);

                // add data into result[key][]:
                PhpArray values = result[key] as PhpArray;
                if (values != null)
                    values.Add(data);
                else
                    result[key] = new PhpArray(2) { data };

                //
                inx += len;
            }

            //
            return result;  // null if no items were found
        }
开发者ID:Ashod,项目名称:Phalanger,代码行数:73,代码来源:PhpImage.cs

示例15: iptcembed

 public static object iptcembed(PhpBytes iptcdata, string jpeg_file_name, int spool)
 {
     return null;
 }
开发者ID:Ashod,项目名称:Phalanger,代码行数:4,代码来源:PhpImage.cs


注:本文中的PHP.Core.PhpBytes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。