json.usp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!--#
  2. Test type 1: JSON serialization
  3. TechEmpower Web Framework Benchmarks
  4. -->
  5. <!--#declaration
  6. static char* ptr;
  7. static UString* pkey;
  8. static UString* pvalue;
  9. static void usp_init_json()
  10. {
  11. U_TRACE(5, "::usp_init_json()")
  12. U_NEW_STRING(pkey, UString(U_CONSTANT_TO_PARAM("message")));
  13. U_NEW_STRING(pvalue, UString(U_CONSTANT_TO_PARAM("Hello, World!")));
  14. }
  15. -->
  16. <!--#header
  17. -->
  18. <!--#code
  19. char* pwbuffer = UClientImage_Base::wbuffer->data();
  20. U_INTERNAL_DUMP("pwbuffer = %#.10S", pwbuffer)
  21. if (u_get_unalignedp64(pwbuffer+44) != U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'))
  22. {
  23. u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
  24. u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
  25. u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('x','x','\r','\n'));
  26. u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
  27. u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
  28. u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
  29. u_put_unalignedp64(pwbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
  30. u_put_unalignedp16(pwbuffer+52, U_MULTICHAR_CONSTANT16('\r','\n'));
  31. ptr = pwbuffer + U_CONSTANT_SIZE("Content-Length: xx\r\nContent-Type: application/json\r\n\r\n");
  32. }
  33. U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->data()), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
  34. UValue::pstringify = ptr;
  35. UValue(*pkey, *pvalue).stringify();
  36. uint32_t content_length = (UValue::pstringify - ptr);
  37. U_INTERNAL_ASSERT_EQUALS(content_length, 27)
  38. (void) u_num2str32(content_length, ptr - U_CONSTANT_SIZE("xx\r\nContent-Type: application/json\r\n\r\n"));
  39. UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: xx\r\nContent-Type: application/json\r\n\r\n") + content_length);
  40. -->