public MessagePackParser GetValueByIntKey(int target) { if (!FormatType.IsMap()) { throw new InvalidOperationException("not map"); } uint count; var current = GetItemCount(out count); var childCount = count * 2; for (var i = 0; i < childCount; i += 2) { var key = new MessagePackParser(current); current = key._Parse(); var value = new MessagePackParser(current); current = value._Parse(); if (key.GetInt32() == target) { return(value); } } throw new KeyNotFoundException(); }
ArraySegment <Byte> _Parse() { ArraySegment <Byte> current; if (FormatType.IsArray()) { uint count; current = GetItemCount(out count); //Children = new MsgPackValue[count]; for (var i = 0; i < count; ++i) { var child = new MessagePackParser(current); current = child._Parse(); } } else if (FormatType.IsMap()) { uint count; current = GetItemCount(out count); //Children = new MsgPackValue[count * 2]; var childCount = count * 2; for (var i = 0; i < childCount; ++i) { var child = new MessagePackParser(current); current = child._Parse(); } } else { var body = GetBody(); var header = body.Offset - Bytes.Offset; current = Bytes.Advance(header + body.Count); } var size = current.Offset - Bytes.Offset; var result = Bytes.Advance(size); Bytes = Bytes.Take(size); return(result); }
public override string ToString() { if (FormatType.IsArray()) { return("array(" + Count + ")"); } else if (FormatType.IsMap()) { return("map(" + Count + ")"); } else if (FormatType.IsExt()) { return("ext"); } else if (FormatType.IsBinary()) { return("binary"); } else { return(GetValue().ToString()); } }