protected var strictRead_:Boolean = false;
protected var strictWrite_:Boolean = true;
- protected var readLength_:int;
- protected var checkReadLength_:Boolean = false;
-
/**
* Factory
*/
public function readBinary():ByteArray {
var size:int = readI32();
- checkReadLength(size);
var buf:ByteArray = new ByteArray();
trans_.readAll(buf, 0, size);
return buf;
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;
protected bool strictRead_ = false;
protected bool strictWrite_ = true;
- protected int readLength_;
- protected bool checkReadLength_ = false;
-
-
#region BinaryProtocol Factory
/**
* Factory
#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);
private int ReadAll(byte[] buf, int off, int len)
{
- CheckReadLength(len);
return trans.ReadAll(buf, off, len);
}
protected\r
FStrictRead : Boolean;\r
FStrictWrite : Boolean;\r
- FReadLength : Integer;\r
- FCheckReadLength : Boolean;\r
\r
private\r
function ReadAll( var buf: TBytes; off: Integer; len: Integer ): Integer;\r
function ReadStringBody( size: Integer): string;\r
- procedure CheckReadLength( len: Integer );\r
+\r
public\r
\r
type\r
function ReadDouble:Double; override;\r
function ReadBinary: TBytes; override;\r
\r
- procedure SetReadLength( readLength: Integer );\r
end;\r
\r
\r
Create( trans, False, True);\r
end;\r
\r
-procedure TBinaryProtocolImpl.CheckReadLength(len: Integer);\r
-begin\r
- if FCheckReadLength then\r
- begin\r
- Dec( FReadLength, len);\r
- if FReadLength < 0 then\r
- begin\r
- raise Exception.Create( 'Message length exceeded: ' + IntToStr( len ) );\r
- end;\r
- end;\r
-end;\r
-\r
constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,\r
strictWrite: Boolean);\r
begin\r
function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,\r
len: Integer): Integer;\r
begin\r
- CheckReadLength( len );\r
Result := FTrans.ReadAll( buf, off, len );\r
end;\r
\r
buf : TBytes;\r
begin\r
size := ReadI32;\r
- CheckReadLength( size );\r
SetLength( buf, size );\r
FTrans.ReadAll( buf, 0, size);\r
Result := buf;\r
var\r
buf : TBytes;\r
begin\r
- CheckReadLength( size );\r
SetLength( buf, size );\r
FTrans.ReadAll( buf, 0, size );\r
Result := TEncoding.UTF8.GetString( buf);\r
\r
end;\r
\r
-procedure TBinaryProtocolImpl.SetReadLength(readLength: Integer);\r
-begin\r
- FReadLength := readLength;\r
- FCheckReadLength := True;\r
-end;\r
-\r
procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);\r
var iLen : Integer;\r
begin\r
trans TTransport
strictRead bool
strictWrite bool
- readLength int
- checkReadLength bool
buffer [8]byte
}
}
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 {
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)
}
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)
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_);
}
}
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");
public ByteBuffer readBinary() throws TException {
int size = readI32();
- checkReadLength(size);
if (trans_.getBytesRemainingInBuffer() >= size) {
ByteBuffer bb = ByteBuffer.wrap(trans_.getBuffer(), trans_.getBufferPosition(), size);
}
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);
- }
- }
- }
-
}
-/*
+ /*
* 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
protected boolean strictRead_ = false;
protected boolean strictWrite_ = true;
- protected int readLength_;
- protected boolean checkReadLength_ = false;
-
/**
* Factory
*/
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");
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);
- }
- }
- }
-
}