protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length) { bufferStream.Skip(FixedHeaderTryConst.KEYSIZE); byte[] bodySizeBuf = new byte[FixedHeaderTryConst.BODYSIZE_LEN]; //注意 Read方法的第二个参数,目标数组的偏移 bufferStream.Read(bodySizeBuf, 0, FixedHeaderTryConst.BODYSIZE_LEN); return(PackageBodyOperator.GetBodyLen(bodySizeBuf)); //throw new NotImplementedException(); }
public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) { //throw new NotImplementedException(); string key = bufferStream.ReadString(FixedHeaderTryConst.KEYSIZE, Encoding.UTF8); byte[] buffer = new byte[FixedHeaderTryConst.BODYSIZE_LEN]; bufferStream.Read(buffer, 0, FixedHeaderTryConst.BODYSIZE_LEN); int bodySize = PackageBodyOperator.GetBodyLen(buffer); string body = bufferStream.ReadString(bodySize, Encoding.UTF8); return(new StringPackageInfo(key, body, null)); }
//offset = 0 protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length) { return(PackageBodyOperator.GetBodyLen(header, offset + FixedHeaderTryConst.KEYSIZE)); }