Code Monkey home page Code Monkey logo

Comments (3)

swankjesse avatar swankjesse commented on May 11, 2024

Existing APIs:

  long readLong();
  long readLongLe();
  String readUtf8(long byteCount);
  Buffer writeLong(long v);
  Buffer writeLongLe(long v);
  Buffer writeUtf8(String string);

We care about a few things:

  • Primitive type. byte, short, int, long. I think we can get away with long only, especially since as I understand it, we'll be using that much memory anyway on 64-bit CPUs.
  • Radix. I think we should do decimal and hexadecimal only. Other radixes aren't common enough to justify being on the fast path, and that way we can put the words decimal and hexadecimal right in the API, instead of using 10 and 16, which read like lengths instead of radixes.
  • Signed vs. Unsigned. I claim that for decimal we start with signed (only), and for hexadecimal we start with unsigned (only). This is particularly important when writing: what should -1L emit? I think for decimal we want "-1" and for hex we want "ffffffffffffffff". Signed hexadecimal is particularly weird and I don't think we need it, at least not in the beginning.

That leaves us with four new methods:

  long readDecimalLong();
  long readHexadecimalUnsignedLong();
  Buffer writeDecimalLong(long value);
  Buffer writeHexadecimalUnsignedLong(long value);

I admit that the method names are wordy! But it gives us the runway should we go mad and later add readDecimalUnsignedLong or readHexadecimalLong.

from okio.

JakeWharton avatar JakeWharton commented on May 11, 2024

How does readDecimalLong know when to stop?

from okio.

swankjesse avatar swankjesse commented on May 11, 2024

We keep reading till we see something not in 0..9, or exhaust the stream.

from okio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.