MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / read

Method read

include/jsoncons/source.hpp:342–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340 }
341
342 std::size_t read(value_type* p, std::size_t length)
343 {
344 std::size_t len = 0;
345 if (length_ > 0)
346 {
347 len = (std::min)(length_, length);
348 std::memcpy(p, data_, len*sizeof(value_type));
349 data_ += len;
350 length_ -= len;
351 position_ += len;
352 }
353 if (length - len == 0)
354 {
355 return len;
356 }
357 else if (length - len < buffer_size_)
358 {
359 fill_buffer();
360 if (length_ > 0)
361 {
362 std::size_t len2 = (std::min)(length_, length-len);
363 std::memcpy(p+len, data_, len2*sizeof(value_type));
364 data_ += len2;
365 length_ -= len2;
366 position_ += len2;
367 len += len2;
368 }
369 return len;
370 }
371 else
372 {
373 if (stream_ptr_->eof())
374 {
375 length_ = 0;
376 return 0;
377 }
378 JSONCONS_TRY
379 {
380 std::streamsize count = sbuf_->sgetn(reinterpret_cast<char_type*>(p+len), length-len);
381 std::size_t len2 = static_cast<std::size_t>(count);
382 if (len2 < length-len)
383 {
384 stream_ptr_->clear(stream_ptr_->rdstate() | std::ios::eofbit);
385 }
386 len += len2;
387 position_ += len2;
388 return len;
389 }
390 JSONCONS_CATCH(const std::exception&)
391 {
392 stream_ptr_->clear(stream_ptr_->rdstate() | std::ios::badbit | std::ios::eofbit);
393 return 0;
394 }
395 }
396 }
397 private:
398 void fill_buffer()

Callers

nothing calls this directly

Calls 3

fill_bufferFunction · 0.85
eofMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected