/// <summary> /// 格式化ajax字符串 /// </summary> /// <param name="jsStream">JS字符流</param> /// <param name="formatStream">格式化JSON字符流</param> internal unsafe static void FormatJavascript(charStream jsStream, unmanagedStream formatStream) { if (jsStream.Length != 0) { char *start = jsStream.Char; int length = formatLength(jsStream); if (length == 0) { char *end = start + (length = jsStream.Length); formatStream.PrepLength(length <<= 1); for (char *write = (char *)(formatStream.CurrentData); start != end; ++start) { *write++ = *start == Quote ? '"' : *start; } formatStream.UnsafeAddLength(length); } else { length += jsStream.Length; formatStream.PrepLength(length <<= 1); formatJavascript(start, start + jsStream.Length, (char *)(formatStream.CurrentData)); formatStream.UnsafeAddLength(length); } } }
/// <summary> /// 文本转HTML /// </summary> /// <param name="value">文本值</param> /// <param name="stream">HTML编码流</param> public unsafe void ToHtml(ref subString value, unmanagedStream stream) { if (value.Length != 0) { if (stream == null) { log.Error.Throw(log.exceptionType.Null); } int length = value.Length; fixed(char *valueFixed = value.value) { char *start = valueFixed + value.StartIndex, end = start + length; int count = encodeCount(start, end); if (count == 0) { stream.PrepLength(length <<= 1); unsafer.memory.Copy(start, stream.CurrentData, length); } else { length += count << 2; stream.PrepLength(length <<= 1); toHtml(start, end, (char *)stream.CurrentData); } stream.UnsafeAddLength(length); } } }
private unsafe static void serialize(fastCSharp.emit.dataSerializer serializer, fileBlockMember <valueType> value) { int indexCustom = value.index.Custom; if ((indexCustom & (int)custom.Serialize) == 0) { if (value.index.Size == 0) { serializer.Stream.Write(fastCSharp.emit.binarySerializer.NullValue); } else { unmanagedStream stream = serializer.Stream; stream.PrepLength(sizeof(int) * 2 + sizeof(long)); byte *data = stream.CurrentData; *(int *)data = (emit.pub.PuzzleValue & 0x7fffff00) + indexCustom; *(int *)(data + sizeof(int)) = value.index.Size; *(long *)(data + sizeof(int) * 2) = value.index.Index; stream.UnsafeAddLength(sizeof(int) * 2 + sizeof(long)); stream.PrepLength(); } } else if (value.value == null) { serializer.Stream.Write(fastCSharp.emit.binarySerializer.NullValue); } else { serializer.Stream.Write(indexCustom); fastCSharp.emit.dataSerializer.typeSerializer <valueType> .Serialize(serializer, value.value); } }
/// <summary> /// 序列化 /// </summary> /// <param name="stream"></param> /// <param name="map"></param> /// <param name="fieldCount"></param> internal static void FieldSerialize(unmanagedStream stream, ulong map, int fieldCount) { if (map == 0) { stream.Write(0); } else { stream.PrepLength(sizeof(int) + sizeof(ulong)); byte *data = stream.CurrentData; *(int *)data = fieldCount; *(ulong *)(data + sizeof(int)) = map; stream.UnsafeAddLength(sizeof(int) + sizeof(ulong)); stream.PrepLength(); } }
/// <summary> /// 序列化 /// </summary> /// <param name="stream"></param> /// <param name="map"></param> /// <param name="type"></param> internal static void FieldSerialize(unmanagedStream stream, byte *map, type type) { if (map == null) { stream.Write(0); } else { stream.PrepLength(type.FieldSerializeSize + sizeof(int)); byte *data = stream.CurrentData, read = map; *(int *)data = type.FieldCount; data += sizeof(int); for (byte *end = map + (type.FieldSerializeSize & (int.MaxValue - sizeof(ulong) + 1)); read != end; read += sizeof(ulong), data += sizeof(ulong)) { *(ulong *)data = *(ulong *)read; } if ((type.FieldSerializeSize & sizeof(int)) != 0) { *(uint *)data = *(uint *)read; } stream.UnsafeAddLength(type.FieldSerializeSize + sizeof(int)); stream.PrepLength(); } }