Thrift: Wide string support for Perl.
Summary:
This patch allows the TBinaryProtocol to encode wide character strings
as UTF-8 before serializing. It does not support decoding when receiving.
Reviewed By: mcslee
Test Plan: None.
Revert Plan: ok
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665407 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/perl/lib/Thrift/BinaryProtocol.pm b/lib/perl/lib/Thrift/BinaryProtocol.pm
index bb570a2..166f9a4 100644
--- a/lib/perl/lib/Thrift/BinaryProtocol.pm
+++ b/lib/perl/lib/Thrift/BinaryProtocol.pm
@@ -15,6 +15,9 @@
use strict;
use warnings;
+use utf8;
+use Encode;
+
use Thrift;
use Thrift::Protocol;
@@ -209,9 +212,14 @@
my $self = shift;
my $value= shift;
+ if( utf8::is_utf8($value) ){
+ $value = Encode::encode_utf8($value);
+ }
+
my $len = length($value);
my $result = $self->writeI32($len);
+
if ($len) {
$self->{trans}->write($value,$len);
}
@@ -240,7 +248,7 @@
$self->readI32($seqid);
} else { # old client support code
return
- $result +
+ $result +
$self->readStringBody($name, $version) + # version here holds the size of the string
$self->readByte($type) +
$self->readI32($seqid);