// newBitReader returns a new bitReader reading from r. If r is not // already an io.ByteReader, it will be converted via a bufio.Reader. private static bitReader newBitReader(io.Reader r) { io.ByteReader(byter, ok) = r._ <io.ByteReader>(); if (!ok) { byter = bufio.NewReader(r); } return(new bitReader(r: byter)); }
// NewChunkedReader returns a new chunkedReader that translates the data read from r // out of HTTP "chunked" format before returning it. // The chunkedReader returns io.EOF when the final 0-length chunk is read. // // NewChunkedReader is not needed by normal applications. The http package // automatically decodes chunking when reading response bodies. public static io.Reader NewChunkedReader(io.Reader r) { ptr <bufio.Reader> (br, ok) = r._ <ptr <bufio.Reader> >(); if (!ok) { br = bufio.NewReader(r); } return(addr(new chunkedReader(r: br))); }
// NewReaderSize returns a new Reader whose buffer has at least the specified // size. If the argument io.Reader is already a Reader with large enough // size, it returns the underlying Reader. // NewReaderSize returns a new Reader whose buffer has at least the specified // size. If the argument io.Reader is already a Reader with large enough // size, it returns the underlying Reader. public static ptr <Reader> NewReaderSize(io.Reader rd, long size) { // Is it already a Reader? ptr <Reader> (b, ok) = rd._ <ptr <Reader> >(); if (ok && len(b.buf) >= size) { return(_addr_b !); } if (size < minReadBufferSize) { size = minReadBufferSize; } ptr <Reader> r = @new <Reader>(); r.reset(make_slice <byte>(size), rd); return(_addr_r !); }
// NewDecoder returns a new decoder that reads from the io.Reader. // If r does not also implement io.ByteReader, it will be wrapped in a // bufio.Reader. public static ptr <Decoder> NewDecoder(io.Reader r) { ptr <Decoder> dec = @new <Decoder>(); // We use the ability to read bytes as a plausible surrogate for buffering. { io.ByteReader(_, ok) = r._ <io.ByteReader>(); if (!ok) { r = bufio.NewReader(r); } } dec.r = r; dec.wireType = make_map <typeId, ptr <wireType> >(); dec.decoderCache = make_map <reflect.Type, map <typeId, ptr <ptr <decEngine> > > >(); dec.ignorerCache = make_map <typeId, ptr <ptr <decEngine> > >(); dec.countBuf = make_slice <byte>(9L); // counts may be uint64s (unlikely!), require 9 bytes return(_addr_dec !); }