private static LLSD DeserializeNotationArray(StringReader reader) { int character; LLSDArray llsdArray = new LLSDArray(); while (((character = PeekAndSkipWhitespace(reader)) > 0) && ((char)character != arrayEndNotationMarker)) { llsdArray.Add(DeserializeNotationElement(reader)); character = ReadAndSkipWhitespace(reader); if (character < 0) { throw new LLSDException("Notation LLSD parsing: Unexpected end of array discovered."); } else if ((char)character == kommaNotationDelimiter) { continue; } else if ((char)character == arrayEndNotationMarker) { break; } } if (character < 0) { throw new LLSDException("Notation LLSD parsing: Unexpected end of array discovered."); } return((LLSD)llsdArray); }
private static LLSDArray ParseXmlArray(XmlTextReader reader) { if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "array") { throw new LLSDException("Expected <array>"); } LLSDArray array = new LLSDArray(); if (reader.IsEmptyElement) { reader.Read(); return(array); } if (reader.Read()) { while (true) { SkipWhitespace(reader); if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "array") { reader.Read(); break; } array.Add(ParseXmlElement(reader)); } } return(array); }
public static LLSD FromVector2(Vector2 value) { LLSDArray array = new LLSDArray(); array.Add(LLSD.FromReal(value.X)); array.Add(LLSD.FromReal(value.Y)); return(array); }
public static LLSD FromColor4(Color4 value) { LLSDArray array = new LLSDArray(); array.Add(LLSD.FromReal(value.R)); array.Add(LLSD.FromReal(value.G)); array.Add(LLSD.FromReal(value.B)); array.Add(LLSD.FromReal(value.A)); return(array); }
public static LLSD FromQuaternion(Quaternion value) { LLSDArray array = new LLSDArray(); array.Add(LLSD.FromReal(value.X)); array.Add(LLSD.FromReal(value.Y)); array.Add(LLSD.FromReal(value.Z)); array.Add(LLSD.FromReal(value.W)); return(array); }
private static void SerializeBinaryArray(MemoryStream stream, LLSDArray llsdArray) { stream.WriteByte(arrayBeginBinaryMarker); byte[] binaryNumElementsHostEnd = HostToNetworkIntBytes(llsdArray.Count); stream.Write(binaryNumElementsHostEnd, 0, int32Length); foreach (LLSD llsd in llsdArray) { SerializeBinaryElement(stream, llsd); } stream.WriteByte(arrayEndBinaryMarker); }
private static void SerializeNotationArray(StringWriter writer, LLSDArray llsdArray) { writer.Write(arrayBeginNotationMarker); int lastIndex = llsdArray.Count - 1; for (int idx = 0; idx <= lastIndex; idx++) { SerializeNotationElement(writer, llsdArray[idx]); if (idx < lastIndex) { writer.Write(kommaNotationDelimiter); } } writer.Write(arrayEndNotationMarker); }
private static LLSD ParseBinaryArray(MemoryStream stream) { int numElements = NetworkToHostInt(ConsumeBytes(stream, int32Length)); int crrElement = 0; LLSDArray llsdArray = new LLSDArray(); while (crrElement < numElements) { llsdArray.Add(ParseBinaryElement(stream)); crrElement++; } if (!FindByte(stream, arrayEndBinaryMarker)) { throw new LLSDException("Binary LLSD parsing: Missing end marker in array."); } return((LLSD)llsdArray); }
private static void SerializeNotationArrayFormatted(StringWriter writer, string intend, LLSDArray llsdArray) { writer.Write(Helpers.NewLine); writer.Write(intend); writer.Write(arrayBeginNotationMarker); int lastIndex = llsdArray.Count - 1; for (int idx = 0; idx <= lastIndex; idx++) { if (llsdArray[idx].Type != LLSDType.Array && llsdArray[idx].Type != LLSDType.Map) { writer.Write(Helpers.NewLine); } writer.Write(intend + baseIndent); SerializeNotationElementFormatted(writer, intend, llsdArray[idx]); if (idx < lastIndex) { writer.Write(kommaNotationDelimiter); } } writer.Write(Helpers.NewLine); writer.Write(intend); writer.Write(arrayEndNotationMarker); }
/// <summary> /// /// </summary> /// <param name="writer"></param> /// <param name="data"></param> public static void SerializeXmlElement(XmlTextWriter writer, LLSD data) { switch (data.Type) { case LLSDType.Unknown: writer.WriteStartElement(String.Empty, "undef", String.Empty); writer.WriteEndElement(); break; case LLSDType.Boolean: writer.WriteStartElement(String.Empty, "boolean", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.Integer: writer.WriteStartElement(String.Empty, "integer", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.Real: writer.WriteStartElement(String.Empty, "real", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.String: writer.WriteStartElement(String.Empty, "string", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.UUID: writer.WriteStartElement(String.Empty, "uuid", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.Date: writer.WriteStartElement(String.Empty, "date", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.URI: writer.WriteStartElement(String.Empty, "uri", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.Binary: writer.WriteStartElement(String.Empty, "binary", String.Empty); writer.WriteStartAttribute(String.Empty, "encoding", String.Empty); writer.WriteString("base64"); writer.WriteEndAttribute(); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case LLSDType.Map: LLSDMap map = (LLSDMap)data; writer.WriteStartElement(String.Empty, "map", String.Empty); foreach (KeyValuePair <string, LLSD> kvp in map) { writer.WriteStartElement(String.Empty, "key", String.Empty); writer.WriteString(kvp.Key); writer.WriteEndElement(); SerializeXmlElement(writer, kvp.Value); } writer.WriteEndElement(); break; case LLSDType.Array: LLSDArray array = (LLSDArray)data; writer.WriteStartElement(String.Empty, "array", String.Empty); for (int i = 0; i < array.Count; i++) { SerializeXmlElement(writer, array[i]); } writer.WriteEndElement(); break; } }