From: David Reiss Date: Wed, 26 Dec 2007 20:23:03 +0000 (+0000) Subject: Thrift: Wide string support for Perl. X-Git-Tag: 0.2.0~1065 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=5d86e399036740633954c50cc88f2a98908f54b0;p=common%2Fthrift.git 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 bb570a26..166f9a4d 100644 --- a/lib/perl/lib/Thrift/BinaryProtocol.pm +++ b/lib/perl/lib/Thrift/BinaryProtocol.pm @@ -15,6 +15,9 @@ require 5.6.0; use strict; use warnings; +use utf8; +use Encode; + use Thrift; use Thrift::Protocol; @@ -209,9 +212,14 @@ sub writeString{ 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 @@ sub readMessageBegin $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);