Commit 734aad70 authored by andersca@apple.com's avatar andersca@apple.com

Add ArgumentCoder specialization for WTF::CString

https://bugs.webkit.org/show_bug.cgi?id=48796

Reviewed by Sam Weinig.

* Platform/CoreIPC/ArgumentCoders.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71069 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent af1b8a2a
2010-11-01 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
Add ArgumentCoder specialization for WTF::CString
https://bugs.webkit.org/show_bug.cgi?id=48796
* Platform/CoreIPC/ArgumentCoders.h:
2010-11-01 Anders Carlsson <andersca@apple.com>
Fix build.
......
......@@ -33,6 +33,7 @@
#include <wtf/TypeTraits.h>
#include <wtf/Vector.h>
#include <wtf/text/AtomicString.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
namespace CoreIPC {
......@@ -194,6 +195,48 @@ template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTrai
}
};
template<> struct ArgumentCoder<CString> {
static void encode(ArgumentEncoder* encoder, const CString& string)
{
// Special case the null string.
if (string.isNull()) {
encoder->encodeUInt32(std::numeric_limits<uint32_t>::max());
return;
}
uint32_t length = string.length();
encoder->encode(length);
encoder->encodeBytes(reinterpret_cast<const uint8_t*>(string.data()), length);
}
static bool decode(ArgumentDecoder* decoder, CString& result)
{
uint32_t length;
if (!decoder->decode(length))
return false;
if (length == std::numeric_limits<uint32_t>::max()) {
// This is the null string.
result = CString();
return true;
}
// Before allocating the string, make sure that the decoder buffer is big enough.
if (!decoder->bufferIsLargeEnoughToContain<char>(length)) {
decoder->markInvalid();
return false;
}
char* buffer;
CString string = CString::newUninitialized(length, buffer);
if (!decoder->decodeBytes(reinterpret_cast<uint8_t*>(buffer), length))
return false;
result = string;
return true;
}
};
template<> struct ArgumentCoder<String> {
static void encode(ArgumentEncoder* encoder, const String& string)
{
......@@ -208,7 +251,7 @@ template<> struct ArgumentCoder<String> {
encoder->encodeBytes(reinterpret_cast<const uint8_t*>(string.characters()), length * sizeof(UChar));
}
static bool decode(ArgumentDecoder* decoder, String& s)
static bool decode(ArgumentDecoder* decoder, String& result)
{
uint32_t length;
if (!decoder->decode(length))
......@@ -216,7 +259,7 @@ template<> struct ArgumentCoder<String> {
if (length == std::numeric_limits<uint32_t>::max()) {
// This is the null string.
s = String();
result = String();
return true;
}
......@@ -231,7 +274,7 @@ template<> struct ArgumentCoder<String> {
if (!decoder->decodeBytes(reinterpret_cast<uint8_t*>(buffer), length * sizeof(UChar)))
return false;
s = string;
result = string;
return true;
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment