diff options
author | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-12 23:12:28 +0000 |
---|---|---|
committer | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-12 23:12:28 +0000 |
commit | c1ee48d04fb70cd0ac6dcf34d6a1ce59b2b9b565 (patch) | |
tree | 46e93af4692c896290c09098858804f781898099 /ipc/ipc_message_utils.cc | |
parent | 94aaf8a94581679fe64dc9d22b25df006bad015b (diff) | |
download | chromium_src-c1ee48d04fb70cd0ac6dcf34d6a1ce59b2b9b565.zip chromium_src-c1ee48d04fb70cd0ac6dcf34d6a1ce59b2b9b565.tar.gz chromium_src-c1ee48d04fb70cd0ac6dcf34d6a1ce59b2b9b565.tar.bz2 |
Add support for marshalling unsigned char in IPC.
Previously, we've supported unsigned short, but not unsigned char. There
are a few places where folks are passing around color values that must be
in the 0..255, and we can save both bytes written and avoid explicit range
checks by the receiving method by using this rather than larger types.
We support unsigned char only. Signed char is evil due to questionable
signedness in the C specs.
I've re-arranged the order of these specializatons so that they go in
order of increasing size as they go down the page.
R=jam@chromium.org
BUG=259903
Review URL: https://chromiumcodereview.appspot.com/18068016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_utils.cc')
-rw-r--r-- | ipc/ipc_message_utils.cc | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc index 8bf7609..2acddce 100644 --- a/ipc/ipc_message_utils.cc +++ b/ipc/ipc_message_utils.cc @@ -253,6 +253,40 @@ void ParamTraits<bool>::Log(const param_type& p, std::string* l) { l->append(p ? "true" : "false"); } +void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) { + m->WriteBytes(&p, sizeof(param_type)); +} + +bool ParamTraits<unsigned char>::Read(const Message* m, PickleIterator* iter, + param_type* r) { + const char* data; + if (!m->ReadBytes(iter, &data, sizeof(param_type))) + return false; + memcpy(r, data, sizeof(param_type)); + return true; +} + +void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { + l->append(base::UintToString(p)); +} + +void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) { + m->WriteBytes(&p, sizeof(param_type)); +} + +bool ParamTraits<unsigned short>::Read(const Message* m, PickleIterator* iter, + param_type* r) { + const char* data; + if (!m->ReadBytes(iter, &data, sizeof(param_type))) + return false; + memcpy(r, data, sizeof(param_type)); + return true; +} + +void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { + l->append(base::UintToString(p)); +} + void ParamTraits<int>::Log(const param_type& p, std::string* l) { l->append(base::IntToString(p)); } @@ -277,23 +311,6 @@ void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { l->append(base::Uint64ToString(p)); } -void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) { - m->WriteBytes(&p, sizeof(param_type)); -} - -bool ParamTraits<unsigned short>::Read(const Message* m, PickleIterator* iter, - param_type* r) { - const char* data; - if (!m->ReadBytes(iter, &data, sizeof(param_type))) - return false; - memcpy(r, data, sizeof(param_type)); - return true; -} - -void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { - l->append(base::UintToString(p)); -} - void ParamTraits<float>::Write(Message* m, const param_type& p) { m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); } |