public string ReadByteString(string s, int tag, bool isRequire) { if (SkipToTag(tag)) { var hd = new HeadData(); ReadHead(hd); switch (hd.Type) { case (byte)TarsStructType.String1: { { int len = 0; len = buffer.ReadByte(); if (len < 0) { len += 256; } byte[] ss = new byte[len]; buffer.ReadBytes(ss); s = HexUtil.Bytes2HexStr(ss); } } break; case (byte)TarsStructType.String4: { { int len = 0; len = buffer.ReadInt(); if (len > Const.TarsMaxStringLength || len < 0) { throw new TarsDecodeException("string too long: " + len); } byte[] ss = buffer.ReadBytes(len).Array; s = HexUtil.Bytes2HexStr(ss); } } break; default: { throw new TarsDecodeException("type mismatch."); } } } else if (isRequire) { throw new TarsDecodeException("require field not exist."); } return(s); }
public string ReadByteString(int tag, bool isRequire) { if (SkipToTag(tag)) { var hd = new HeadData(); ReadHead(hd); switch (hd.Type) { case TarsStructBase.STRING1: { int len = buffer.ReadByte(); if (len < 0) { len += 256; } byte[] ss = new byte[len]; buffer.ReadBytes(ss); return(HexUtil.Bytes2HexStr(ss)); } case TarsStructBase.STRING4: { int len = buffer.ReadInt(); if (len > TarsStructBase.MAX_STRING_LENGTH || len < 0) { throw new TarsDecodeException("string too long: " + len); } byte[] ss = buffer.ReadBytes(len).Array; return(HexUtil.Bytes2HexStr(ss)); } default: throw new TarsDecodeException("type mismatch."); } } else if (isRequire) { throw new TarsDecodeException("require field not exist."); } return(null); }