本文整理汇总了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));
}
}