本文整理匯總了C#中System.ByteBuffer.Remaining方法的典型用法代碼示例。如果您正苦於以下問題:C# ByteBuffer.Remaining方法的具體用法?C# ByteBuffer.Remaining怎麽用?C# ByteBuffer.Remaining使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.Remaining方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Read
public void Read(ByteBuffer buf)
{
buf.Get();//0x01
int len=buf.GetUShort();
Text = Utils.Util.GetString(buf.GetByteArray(len));
if (buf.HasRemaining())
{
RemainBytes = buf.GetByteArray(buf.Remaining());
QQClient.LogManager.Log("NormalIMText Class Parse Buf Remaining Data:" + Utils.Util.ToHex(RemainBytes));
}
}
示例2: Accept
public bool Accept(ByteBuffer buf)
{
//保存偏移
offset = buf.Position;
int bufferLength = buf.Remaining();
if (bufferLength <= 0)
return false;
bool accept = CheckTcp(buf);
if (!accept)
accept = CheckUdp(buf);
return accept;
}
示例3: Read
/// <summary>
/// 給定一個輸入流,解析SendFileRequest結構
/// </summary>
/// <param name="buf">The buf.</param>
public void Read(ByteBuffer buf)
{
// 跳過空格符和分隔符
buf.GetChar();
// 獲取後麵的所有內容
byte[] b = buf.GetByteArray(buf.Remaining());
// 找到分隔符
int i = Array.IndexOf<byte>(b, 0, (byte)0x1F);
// 得到文件名
FileName = Utils.Util.GetString(b, 0, i);
// 得到文件大小的字符串形式
String sizeStr = Utils.Util.GetString(b, i + 1, b.Length - 6 - i);
FileSize = Utils.Util.GetInt(sizeStr, 0);
}
示例4: ParseBody
/// <summary>
/// 解析包體,從buf的開頭位置解析起
/// <remark>abu 2008-02-18 </remark>
/// </summary>
/// <param name="buf">The buf.</param>
protected override void ParseBody(ByteBuffer buf)
{
#if DEBUG
Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray()));
#endif
Empty = false;
// 檢查消息長度,至少要有16字節,因為我們需要前16字節做為確認發回
if (buf.Remaining() < 16)
{
throw new PacketParseException("收到的消息太短,拋棄該消息");
}
// 得到前16個字節用作回複
Reply = buf.GetByteArray(16);
// 讀取消息頭
buf.Position = 0;
Header = new ReceiveIMHeader();
Header.Read(buf);
// 檢查輸入流可用字節
if (!buf.HasRemaining())
{
Empty = true;
return;
}
// 判斷消息類型
int len = 0;
switch (Header.Type)
{
case RecvSource.FRIEND_0801: //手機消息
buf.Position += 10;//buf.GetInt();
ParseNormalIM(buf);
break;
case RecvSource.FRIEND_0802:
ParseNormalIM(buf);
break;
case RecvSource.FRIEND_09:
buf.Position += 11;
ParseNormalIM(buf);
break;
case RecvSource.FRIEND_09SP1:
buf.Position += 2;
int len1 = buf.GetUShort();
buf.Position += len1;
ParseNormalIM(buf);
break;
case RecvSource.STRANGER:
/* 是從好友或者陌生人處發來的消息 */
ParseNormalIM(buf);
break;
case RecvSource.TEMP_SESSION:
TempSessionIM = new TempSessionIM();
TempSessionIM.Read(buf);
break;
case RecvSource.SYS_MESSAGE:
/* 是係統消息 */
buf.GetInt();//00 00 00 00
ParseSystemMessage(buf);
break;
case RecvSource.CLUSTER_09:
/* 群消息09 */
ParseClusterIM09(buf);
break;
case RecvSource.CLUSTER:
/* 群消息 */
ParseClusterIM(buf);
break;
case RecvSource.TEMP_CLUSTER:
/* 臨時群消息 */
ParseTempClusterIM(buf);
break;
case RecvSource.UNKNOWN_CLUSTER:
ParseUnknownClusterIM(buf);
break;
case RecvSource.BIND_USER:
SMS = new SMS();
SMS.ReadBindUserSMS(buf);
break;
case RecvSource.MOBILE_QQ:
SMS = new SMS();
SMS.ReadMobileQQSMS(buf);
break;
case RecvSource.MOBILE_QQ_2 :
SMS = new SMS();
SMS.ReadMobileQQ2SMS(buf);
break;
case RecvSource.MOBILE:
SMS = new SMS();
SMS.ReadMobileSMS(buf);
break;
case RecvSource.CREATE_CLUSTER:
case RecvSource.ADDED_TO_CLUSTER:
case RecvSource.DELETED_FROM_CLUSTER:
ExternalId = buf.GetInt();
ClusterType = (ClusterType)buf.Get();
//.........這裏部分代碼省略.........
示例5: Read09
/// <summary>
/// 分析09的流
/// </summary>
/// <param name="buf"></param>
public void Read09(ByteBuffer buf)
{
FontStyle = new FontStyle();
// 是否有字體屬性
HasFontAttribute = buf.GetInt() != 0;
// 分片數
TotalFragments = (int)buf.Get();
// 分片序號
FragmentSequence = (int)buf.Get();
// 消息id 兩個字節
MessageId = (int)buf.GetUShort();
// 消息類型,這裏的類型表示是正常回複還是自動回複之類的信息
ReplyType = (ReplyType)buf.Get();
// 消息正文
#region 字體屬性開始 未處理
buf.Position += 8;//'M' 'S' 'G' 00 00 00 00 00
buf.GetInt();//send time
buf.Position += 12;//5D 69 71 DE 00 80 80 00 0A 00 86 00 參見sendim
int len = buf.GetUShort();
buf.GetByteArray(len);//字體 E5 AE 8B E4 BD 93 =宋體
#endregion
buf.GetUShort();//00 00
IsNormalIM09 = true;//標注09的信息
MessageBytes = buf.GetByteArray(buf.Remaining());
//_Message = "";
//while (buf.HasRemaining())
//{
// byte type = buf.Get();
// len = buf.GetUShort();
// switch (type)
// {
// case 0x01://pure text
// //len_str = buf.GetUShort();
// _Message +=new NormalIMText(QQClient,buf.GetByteArray(len)).ToString();
// break;
// case 0x02://face
// _Message += new NormalIMFace(QQClient, buf.GetByteArray(len)).ToString();
// break;
// case 0x06://image
// _Message += new NormalIMImage(QQClient, buf.GetByteArray(len)).ToString();
// break;
// default:
// QQClient.LogManager.Log(ToString() + " Class Parse Unknown Type=0x" + type.ToString("X") + " Data=" + Utils.Util.ToHex(buf.GetByteArray(len)));
// break;
// }
//}
}
示例6: Read
/// <summary>給定一個輸入流,解析NormalIM結構
/// </summary>
/// <param name="buf">The buf.</param>
public void Read(ByteBuffer buf)
{
FontStyle = new FontStyle();
// 是否有字體屬性
HasFontAttribute = buf.GetInt() != 0;
// 分片數
TotalFragments = (int)buf.Get();
// 分片序號
FragmentSequence = (int)buf.Get();
// 消息id 兩個字節
MessageId = (int)buf.GetUShort();
// 消息類型,這裏的類型表示是正常回複還是自動回複之類的信息
ReplyType = (ReplyType)buf.Get();
// 消息正文,長度=剩餘字節數 - 包尾字體屬性長度
int remain = buf.Remaining();
int fontAttributeLength = HasFontAttribute ? (buf.Get(buf.Position + remain - 1) & 0xFF) : 0;
MessageBytes = buf.GetByteArray(remain - fontAttributeLength);
// 這後麵都是字體屬性,這個和SendIMPacket裏麵的是一樣的
if (HasFontAttribute)
{
if (buf.HasRemaining())
FontStyle.Read(buf);
else
HasFontAttribute = false;
}
}
示例7: Relocate
public int Relocate(ByteBuffer buf)
{
int offset = buf.Position;
if (buf.Remaining() < 2)
return offset;
int len = buf.GetUShort(offset);
if (len <= 0 || offset + len > buf.Length)
return offset;
else
return offset + len;
}
示例8: Read
public void Read(ByteBuffer buf)
{
while (buf.HasRemaining())
{
byte type = buf.Get();
int len = buf.GetUShort();
switch (type)
{
case 0x02:
FileName = Utils.Util.GetString(buf.GetByteArray(len));
break;
case 0x03://filesize
FileSize =(int) Utils.Util.GetUInt(buf.GetByteArray(len), 0, 4); //buf.GetInt();
break;
case 0x04://guid
FGuid = Utils.Util.GetString(buf.GetByteArray(len));
break;
case 0xff:
FFData = buf.GetByteArray(len);
break;
default:
QQClient.LogManager.Log(base.ToString()+" Parse Error,Unknown Type=" + type.ToString("X") + ": Data=" + Utils.Util.ToHex(buf.GetByteArray(len)));
break;
}
}
if (buf.HasRemaining())
{
RemainBytes = buf.GetByteArray(buf.Remaining());
QQClient.LogManager.Log(base.ToString() + " Class Parse Buf Remaining Data:" + Utils.Util.ToHex(RemainBytes));
}
}
示例9: Read
public void Read( ByteBuffer buf)
{
while (buf.HasRemaining())
{
byte type = buf.Get();
int len = buf.GetUShort();
switch (type)
{
case 0x01:
FaceId = buf.Get();
break;
case 0xff:
FFData = buf.GetByteArray(len);
break;
default:
QQClient.LogManager.Log(base.ToString()+" Parse Error,Unknown Type=" + type.ToString("X") + ": Data=" + Utils.Util.ToHex(buf.GetByteArray(len)));
break;
}
}
if (buf.HasRemaining())
{
RemainBytes = buf.GetByteArray(buf.Remaining());
QQClient.LogManager.Log(base.ToString() + " Class Parse Buf Remaining Data:" + Utils.Util.ToHex(RemainBytes));
}
}