PageRenderTime 81ms CodeModel.GetById 14ms app.highlight 59ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llsdserialize.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 797 lines | 230 code | 81 blank | 486 comment | 0 complexity | aafd9e52eebb23a3cf8a03442417eda2 MD5 | raw file
  1/** 
  2 * @file llsdserialize.h
  3 * @author Phoenix
  4 * @date 2006-02-26
  5 * @brief Declaration of parsers and formatters for LLSD
  6 *
  7 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#ifndef LL_LLSDSERIALIZE_H
 30#define LL_LLSDSERIALIZE_H
 31
 32#include <iosfwd>
 33#include "llpointer.h"
 34#include "llrefcount.h"
 35#include "llsd.h"
 36
 37/** 
 38 * @class LLSDParser
 39 * @brief Abstract base class for LLSD parsers.
 40 */
 41class LL_COMMON_API LLSDParser : public LLRefCount
 42{
 43protected:
 44	/** 
 45	 * @brief Destructor
 46	 */
 47	virtual ~LLSDParser();
 48
 49public:
 50	/** 
 51	 * @brief Anonymous enum to indicate parsing failure.
 52	 */
 53	enum
 54	{
 55		PARSE_FAILURE = -1
 56	};
 57
 58	/** 
 59	 * @brief Constructor
 60	 */
 61	LLSDParser();
 62
 63	/** 
 64	 * @brief Call this method to parse a stream for LLSD.
 65	 *
 66	 * This method parses the istream for a structured data. This
 67	 * method assumes that the istream is a complete llsd object --
 68	 * for example an opened and closed map with an arbitrary nesting
 69	 * of elements. This method will return after reading one data
 70	 * object, allowing continued reading from the stream by the
 71	 * caller.
 72	 * @param istr The input stream.
 73	 * @param data[out] The newly parse structured data.
 74	 * @param max_bytes The maximum number of bytes that will be in
 75	 * the stream. Pass in LLSDSerialize::SIZE_UNLIMITED (-1) to set no
 76	 * byte limit.
 77	 * @return Returns the number of LLSD objects parsed into
 78	 * data. Returns PARSE_FAILURE (-1) on parse failure.
 79	 */
 80	S32 parse(std::istream& istr, LLSD& data, S32 max_bytes);
 81
 82	/** Like parse(), but uses a different call (istream.getline()) to read by lines
 83	 *  This API is better suited for XML, where the parse cannot tell
 84	 *  where the document actually ends.
 85	 */
 86	S32 parseLines(std::istream& istr, LLSD& data);
 87
 88	/** 
 89	 * @brief Resets the parser so parse() or parseLines() can be called again for another <llsd> chunk.
 90	 */
 91	void reset()	{ doReset();	};
 92
 93
 94protected:
 95	/** 
 96	 * @brief Pure virtual base for doing the parse.
 97	 *
 98	 * This method parses the istream for a structured data. This
 99	 * method assumes that the istream is a complete llsd object --
100	 * for example an opened and closed map with an arbitrary nesting
101	 * of elements. This method will return after reading one data
102	 * object, allowing continued reading from the stream by the
103	 * caller.
104	 * @param istr The input stream.
105	 * @param data[out] The newly parse structured data.
106	 * @return Returns the number of LLSD objects parsed into
107	 * data. Returns PARSE_FAILURE (-1) on parse failure.
108	 */
109	virtual S32 doParse(std::istream& istr, LLSD& data) const = 0;
110
111	/** 
112	 * @brief Virtual default function for resetting the parser
113	 */
114	virtual void doReset()	{};
115
116	/* @name Simple istream helper methods 
117	 *
118	 * These helper methods exist to help correctly use the
119	 * mMaxBytesLeft without really thinking about it for most simple
120	 * operations. Use of the streamtools in llstreamtools.h will
121	 * require custom wrapping.
122	 */
123	//@{
124	/** 
125	 * @brief get a byte off the stream
126	 *
127	 * @param istr The istream to work with.
128	 * @return returns the next character.
129	 */
130	int get(std::istream& istr) const;
131	
132	/** 
133	 * @brief get several bytes off the stream into a buffer.
134	 *
135	 * @param istr The istream to work with.
136	 * @param s The buffer to get into
137	 * @param n Extract maximum of n-1 bytes and null temrinate.
138	 * @param delim Delimiter to get until found.
139	 * @return Returns istr.
140	 */
141	std::istream& get(
142		std::istream& istr,
143		char* s,
144		std::streamsize n,
145		char delim) const;
146
147	/** 
148	 * @brief get several bytes off the stream into a streambuf
149	 *
150	 * @param istr The istream to work with.
151	 * @param sb The streambuf to read into
152	 * @param delim Delimiter to get until found.
153	 * @return Returns istr.
154	 */
155	std::istream& get(
156		std::istream& istr,
157		std::streambuf& sb,
158		char delim) const;
159
160	/** 
161	 * @brief ignore the next byte on the istream
162	 *
163	 * @param istr The istream to work with.
164	 * @return Returns istr.
165	 */
166	std::istream& ignore(std::istream& istr) const;
167
168	/** 
169	 * @brief put the last character retrieved back on the stream
170	 *
171	 * @param istr The istream to work with.
172	 * @param c The character to put back
173	 * @return Returns istr.
174	 */
175	std::istream& putback(std::istream& istr, char c) const;
176
177	/** 
178	 * @brief read a block of n characters into a buffer
179	 *
180	 * @param istr The istream to work with.
181	 * @param s The buffer to read into
182	 * @param n The number of bytes to read.
183	 * @return Returns istr.
184	 */
185	std::istream& read(std::istream& istr, char* s, std::streamsize n) const;
186	//@}
187
188protected:
189	/**
190	 * @brief Accunt for bytes read outside of the istream helpers.
191	 *
192	 * Conceptually const since it only modifies mutable members.
193	 * @param bytes The number of bytes read.
194	 */
195	void account(S32 bytes) const;
196
197protected:
198	/**
199	 * @brief boolean to set if byte counts should be checked during parsing.
200	 */
201	bool mCheckLimits;
202
203	/**
204	 * @brief The maximum number of bytes left to be parsed.
205	 */
206	mutable S32 mMaxBytesLeft;
207	
208	/**
209	 * @brief Use line-based reading to get text
210	 */
211	bool mParseLines;
212};
213
214/** 
215 * @class LLSDNotationParser
216 * @brief Parser which handles the original notation format for LLSD.
217 */
218class LL_COMMON_API LLSDNotationParser : public LLSDParser
219{
220protected:
221	/** 
222	 * @brief Destructor
223	 */
224	virtual ~LLSDNotationParser();
225
226public:
227	/** 
228	 * @brief Constructor
229	 */
230	LLSDNotationParser();
231
232protected:
233	/** 
234	 * @brief Call this method to parse a stream for LLSD.
235	 *
236	 * This method parses the istream for a structured data. This
237	 * method assumes that the istream is a complete llsd object --
238	 * for example an opened and closed map with an arbitrary nesting
239	 * of elements. This method will return after reading one data
240	 * object, allowing continued reading from the stream by the
241	 * caller.
242	 * @param istr The input stream.
243	 * @param data[out] The newly parse structured data. Undefined on failure.
244	 * @return Returns the number of LLSD objects parsed into
245	 * data. Returns PARSE_FAILURE (-1) on parse failure.
246	 */
247	virtual S32 doParse(std::istream& istr, LLSD& data) const;
248
249private:
250	/** 
251	 * @brief Parse a map from the istream
252	 *
253	 * @param istr The input stream.
254	 * @param map The map to add the parsed data.
255	 * @return Returns The number of LLSD objects parsed into data.
256	 */
257	S32 parseMap(std::istream& istr, LLSD& map) const;
258
259	/** 
260	 * @brief Parse an array from the istream.
261	 *
262	 * @param istr The input stream.
263	 * @param array The array to append the parsed data.
264	 * @return Returns The number of LLSD objects parsed into data.
265	 */
266	S32 parseArray(std::istream& istr, LLSD& array) const;
267
268	/** 
269	 * @brief Parse a string from the istream and assign it to data.
270	 *
271	 * @param istr The input stream.
272	 * @param data[out] The data to assign.
273	 * @return Retuns true if a complete string was parsed.
274	 */
275	bool parseString(std::istream& istr, LLSD& data) const;
276
277	/** 
278	 * @brief Parse binary data from the stream.
279	 *
280	 * @param istr The input stream.
281	 * @param data[out] The data to assign.
282	 * @return Retuns true if a complete blob was parsed.
283	 */
284	bool parseBinary(std::istream& istr, LLSD& data) const;
285};
286
287/** 
288 * @class LLSDXMLParser
289 * @brief Parser which handles XML format LLSD.
290 */
291class LL_COMMON_API LLSDXMLParser : public LLSDParser
292{
293protected:
294	/** 
295	 * @brief Destructor
296	 */
297	virtual ~LLSDXMLParser();
298
299public:
300	/** 
301	 * @brief Constructor
302	 */
303	LLSDXMLParser();
304
305protected:
306	/** 
307	 * @brief Call this method to parse a stream for LLSD.
308	 *
309	 * This method parses the istream for a structured data. This
310	 * method assumes that the istream is a complete llsd object --
311	 * for example an opened and closed map with an arbitrary nesting
312	 * of elements. This method will return after reading one data
313	 * object, allowing continued reading from the stream by the
314	 * caller.
315	 * @param istr The input stream.
316	 * @param data[out] The newly parse structured data.
317	 * @return Returns the number of LLSD objects parsed into
318	 * data. Returns PARSE_FAILURE (-1) on parse failure.
319	 */
320	virtual S32 doParse(std::istream& istr, LLSD& data) const;
321
322	/** 
323	 * @brief Virtual default function for resetting the parser
324	 */
325	virtual void doReset();
326
327private:
328	class Impl;
329	Impl& impl;
330
331	void parsePart(const char* buf, int len);
332	friend class LLSDSerialize;
333};
334
335/** 
336 * @class LLSDBinaryParser
337 * @brief Parser which handles binary formatted LLSD.
338 */
339class LL_COMMON_API LLSDBinaryParser : public LLSDParser
340{
341protected:
342	/** 
343	 * @brief Destructor
344	 */
345	virtual ~LLSDBinaryParser();
346
347public:
348	/** 
349	 * @brief Constructor
350	 */
351	LLSDBinaryParser();
352
353protected:
354	/** 
355	 * @brief Call this method to parse a stream for LLSD.
356	 *
357	 * This method parses the istream for a structured data. This
358	 * method assumes that the istream is a complete llsd object --
359	 * for example an opened and closed map with an arbitrary nesting
360	 * of elements. This method will return after reading one data
361	 * object, allowing continued reading from the stream by the
362	 * caller.
363	 * @param istr The input stream.
364	 * @param data[out] The newly parse structured data.
365	 * @return Returns the number of LLSD objects parsed into
366	 * data. Returns -1 on parse failure.
367	 */
368	virtual S32 doParse(std::istream& istr, LLSD& data) const;
369
370private:
371	/** 
372	 * @brief Parse a map from the istream
373	 *
374	 * @param istr The input stream.
375	 * @param map The map to add the parsed data.
376	 * @return Returns The number of LLSD objects parsed into data.
377	 */
378	S32 parseMap(std::istream& istr, LLSD& map) const;
379
380	/** 
381	 * @brief Parse an array from the istream.
382	 *
383	 * @param istr The input stream.
384	 * @param array The array to append the parsed data.
385	 * @return Returns The number of LLSD objects parsed into data.
386	 */
387	S32 parseArray(std::istream& istr, LLSD& array) const;
388
389	/** 
390	 * @brief Parse a string from the istream and assign it to data.
391	 *
392	 * @param istr The input stream.
393	 * @param value[out] The string to assign.
394	 * @return Retuns true if a complete string was parsed.
395	 */
396	bool parseString(std::istream& istr, std::string& value) const;
397};
398
399
400/** 
401 * @class LLSDFormatter
402 * @brief Abstract base class for formatting LLSD.
403 */
404class LL_COMMON_API LLSDFormatter : public LLRefCount
405{
406protected:
407	/** 
408	 * @brief Destructor
409	 */
410	virtual ~LLSDFormatter();
411
412public:
413	/**
414	 * Options for output
415	 */
416	typedef enum e_formatter_options_type
417	{
418		OPTIONS_NONE = 0,
419		OPTIONS_PRETTY = 1
420	} EFormatterOptions;
421
422	/** 
423	 * @brief Constructor
424	 */
425	LLSDFormatter();
426
427	/** 
428	 * @brief Set the boolean serialization format.
429	 *
430	 * @param alpha Serializes boolean as alpha if true.
431	 */
432	void boolalpha(bool alpha);
433
434	/** 
435	 * @brief Set the real format
436	 *
437	 * By default, the formatter will use default double serialization
438	 * which is frequently frustrating for many applications. You can
439	 * set the precision on the stream independently, but that still
440	 * might not work depending on the value.
441	 * EXAMPLES:<br>
442	 * %.2f<br>
443	 * @param format A format string which follows the printf format
444	 * rules. Specify an empty string to return to default formatting.
445	 */
446	void realFormat(const std::string& format);
447
448	/** 
449	 * @brief Call this method to format an LLSD to a stream.
450	 *
451	 * @param data The data to write.
452	 * @param ostr The destination stream for the data.
453	 * @return Returns The number of LLSD objects fomatted out
454	 */
455	virtual S32 format(const LLSD& data, std::ostream& ostr, U32 options = LLSDFormatter::OPTIONS_NONE) const = 0;
456
457protected:
458	/** 
459	 * @brief Helper method which appropriately obeys the real format.
460	 *
461	 * @param real The real value to format.
462	 * @param ostr The destination stream for the data.
463	 */
464	void formatReal(LLSD::Real real, std::ostream& ostr) const;
465
466protected:
467	bool mBoolAlpha;
468	std::string mRealFormat;
469};
470
471
472/** 
473 * @class LLSDNotationFormatter
474 * @brief Formatter which outputs the original notation format for LLSD.
475 */
476class LL_COMMON_API LLSDNotationFormatter : public LLSDFormatter
477{
478protected:
479	/** 
480	 * @brief Destructor
481	 */
482	virtual ~LLSDNotationFormatter();
483
484public:
485	/** 
486	 * @brief Constructor
487	 */
488	LLSDNotationFormatter();
489
490	/** 
491	 * @brief Helper static method to return a notation escaped string
492	 *
493	 * This method will return the notation escaped string, but not
494	 * the surrounding serialization identifiers such as a double or
495	 * single quote. It will be up to the caller to embed those as
496	 * appropriate.
497	 * @param in The raw, unescaped string.
498	 * @return Returns an escaped string appropriate for serialization.
499	 */
500	static std::string escapeString(const std::string& in);
501
502	/** 
503	 * @brief Call this method to format an LLSD to a stream.
504	 *
505	 * @param data The data to write.
506	 * @param ostr The destination stream for the data.
507	 * @return Returns The number of LLSD objects fomatted out
508	 */
509	virtual S32 format(const LLSD& data, std::ostream& ostr, U32 options = LLSDFormatter::OPTIONS_NONE) const;
510};
511
512
513/** 
514 * @class LLSDXMLFormatter
515 * @brief Formatter which outputs the LLSD as XML.
516 */
517class LL_COMMON_API LLSDXMLFormatter : public LLSDFormatter
518{
519protected:
520	/** 
521	 * @brief Destructor
522	 */
523	virtual ~LLSDXMLFormatter();
524
525public:
526	/** 
527	 * @brief Constructor
528	 */
529	LLSDXMLFormatter();
530
531	/** 
532	 * @brief Helper static method to return an xml escaped string
533	 *
534	 * @param in A valid UTF-8 string.
535	 * @return Returns an escaped string appropriate for serialization.
536	 */
537	static std::string escapeString(const std::string& in);
538
539	/** 
540	 * @brief Call this method to format an LLSD to a stream.
541	 *
542	 * @param data The data to write.
543	 * @param ostr The destination stream for the data.
544	 * @return Returns The number of LLSD objects fomatted out
545	 */
546	virtual S32 format(const LLSD& data, std::ostream& ostr, U32 options = LLSDFormatter::OPTIONS_NONE) const;
547
548protected:
549
550	/** 
551	 * @brief Implementation to format the data. This is called recursively.
552	 *
553	 * @param data The data to write.
554	 * @param ostr The destination stream for the data.
555	 * @return Returns The number of LLSD objects fomatted out
556	 */
557	S32 format_impl(const LLSD& data, std::ostream& ostr, U32 options, U32 level) const;
558};
559
560
561/** 
562 * @class LLSDBinaryFormatter
563 * @brief Formatter which outputs the LLSD as a binary notation format.
564 *
565 * The binary format is a compact and efficient representation of
566 * structured data useful for when transmitting over a small data pipe
567 * or when transmission frequency is very high.<br>
568 *
569 * The normal boolalpha and real format commands are ignored.<br>
570 *
571 * All integers are transmitted in network byte order. The format is:<br>
572 * Undefined: '!'<br>
573 * Boolean: character '1' for true character '0' for false<br>
574 * Integer: 'i' + 4 bytes network byte order<br>
575 * Real: 'r' + 8 bytes IEEE double<br>
576 * UUID: 'u' + 16 byte unsigned integer<br>
577 * String: 's' + 4 byte integer size + string<br>
578 * Date: 'd' + 8 byte IEEE double for seconds since epoch<br>
579 * URI: 'l' + 4 byte integer size + string uri<br>
580 * Binary: 'b' + 4 byte integer size + binary data<br>
581 * Array: '[' + 4 byte integer size  + all values + ']'<br>
582 * Map: '{' + 4 byte integer size  every(key + value) + '}'<br>
583 *  map keys are serialized as 'k' + 4 byte integer size + string
584 */
585class LL_COMMON_API LLSDBinaryFormatter : public LLSDFormatter
586{
587protected:
588	/** 
589	 * @brief Destructor
590	 */
591	virtual ~LLSDBinaryFormatter();
592
593public:
594	/** 
595	 * @brief Constructor
596	 */
597	LLSDBinaryFormatter();
598
599	/** 
600	 * @brief Call this method to format an LLSD to a stream.
601	 *
602	 * @param data The data to write.
603	 * @param ostr The destination stream for the data.
604	 * @return Returns The number of LLSD objects fomatted out
605	 */
606	virtual S32 format(const LLSD& data, std::ostream& ostr, U32 options = LLSDFormatter::OPTIONS_NONE) const;
607
608protected:
609	/** 
610	 * @brief Helper method to serialize strings
611	 *
612	 * This method serializes a network byte order size and the raw
613	 * string contents.
614	 * @param string The string to write.
615	 * @param ostr The destination stream for the data.
616	 */
617	void formatString(const std::string& string, std::ostream& ostr) const;
618};
619
620
621/** 
622 * @class LLSDNotationStreamFormatter
623 * @brief Formatter which is specialized for use on streams which
624 * outputs the original notation format for LLSD.
625 *
626 * This class is useful for doing inline stream operations. For example:
627 *
628 * <code>
629 *  LLSD sd;<br>
630 *  sd["foo"] = "bar";<br>
631 *  std::stringstream params;<br>
632 *	params << "[{'version':i1}," << LLSDOStreamer<LLSDNotationFormatter>(sd)
633 *    << "]";
634 *  </code>
635 *
636 * *NOTE - formerly this class inherited from its template parameter Formatter,
637 * but all insnatiations passed in LLRefCount subclasses.  This conflicted with
638 * the auto allocation intended for this class template (demonstrated in the
639 * example above).  -brad
640 */
641template <class Formatter>
642class LLSDOStreamer
643{
644public:
645	/** 
646	 * @brief Constructor
647	 */
648	LLSDOStreamer(const LLSD& data, U32 options = LLSDFormatter::OPTIONS_NONE) :
649		mSD(data), mOptions(options) {}
650
651	/**
652	 * @brief Stream operator.
653	 *
654	 * Use this inline during construction during a stream operation.
655	 * @param str The destination stream for serialized output.
656	 * @param The formatter which will output it's LLSD.
657	 * @return Returns the stream passed in after streaming mSD.
658	 */
659	friend std::ostream& operator<<(
660		std::ostream& str,
661		const LLSDOStreamer<Formatter>& formatter)
662	{
663		LLPointer<Formatter> f = new Formatter;
664		f->format(formatter.mSD, str, formatter.mOptions);
665		return str;
666	}
667
668protected:
669	LLSD mSD;
670	U32 mOptions;
671};
672
673typedef LLSDOStreamer<LLSDNotationFormatter>	LLSDNotationStreamer;
674typedef LLSDOStreamer<LLSDXMLFormatter>			LLSDXMLStreamer;
675
676/** 
677 * @class LLSDSerialize
678 * @brief Serializer / deserializer for the various LLSD formats
679 */
680class LL_COMMON_API LLSDSerialize
681{
682public:
683	enum ELLSD_Serialize
684	{
685		LLSD_BINARY, LLSD_XML
686	};
687
688	/**
689	 * @brief anonymouse enumeration for useful max_bytes constants.
690	 */
691	enum
692	{
693		// Setting an unlimited size is discouraged and should only be
694		// used when reading cin or another stream source which does
695		// not provide access to size.
696		SIZE_UNLIMITED = -1,
697	};
698
699	/*
700	 * Generic in/outs
701	 */
702	static void serialize(const LLSD& sd, std::ostream& str, ELLSD_Serialize,
703		U32 options = LLSDFormatter::OPTIONS_NONE);
704
705	/**
706	 * @brief Examine a stream, and parse 1 sd object out based on contents.
707	 *
708	 * @param sd [out] The data found on the stream
709	 * @param str The incoming stream
710	 * @param max_bytes the maximum number of bytes to parse
711	 * @return Returns true if the stream appears to contain valid data
712	 */
713	static bool deserialize(LLSD& sd, std::istream& str, S32 max_bytes);
714
715	/*
716	 * Notation Methods
717	 */
718	static S32 toNotation(const LLSD& sd, std::ostream& str)
719	{
720		LLPointer<LLSDNotationFormatter> f = new LLSDNotationFormatter;
721		return f->format(sd, str, LLSDFormatter::OPTIONS_NONE);
722	}
723	static S32 fromNotation(LLSD& sd, std::istream& str, S32 max_bytes)
724	{
725		LLPointer<LLSDNotationParser> p = new LLSDNotationParser;
726		return p->parse(str, sd, max_bytes);
727	}
728	static LLSD fromNotation(std::istream& str, S32 max_bytes)
729	{
730		LLPointer<LLSDNotationParser> p = new LLSDNotationParser;
731		LLSD sd;
732		(void)p->parse(str, sd, max_bytes);
733		return sd;
734	}
735	
736	/*
737	 * XML Methods
738	 */
739	static S32 toXML(const LLSD& sd, std::ostream& str)
740	{
741		LLPointer<LLSDXMLFormatter> f = new LLSDXMLFormatter;
742		return f->format(sd, str, LLSDFormatter::OPTIONS_NONE);
743	}
744	static S32 toPrettyXML(const LLSD& sd, std::ostream& str)
745	{
746		LLPointer<LLSDXMLFormatter> f = new LLSDXMLFormatter;
747		return f->format(sd, str, LLSDFormatter::OPTIONS_PRETTY);
748	}
749
750	static S32 fromXMLEmbedded(LLSD& sd, std::istream& str)
751	{
752		// no need for max_bytes since xml formatting is not
753		// subvertable by bad sizes.
754		LLPointer<LLSDXMLParser> p = new LLSDXMLParser;
755		return p->parse(str, sd, LLSDSerialize::SIZE_UNLIMITED);
756	}
757	// Line oriented parser, 30% faster than fromXML(), but can
758	// only be used when you know you have the complete XML
759	// document available in the stream.
760	static S32 fromXMLDocument(LLSD& sd, std::istream& str)
761	{
762		LLPointer<LLSDXMLParser> p = new LLSDXMLParser();
763		return p->parseLines(str, sd);
764	}
765	static S32 fromXML(LLSD& sd, std::istream& str)
766	{
767		return fromXMLEmbedded(sd, str);
768//		return fromXMLDocument(sd, str);
769	}
770
771	/*
772	 * Binary Methods
773	 */
774	static S32 toBinary(const LLSD& sd, std::ostream& str)
775	{
776		LLPointer<LLSDBinaryFormatter> f = new LLSDBinaryFormatter;
777		return f->format(sd, str, LLSDFormatter::OPTIONS_NONE);
778	}
779	static S32 fromBinary(LLSD& sd, std::istream& str, S32 max_bytes)
780	{
781		LLPointer<LLSDBinaryParser> p = new LLSDBinaryParser;
782		return p->parse(str, sd, max_bytes);
783	}
784	static LLSD fromBinary(std::istream& str, S32 max_bytes)
785	{
786		LLPointer<LLSDBinaryParser> p = new LLSDBinaryParser;
787		LLSD sd;
788		(void)p->parse(str, sd, max_bytes);
789		return sd;
790	}
791};
792
793//dirty little zip functions -- yell at davep
794LL_COMMON_API std::string zip_llsd(LLSD& data);
795LL_COMMON_API bool unzip_llsd(LLSD& data, std::istream& is, S32 size);
796
797#endif // LL_LLSDSERIALIZE_H