From user-return-3951-apmail-thrift-user-archive=thrift.apache.org@thrift.apache.org Fri Sep 19 23:25:43 2014 Return-Path: X-Original-To: apmail-thrift-user-archive@www.apache.org Delivered-To: apmail-thrift-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E47D0118AD for ; Fri, 19 Sep 2014 23:25:43 +0000 (UTC) Received: (qmail 5330 invoked by uid 500); 19 Sep 2014 23:25:43 -0000 Delivered-To: apmail-thrift-user-archive@thrift.apache.org Received: (qmail 5289 invoked by uid 500); 19 Sep 2014 23:25:43 -0000 Mailing-List: contact user-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@thrift.apache.org Delivered-To: mailing list user@thrift.apache.org Received: (qmail 5277 invoked by uid 99); 19 Sep 2014 23:25:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Sep 2014 23:25:43 +0000 X-ASF-Spam-Status: No, hits=2.5 required=5.0 tests=FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rodolfo.ochoa@gmail.com designates 209.85.212.175 as permitted sender) Received: from [209.85.212.175] (HELO mail-wi0-f175.google.com) (209.85.212.175) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Sep 2014 23:25:37 +0000 Received: by mail-wi0-f175.google.com with SMTP id r20so321890wiv.14 for ; Fri, 19 Sep 2014 16:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=5awv6RoFKO7MK6Q2agnGER/oZUJA+CUO43ztlzCN0uQ=; b=tso5bM9LaRQo1oaZpuMoo0UXHKoHy9ArLHj5lMQ2EokhqlFe//P0vGWB3WhCbX8vjM KFvMbWL5eb+b9kDz2uOBBtvlYYfJbVzRs667lPkLML8J2qHjEWNX/LKyUdFhWwYFpsbR Qph+DeR+jUVZYy+8gnOOmearRKuRZKeb8T9XZtFkuOchKUnUF/od8rtjr/FN8Rq8N1xf u1pt6DRrg5gjcG66kSY1btDpMq5CZbVgYP7PWjrRdkDq66qGfmZrnXLJ3d0/8NQNQ496 OqKS4IWCJ+k7K7xsC2RoOBOXeluQGQECoYkDeYQ5/ztPleDrBZzQZ2Z02aVErvpQqiXx icDQ== X-Received: by 10.194.220.7 with SMTP id ps7mr4275174wjc.28.1411169116225; Fri, 19 Sep 2014 16:25:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.109.100 with HTTP; Fri, 19 Sep 2014 16:24:56 -0700 (PDT) In-Reply-To: References: From: Rodolfo Ochoa Date: Fri, 19 Sep 2014 18:24:56 -0500 Message-ID: Subject: Re: Error with binary data with node.js To: user Content-Type: multipart/alternative; boundary=001a11c1b424e4073805037369a5 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c1b424e4073805037369a5 Content-Type: text/plain; charset=UTF-8 this error start happening here: https://issues.apache.org/jira/browse/THRIFT-1679 which is a correct fix, but then you need to correctly implement binary. -Rod.O On Fri, Sep 19, 2014 at 5:33 PM, Rodolfo Ochoa wrote: > the problem is... > the problem is that for the generated code, > thrift maps binary data into strings, and uses the method readString from > the BinaryProtocol > protocol.js:280 TBinaryProtocol.prototype.readString = function() { > instead of using readBinary, > protocol.js:275 TBinaryProtocol.prototype.readBinary = function() { > which would return a buffer object. > readString method in the transport will use buffer(...).toString("utf8") > which will sanitize utf and will replace invalid unicode sequences with the > Unicode Replacement Character. > > *my code:* > my binary field was mapped on ondb_types.js as: > TGetResult.prototype = {}; > TGetResult.prototype.read = function(input) { > input.readStructBegin(); > while (true) > { > var ret = input.readFieldBegin(); > var fname = ret.fname; > var ftype = ret.ftype; > var fid = ret.fid; > if (ftype == Thrift.Type.STOP) { > break; > } > switch (fid) > { > case 1: > if (ftype == Thrift.Type.STRUCT) { > this.currentRow = new ttypes.TRow(); > this.currentRow.read(input); > } else { > input.skip(ftype); > } > break; > case 2: > * if (ftype == Thrift.Type.STRING) {* > * this.currentRowVersion = input.readString();* > } else { > input.skip(ftype); > } > break; > default: > input.skip(ftype); > } > input.readFieldEnd(); > } > input.readStructEnd(); > return; > }; > > > and TGetResult is defined in ondb.thrift file as: > typedef binary TVersion > struct TGetResult > { > 1:TRow currentRow; > 2:TVersion currentRowVersion; > } > > I'm not sure if this is already been reported or if this is already been > fixed on the newest version. > > -Rod.O > > > > > > > On Thu, Sep 18, 2014 at 11:23 PM, Randy Abernethy < > randy.abernethy@gmail.com> wrote: > >> Hey Rodolfo, >> >> While I can not say for sure not having seen your code, I would be highly >> suspect of any Thift node lib prior to 0.9.2, which is not yet released. >> Try the current master, it has too many fixes to mention and will likely >> solve your problem. You don't need to change versions on any of the other >> languages. Ping back if you still have trouble. >> >> Best, >> Randy >> >> On Thursday, September 18, 2014, Rodolfo Ochoa >> wrote: >> >> > on node: >> > thrift@0.9.1 >> > >> > on java: >> > libthrift-0.9.1.jar >> > >> > >> > >> > On Thu, Sep 18, 2014 at 9:09 PM, Randy Abernethy < >> > randy.abernethy@gmail.com > >> > wrote: >> > >> > > What version of thrift are you using? >> > > On Sep 18, 2014 7:46 PM, "Rodolfo Ochoa" > > > wrote: >> > > >> > > > I have a Java server sending info to C/Python/node.js clients, >> > > > I don't have issues with C or Python, only with node.js >> > > > on Java side, I'm sending a byte array, and if I print the values of >> > this >> > > > byte array I got: >> > > > byte codes: -84 -19 0 5 119 44 0 5 -50 108 0 44 75 73 78 -120 -103 >> -59 >> > > > -124 3 -92 -121 -98 -104 0 0 0 0 0 0 37 -128 1 3 0 0 0 1 0 0 0 1 0 >> 0 0 >> > 0 >> > > 0 >> > > > -78 68 -89 >> > > > >> > > > but on node.js side I receive: >> > > > byte codes: 65533 65533 0 5 119 44 0 5 65533 108 0 44 75 73 78 >> 65533 >> > > 65533 >> > > > 324 3 65533 65533 65533 65533 0 0 0 0 0 0 37 65533 1 3 0 0 0 1 0 0 >> 0 1 >> > 0 >> > > 0 >> > > > 0 0 0 65533 68 65533 >> > > > >> > > > this means that some characters were replaced, why? how? >> > > > how can avoid this behavior? >> > > > >> > > > >> > > > >> > > > -- >> > > > *Rod.O* >> > > > >> > > >> > >> > >> > >> > -- >> > *Rod.O* >> > >> > > > > -- > *Rod.O* > -- *Rod.O* --001a11c1b424e4073805037369a5--