/// <summary> /// Parses a metadata. /// Metadata consists of a list of properties consisting of /// name and value as size-specified strings. /// </summary> /// <returns>Returns true on success and false on error.</returns> protected bool ParseMetadata(Span <byte> source) { while (source.Length > 1) { int nameLength = source[0]; source = source.Slice(NameLengthSize); if (source.Length < nameLength) { break; } string name = SpanUtility.ToAscii(source.Slice(0, nameLength)); source = source.Slice(nameLength); if (source.Length < ValueLengthSize) { break; } int valueLength = NetworkOrderBitsConverter.ToInt32(source); source = source.Slice(ValueLengthSize); if (source.Length < valueLength) { break; } byte[] value = new byte[valueLength]; source.Slice(0, valueLength).CopyTo(value); source = source.Slice(valueLength); if (name == ZmtpPropertyIdentity && Options.RecvIdentity) { PeerIdentity = value; } else if (name == ZmtpPropertySocketType) { if (!CheckSocketType(Encoding.ASCII.GetString(value))) { return(false); } } else { if (!GetProperty(name, value, valueLength)) { return(false); } } } if (source.Length > 0) { return(false); } return(true); }
PushMsgResult ProcessErrorCommand(Span <byte> commandData) { int fixedPrefixSize = ErrorCommandName.Length + 1 + ErrorReasonLengthSize; if (commandData.Length < fixedPrefixSize) { return(PushMsgResult.Error); } int errorReasonLength = commandData[ErrorCommandName.Length + 1]; if (errorReasonLength > commandData.Length - fixedPrefixSize) { return(PushMsgResult.Error); } string errorReason = SpanUtility.ToAscii(commandData.Slice(fixedPrefixSize, errorReasonLength)); // TODO: handle error, nothing todo at the moment as monitoring and zap are not yet implemented m_errorCommandReceived = true; return(PushMsgResult.Ok); }