本文整理汇总了C#中ByteBuffer.toArray方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.toArray方法的具体用法?C# ByteBuffer.toArray怎么用?C# ByteBuffer.toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.toArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Adler32
public static uint Adler32(ByteBuffer data, uint start, uint len)
{
if (start >= data.length())
{
start = (uint) data.length();
}
if (len == 0)
{
len = ((uint) data.length()) - start;
}
if ((len + start) > data.length())
{
len = ((uint) data.length()) - start;
}
uint index = start;
uint num2 = 1;
uint num3 = 0;
while (index < (start + len))
{
num2 = (num2 + data.toArray()[index]) % 0xfff1;
num3 = (num2 + num3) % 0xfff1;
index++;
}
return ((num3 << 0x10) | num2);
}
示例2: writeBytes
public void writeBytes(ByteBuffer b, uint offset, uint len)
{
this.write(b.toArray(), (int) offset, (int) len);
}
示例3: encryptionCode
private ByteBuffer encryptionCode(ByteBuffer data, int[] code)
{
byte[] buffer = CodecKit.encodeXor (data.toArray (), this.nextPK (code));
data = new ByteBuffer ();
for (int i = 0; i < buffer.Length; i++) {
data.writeByte (buffer [i]);
}
data.position = 0;
return data;
}
示例4: parseMessage
public void parseMessage(ByteBuffer socketbuffer)
{
int num = socketbuffer.readByte ();
bool flag = (num & 8) != 0;
bool flag2 = (num & 4) != 0;
bool flag3 = (num & 2) != 0;
ByteBuffer data = new ByteBuffer (this.length - 1);
data.write (socketbuffer.toArray (), 0, this.length - 1);
if (base.socket.Available >= 2) {
byte[] buffer = new byte[2];
base.socket.Receive (buffer, SocketFlags.None);
this.length = ByteKit.readUnsignedShort (buffer, 0);
} else {
this.length = 0;
}
if (flag) {
data = this.encryptionCode (data, this._receiveChallengeCode);
}
if (flag3) {
data = new ByteBuffer (ZIPUtil.Decompress (data.toArray ()));
}
if (flag2) {
int num2 = data.readInt ();
ByteBuffer buffer4 = new ByteBuffer ();
buffer4.writeBytes (data.toArray (), 0, data.top - data.position);
int num3 = (int)ChecksumUtil.Adler32 (buffer4);
if (num2 != num3) {
//MonoBehaviour.print(string.Concat(new object[] { "crc is err,crcValue", num2, ",nowCrc=", num3 }));
// Log.info
return;
}
}
ErlKVMessage message = new ErlKVMessage (null);
message.bytesRead (data);
if (base._portHandler != null) {
base._portHandler.erlReceive (this, message);
}
}
示例5: createDataByHead
protected override ByteBuffer createDataByHead(ByteBuffer head)
{
ByteBuffer buffer = new ByteBuffer ();
int b = (((0 | (this._encryption << 3)) | (this._crc << 2)) | (this._compress << 1)) | this._kv;
buffer.writeShort (head.length () + 1);
buffer.writeByte (b);
buffer.writeBytes (head.toArray ());
return buffer;
}
示例6: TransParseMessage
public void TransParseMessage(ByteBuffer socketbuffer , bool isServer , ByteBuffer src)
{
try{
int num = socketbuffer.readByte ();
bool flag = (num & 8) != 0;
bool flag2 = (num & 4) != 0;
bool flag3 = (num & 2) != 0;
ByteBuffer data = new ByteBuffer (this.length - 1);
data.write (socketbuffer.toArray (), 0, this.length - 1);
if ((this.dataBuffer.bytesAvailable) >= 2) {
byte[] buffer = new byte[2];
//base.socket.Receive (buffer, SocketFlags.None);
this.dataBuffer.readBytes(buffer,0,2);
this.length = ByteKit.readUnsignedShort (buffer, 0);
} else {
this.length = 0;
}
if (flag) {
if (this.isServer) {
data = this.encryptionCode (data, this._sendChallengeCode);
} else {
data = this.encryptionCode (data, this._receiveChallengeCode);
}
}
if (flag3) {
data = new ByteBuffer (ZIPUtil.Decompress (data.toArray ()));
}
if (flag2) {
int num2 = data.readInt ();
ByteBuffer buffer4 = new ByteBuffer ();
buffer4.writeBytes (data.toArray (), 0, (int)data.bytesAvailable);
int num3 = (int)ChecksumUtil.Adler32 (buffer4);
if (num2 != num3) {
Log.Error(string.Concat(new object[] { "crc is err,crcValue", num2, ",nowCrc=", num3 }));
// Log.info
//if (this.transCallBack != null) {
// this.transCallBack.Invoke ();
// }
int len = (int)this.dataBuffer.bytesAvailable;
int pos = this.dataBuffer.position;
byte[] tmp = new byte[len];
byte[] bak = new byte[pos];
this.dataBuffer.position = 0;
this.dataBuffer.readBytes (bak, 0, pos);
this.dataBuffer.readBytes (tmp, 0, len);
this.dataBuffer.clear ();
this.dataBuffer = new ByteBuffer (tmp);
if(!this.isServer){
base.socket.Send (bak);}
if (this.dataBuffer.bytesAvailable > 0) {
this.TransReceive (null, this.isServer);
}
return;
}
}
ErlKVMessage message = new ErlKVMessage (null);
this.tmpBuffer = data;
message.bytesRead (data);
Log.Debug(string.Concat( data.getArray())+"++++++");
this.myLen = this.dataBuffer.top;
if (base._portHandler != null) {
base._portHandler.erlReceive (this, message);
}
}
catch(Exception e) {
Log.Error (e.Message);
if (this.dataBuffer.bytesAvailable > 0) {
this.TransReceive (null, this.isServer);
} else {
int len = (int)this.dataBuffer.bytesAvailable;
int pos = this.dataBuffer.position;
byte[] tmp = new byte[len];
byte[] bak = new byte[pos];
this.dataBuffer.position = 0;
this.dataBuffer.readBytes (bak, 0, pos);
this.dataBuffer.readBytes (tmp, 0, len);
this.dataBuffer.clear ();
this.dataBuffer = new ByteBuffer (tmp);
if (!this.isServer) {
base.socket.Send (bak);
}
if (this.dataBuffer.bytesAvailable > 0) {
this.TransReceive (null, this.isServer);
}
}
}
}
示例7: sendErl
public void sendErl(ByteBuffer data, int encryption, int crc, int compress, int kv)
{
if ((this._sendChallengeCode != null) && (this._sendChallengeCode.Length >= 0)) {
this._encryption = encryption;
this._crc = crc;
this._compress = compress;
this._kv = kv;
int i = 0;
ByteBuffer buffer = new ByteBuffer ();
if ((this._compress == 1) && (data.length () >= 0x40)) {
data = new ByteBuffer (ZIPUtil.Compress (data.toArray ()));
} else {
this._compress = 0;
}
if ((this._crc == 1) && (this._compress == 0)) {
i = (int)ChecksumUtil.Adler32 (data);
buffer.writeInt (i);
} else {
this._crc = 0;
}
buffer.writeBytes (data.toArray ());
if (this._encryption == 1) {
if (!this.isServer) {
buffer = this.encryptionCode (buffer, this._receiveChallengeCode);
/*string code = "";
foreach(int sc in this._receiveChallengeCode)
{
code = code + sc ;
}
//Log.Info("---this._receiveChallengeCode="+ code);
*/
} else {
buffer = this.encryptionCode (buffer, this._sendChallengeCode);
/*string code = "";
foreach(int sc in this._sendChallengeCode)
{
code = code + sc ;
}
Log.Info("---this._sendChallengeCode="+ code);
*/
}
//buffer = this.encryptionCode (buffer, this._receiveChallengeCode);
}
base.send (buffer);
//Log.Info(string.Concat(buffer.getArray()));
this._encryption = 1;
this._crc = 1;
this._compress = 1;
this._kv = 1;
}
}
示例8: createDataByHead
protected virtual ByteBuffer createDataByHead(ByteBuffer body)
{
int len = body.length();
ByteBuffer data = new ByteBuffer();
ByteKit.writeLength(data, len);
data.writeBytes(body.toArray());
return data;
}
示例9: send
public void send(ByteBuffer data)
{
if (this._active)
{
data = this.createDataByHead(data);
//Log.info(data.toArray().Length);
this.send(data.toArray(), 0, data.length());
}
}