summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Yeksigian <carl@apache.org>2013-08-14 19:37:54 -0400
committerCarl Yeksigian <carl@apache.org>2013-08-14 19:38:42 -0400
commit2ca9c2028593782621c8876817d8772aa5f46ac7 (patch)
tree75d9cbde1f9994b5b8b7cb0b637504d66787a39f
parentd051ca0b23eab53ede689ba319256e5f30feebf8 (diff)
downloadthrift-2ca9c2028593782621c8876817d8772aa5f46ac7.tar.gz
THRIFT-820 Remove readLength attribute from BinaryProtocol
Patch: Carl Yeksigian
-rw-r--r--lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as19
-rw-r--r--lib/csharp/src/Protocol/TBinaryProtocol.cs25
-rw-r--r--lib/delphi/src/Thrift.Protocol.pas26
-rw-r--r--lib/go/thrift/binary_protocol.go29
-rw-r--r--lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java36
-rw-r--r--lib/javame/src/org/apache/thrift/protocol/TBinaryProtocol.java23
6 files changed, 4 insertions, 154 deletions
diff --git a/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as b/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
index 441247977..b2ff9d808 100644
--- a/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
+++ b/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
@@ -38,9 +38,6 @@ package org.apache.thrift.protocol {
protected var strictRead_:Boolean = false;
protected var strictWrite_:Boolean = true;
- protected var readLength_:int;
- protected var checkReadLength_:Boolean = false;
-
/**
* Factory
*/
@@ -298,7 +295,6 @@ package org.apache.thrift.protocol {
public function readBinary():ByteArray {
var size:int = readI32();
- checkReadLength(size);
var buf:ByteArray = new ByteArray();
trans_.readAll(buf, 0, size);
return buf;
@@ -307,25 +303,10 @@ package org.apache.thrift.protocol {
private function readAll(len:int):void {
reset(bytes);
- checkReadLength(len);
trans_.readAll(bytes, 0, len);
bytes.position = 0;
}
-
- public function setReadLength(readLength:int):void {
- readLength_ = readLength;
- checkReadLength_ = true;
- }
-
- protected function checkReadLength(length:int):void {
- if (checkReadLength_) {
- readLength_ -= length;
- if (readLength_ < 0) {
- throw new TError("Message length exceeded: " + length);
- }
- }
- }
private static function reset(arr:ByteArray):void {
arr.length = 0;
diff --git a/lib/csharp/src/Protocol/TBinaryProtocol.cs b/lib/csharp/src/Protocol/TBinaryProtocol.cs
index e16b8371a..4bbd9ad1a 100644
--- a/lib/csharp/src/Protocol/TBinaryProtocol.cs
+++ b/lib/csharp/src/Protocol/TBinaryProtocol.cs
@@ -35,10 +35,6 @@ namespace Thrift.Protocol
protected bool strictRead_ = false;
protected bool strictWrite_ = true;
- protected int readLength_;
- protected bool checkReadLength_ = false;
-
-
#region BinaryProtocol Factory
/**
* Factory
@@ -375,35 +371,15 @@ namespace Thrift.Protocol
#endif
}
- public void SetReadLength(int readLength)
- {
- readLength_ = readLength;
- checkReadLength_ = true;
- }
-
- protected void CheckReadLength(int length)
- {
- if (checkReadLength_)
- {
- readLength_ -= length;
- if (readLength_ < 0)
- {
- throw new Exception("Message length exceeded: " + length);
- }
- }
- }
-
public override byte[] ReadBinary()
{
int size = ReadI32();
- CheckReadLength(size);
byte[] buf = new byte[size];
trans.ReadAll(buf, 0, size);
return buf;
}
private string ReadStringBody(int size)
{
- CheckReadLength(size);
byte[] buf = new byte[size];
trans.ReadAll(buf, 0, size);
return Encoding.UTF8.GetString(buf, 0, buf.Length);
@@ -411,7 +387,6 @@ namespace Thrift.Protocol
private int ReadAll(byte[] buf, int off, int len)
{
- CheckReadLength(len);
return trans.ReadAll(buf, off, len);
}
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index b08458aa3..1f2720382 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -370,13 +370,11 @@ type
protected
FStrictRead : Boolean;
FStrictWrite : Boolean;
- FReadLength : Integer;
- FCheckReadLength : Boolean;
private
function ReadAll( var buf: TBytes; off: Integer; len: Integer ): Integer;
function ReadStringBody( size: Integer): string;
- procedure CheckReadLength( len: Integer );
+
public
type
@@ -434,7 +432,6 @@ type
function ReadDouble:Double; override;
function ReadBinary: TBytes; override;
- procedure SetReadLength( readLength: Integer );
end;
@@ -859,18 +856,6 @@ begin
Create( trans, False, True);
end;
-procedure TBinaryProtocolImpl.CheckReadLength(len: Integer);
-begin
- if FCheckReadLength then
- begin
- Dec( FReadLength, len);
- if FReadLength < 0 then
- begin
- raise Exception.Create( 'Message length exceeded: ' + IntToStr( len ) );
- end;
- end;
-end;
-
constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
strictWrite: Boolean);
begin
@@ -882,7 +867,6 @@ end;
function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,
len: Integer): Integer;
begin
- CheckReadLength( len );
Result := FTrans.ReadAll( buf, off, len );
end;
@@ -892,7 +876,6 @@ var
buf : TBytes;
begin
size := ReadI32;
- CheckReadLength( size );
SetLength( buf, size );
FTrans.ReadAll( buf, 0, size);
Result := buf;
@@ -1063,7 +1046,6 @@ function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
var
buf : TBytes;
begin
- CheckReadLength( size );
SetLength( buf, size );
FTrans.ReadAll( buf, 0, size );
Result := TEncoding.UTF8.GetString( buf);
@@ -1080,12 +1062,6 @@ begin
end;
-procedure TBinaryProtocolImpl.SetReadLength(readLength: Integer);
-begin
- FReadLength := readLength;
- FCheckReadLength := True;
-end;
-
procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
var iLen : Integer;
begin
diff --git a/lib/go/thrift/binary_protocol.go b/lib/go/thrift/binary_protocol.go
index 6fb862473..b57b528df 100644
--- a/lib/go/thrift/binary_protocol.go
+++ b/lib/go/thrift/binary_protocol.go
@@ -30,8 +30,6 @@ type TBinaryProtocol struct {
trans TTransport
strictRead bool
strictWrite bool
- readLength int
- checkReadLength bool
buffer [8]byte
}
@@ -45,8 +43,7 @@ func NewTBinaryProtocolTransport(t TTransport) *TBinaryProtocol {
}
func NewTBinaryProtocol(t TTransport, strictRead, strictWrite bool) *TBinaryProtocol {
- //return &TBinaryProtocol{TProtocolBase:TProtocolBase{trans:t}, strictRead:strictRead, strictWrite:strictWrite, readLength:0, checkReadLength:false};
- return &TBinaryProtocol{trans: t, strictRead: strictRead, strictWrite: strictWrite, readLength: 0, checkReadLength: false}
+ return &TBinaryProtocol{trans: t, strictRead: strictRead, strictWrite: strictWrite}
}
func NewTBinaryProtocolFactoryDefault() *TBinaryProtocolFactory {
@@ -412,9 +409,6 @@ func (p *TBinaryProtocol) ReadBinary() ([]byte, error) {
return nil, e
}
isize := int(size)
- if e = p.readLengthOk(isize); e != nil {
- return nil, e
- }
buf := make([]byte, isize)
_, err := io.ReadFull(p.trans, buf)
return buf, NewTProtocolException(err)
@@ -433,35 +427,14 @@ func (p *TBinaryProtocol) Transport() TTransport {
}
func (p *TBinaryProtocol) readAll(buf []byte) error {
- if e := p.readLengthOk(len(buf)); e != nil {
- return e
- }
_, err := io.ReadFull(p.trans, buf)
return NewTProtocolException(err)
}
-func (p *TBinaryProtocol) setReadLength(readLength int) {
- p.readLength = readLength
- p.checkReadLength = true
-}
-
-func (p *TBinaryProtocol) readLengthOk(length int) error {
- if p.checkReadLength {
- p.readLength = p.readLength - length
- if p.readLength < 0 {
- return NewTProtocolExceptionWithType(UNKNOWN_PROTOCOL_EXCEPTION, fmt.Errorf("Message length exceeded: %d", length))
- }
- }
- return nil
-}
-
func (p *TBinaryProtocol) readStringBody(size int) (value string, err error) {
if size < 0 {
return "", nil
}
- if err := p.readLengthOk(size); err != nil {
- return "", err
- }
isize := int(size)
buf := make([]byte, isize)
_, e := io.ReadFull(p.trans, buf)
diff --git a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
index 0c20fa98c..32a761f23 100644
--- a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
@@ -38,37 +38,24 @@ public class TBinaryProtocol extends TProtocol {
protected boolean strictRead_ = false;
protected boolean strictWrite_ = true;
- protected int readLength_;
- protected boolean checkReadLength_ = false;
-
/**
* Factory
*/
public static class Factory implements TProtocolFactory {
protected boolean strictRead_ = false;
protected boolean strictWrite_ = true;
- protected int readLength_;
public Factory() {
this(false, true);
}
public Factory(boolean strictRead, boolean strictWrite) {
- this(strictRead, strictWrite, 0);
- }
-
- public Factory(boolean strictRead, boolean strictWrite, int readLength) {
strictRead_ = strictRead;
strictWrite_ = strictWrite;
- readLength_ = readLength;
}
public TProtocol getProtocol(TTransport trans) {
- TBinaryProtocol proto = new TBinaryProtocol(trans, strictRead_, strictWrite_);
- if (readLength_ != 0) {
- proto.setReadLength(readLength_);
- }
- return proto;
+ return new TBinaryProtocol(trans, strictRead_, strictWrite_);
}
}
@@ -349,7 +336,6 @@ public class TBinaryProtocol extends TProtocol {
public String readStringBody(int size) throws TException {
try {
- checkReadLength(size);
byte[] buf = new byte[size];
trans_.readAll(buf, 0, size);
return new String(buf, "UTF-8");
@@ -360,7 +346,6 @@ public class TBinaryProtocol extends TProtocol {
public ByteBuffer readBinary() throws TException {
int size = readI32();
- checkReadLength(size);
if (trans_.getBytesRemainingInBuffer() >= size) {
ByteBuffer bb = ByteBuffer.wrap(trans_.getBuffer(), trans_.getBufferPosition(), size);
@@ -374,25 +359,6 @@ public class TBinaryProtocol extends TProtocol {
}
private int readAll(byte[] buf, int off, int len) throws TException {
- checkReadLength(len);
return trans_.readAll(buf, off, len);
}
-
- public void setReadLength(int readLength) {
- readLength_ = readLength;
- checkReadLength_ = true;
- }
-
- protected void checkReadLength(int length) throws TException {
- if (length < 0) {
- throw new TProtocolException("Negative length: " + length);
- }
- if (checkReadLength_) {
- readLength_ -= length;
- if (readLength_ < 0) {
- throw new TProtocolException("Message length exceeded: " + length);
- }
- }
- }
-
}
diff --git a/lib/javame/src/org/apache/thrift/protocol/TBinaryProtocol.java b/lib/javame/src/org/apache/thrift/protocol/TBinaryProtocol.java
index 1d16889e7..f6fe76543 100644
--- a/lib/javame/src/org/apache/thrift/protocol/TBinaryProtocol.java
+++ b/lib/javame/src/org/apache/thrift/protocol/TBinaryProtocol.java
@@ -1,4 +1,4 @@
-/*
+ /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -36,9 +36,6 @@ public class TBinaryProtocol extends TProtocol {
protected boolean strictRead_ = false;
protected boolean strictWrite_ = true;
- protected int readLength_;
- protected boolean checkReadLength_ = false;
-
/**
* Factory
*/
@@ -311,7 +308,6 @@ public class TBinaryProtocol extends TProtocol {
public String readStringBody(int size) throws TException {
try {
- checkReadLength(size);
byte[] buf = new byte[size];
trans_.readAll(buf, 0, size);
return new String(buf, "UTF-8");
@@ -322,29 +318,12 @@ public class TBinaryProtocol extends TProtocol {
public byte[] readBinary() throws TException {
int size = readI32();
- checkReadLength(size);
byte[] buf = new byte[size];
trans_.readAll(buf, 0, size);
return buf;
}
private int readAll(byte[] buf, int off, int len) throws TException {
- checkReadLength(len);
return trans_.readAll(buf, off, len);
}
-
- public void setReadLength(int readLength) {
- readLength_ = readLength;
- checkReadLength_ = true;
- }
-
- protected void checkReadLength(int length) throws TException {
- if (checkReadLength_) {
- readLength_ -= length;
- if (readLength_ < 0) {
- throw new TException("Message length exceeded: " + length);
- }
- }
- }
-
}