No, you are misusing the ByteBuffer. You need to pay attention to .position() and .limit() - only the bytes between those two values are part of that field.
On Mon, Apr 25, 2011 at 1:52 PM, Michi Mutsuzaki <[email protected]>wrote: > Hello, > > I'm having trouble using binary type with TFramedTransport in Java. I'm > using Thrift 0.6. I have a method that takes a binary as an argument: > > i32 myMethod(1:binary blob), > > I have a Java client that calls myMethod(): > > TSocket socket = new TSocket("localhost", 9090); > TTransport transport = new TFramedTransport(socket); > transport.open(); > TProtocol protocol = new TBinaryProtocol(transport); > MyService.Client client = new MyService.Client(protocol); > client.myMethod(ByteBuffer.wrap("hello".getBytes())); > > The server is started like this: > > TServerTransport trans = new TServerSocket(port); > TThreadPoolServer.Args args = new TThreadPoolServer.Args(trans); > args.processor(new MyService.Processor(new MyProcessor())); > args.transportFactory(new TFramedTransport.Factory()); > args.protocolFactory(new TBinaryProtocol.Factory(true, true)); > TServer server = new TThreadPoolServer(args); > server.serve(); > > On the server side, myMethod() receives more than "hello". It looks > something like this: > > ?^A^@^A^@^@^@^KmyMethod^@^@^@^A^K^@^A^@^@^@^Chello^@ > > It works correctly if I don't use TFramedTransport. Am I misusing > TFramedTransport? > > Thanks! > --Michi > >
