private static LLSD DeserializeNotationMap(StringReader reader) { int character; LLSDMap llsdMap = new LLSDMap(); while (((character = PeekAndSkipWhitespace(reader)) > 0) && ((char)character != mapEndNotationMarker)) { LLSD llsdKey = DeserializeNotationElement(reader); if (llsdKey.Type != LLSDType.String) { throw new LLSDException("Notation LLSD parsing: Invalid key in map"); } string key = llsdKey.AsString(); character = ReadAndSkipWhitespace(reader); if ((char)character != keyNotationDelimiter) { throw new LLSDException("Notation LLSD parsing: Unexpected end of stream in map."); } if ((char)character != keyNotationDelimiter) { throw new LLSDException("Notation LLSD parsing: Invalid delimiter in map."); } llsdMap[key] = DeserializeNotationElement(reader); character = ReadAndSkipWhitespace(reader); if (character < 0) { throw new LLSDException("Notation LLSD parsing: Unexpected end of map discovered."); } else if ((char)character == kommaNotationDelimiter) { continue; } else if ((char)character == mapEndNotationMarker) { break; } } if (character < 0) { throw new LLSDException("Notation LLSD parsing: Unexpected end of map discovered."); } return((LLSD)llsdMap); }
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; } }
private static void SerializeNotationElementFormatted(StringWriter writer, string intend, LLSD llsd) { switch (llsd.Type) { case LLSDType.Unknown: writer.Write(undefNotationValue); break; case LLSDType.Boolean: if (llsd.AsBoolean()) { writer.Write(trueNotationValueTwo); } else { writer.Write(falseNotationValueTwo); } break; case LLSDType.Integer: writer.Write(integerNotationMarker); writer.Write(llsd.AsString()); break; case LLSDType.Real: writer.Write(realNotationMarker); writer.Write(llsd.AsString()); break; case LLSDType.UUID: writer.Write(uuidNotationMarker); writer.Write(llsd.AsString()); break; case LLSDType.String: writer.Write(singleQuotesNotationMarker); writer.Write(EscapeCharacter(llsd.AsString(), singleQuotesNotationMarker)); writer.Write(singleQuotesNotationMarker); break; case LLSDType.Binary: writer.Write(binaryNotationMarker); writer.Write("64"); writer.Write(doubleQuotesNotationMarker); writer.Write(llsd.AsString()); writer.Write(doubleQuotesNotationMarker); break; case LLSDType.Date: writer.Write(dateNotationMarker); writer.Write(doubleQuotesNotationMarker); writer.Write(llsd.AsString()); writer.Write(doubleQuotesNotationMarker); break; case LLSDType.URI: writer.Write(uriNotationMarker); writer.Write(doubleQuotesNotationMarker); writer.Write(EscapeCharacter(llsd.AsString(), doubleQuotesNotationMarker)); writer.Write(doubleQuotesNotationMarker); break; case LLSDType.Array: SerializeNotationArrayFormatted(writer, intend + baseIntend, (LLSDArray)llsd); break; case LLSDType.Map: SerializeNotationMapFormatted(writer, intend + baseIntend, (LLSDMap)llsd); break; default: throw new LLSDException("Notation serialization: Not existing element discovered."); } }