1
0

LLSDStreamHandler.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using OpenSim.Framework.Servers;
  5. using System.IO;
  6. using System.Collections;
  7. using libsecondlife;
  8. namespace OpenSim.Region.Capabilities
  9. {
  10. public class LLSDStreamhandler<TRequest, TResponse> : BaseStreamHandler
  11. where TRequest : new()
  12. {
  13. private LLSDMethod<TRequest, TResponse> m_method;
  14. public LLSDStreamhandler(string httpMethod, string path, LLSDMethod<TRequest, TResponse> method)
  15. : base(httpMethod, path )
  16. {
  17. m_method = method;
  18. }
  19. public override byte[] Handle(string path, Stream request)
  20. {
  21. //Encoding encoding = Encoding.UTF8;
  22. //StreamReader streamReader = new StreamReader(request, false);
  23. //string requestBody = streamReader.ReadToEnd();
  24. //streamReader.Close();
  25. Hashtable hash = (Hashtable)LLSD.LLSDDeserialize( request );
  26. TRequest llsdRequest = new TRequest();
  27. LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest);
  28. TResponse response = m_method(llsdRequest);
  29. Encoding encoding = new UTF8Encoding(false);
  30. return encoding.GetBytes( LLSDHelpers.SerialiseLLSDReply(response) );
  31. }
  32. }
  33. }