public static State Get(long size) { if (size == 0) { return(End.Singleton); } if (size < 0) { throw new ArgumentException("Size must be nonnegative", nameof(size)); } if (size > 256) { return(new Seek(size)); } var cached = Volatile.Read(ref cache[size - 1]); if (cached != null) { return(cached); } var result = new Seek(size); Volatile.Write(ref cache[size - 1], result); return(result); }
public override State Transit(Stream stream) { var @byte = stream.ReadByte(); if (@byte == -1) { return(this); } if (@byte == '-') { // | // -1\r\n return(Seek.Get(3)); } if (@byte == '0') { // | // 0\r\n return(Seek.Get(2)); } return(new ArrayLength(@byte - '0')); }
public override State Transit(Stream stream) { var @byte = stream.ReadByte(); if (@byte == -1) { return(this); } if (@byte == '-') { // | // "-1\r\n" return(Seek.Get(3)); } if (@byte == '0') { // | // 0\r\n\r\n return(Seek.Get(4)); } return(new BulkString(@byte - '0')); }
public override State Transit(Stream stream) { var length = partiallyParsedLength; while (true) { var @byte = stream.ReadByte(); if (@byte == -1) { return(length == partiallyParsedLength ? this : new ArrayLength(length)); } if (@byte == '\r') { // \n (length items) return(new Serial( Seek.Get(1), Array.Get(length) )); } length = length * 10 + @byte - '0'; } }
public override State Transit(Stream stream) { while (true) { var @byte = stream.ReadByte(); if (@byte == -1) { return(this); } if (@byte == '\r') { return(Seek.Get(1)); } } }
public override State Transit(Stream stream) { var length = partiallyParsedLength; while (true) { var @byte = stream.ReadByte(); if (@byte == -1) { return(length == partiallyParsedLength ? this : new BulkString(length)); } if (@byte == '\r') { // \n content \r\n return(Seek.Get(length + Sizes.LF + Sizes.CRLF)); } length = length * 10 + @byte - '0'; } }