-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add encoding/hex module #434
Conversation
@axetroy what's the status of this PR? Is it ready? |
encoding/hex.ts
Outdated
* DecodeString returns the bytes represented by the hexadecimal string `s`. | ||
* DecodeString expects that src contains only hexadecimal characters and that src has even length. | ||
* If the input is malformed, DecodeString will throws an error. | ||
* @param s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only need to add this if you are actually going to add a comment about the argument, otherwise I would just omit it as it adds nothing.
The merge the part of hex module first and the rest are waiting for other modules to be completed. So I think it is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool - looks good - just a few comments
encoding/hex.ts
Outdated
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | ||
// import { copyBytes } from "../io/util.ts"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove dead code
encoding/hex.ts
Outdated
// import { copyBytes } from "../io/util.ts"; | ||
|
||
const hextable = new TextEncoder().encode("0123456789abcdef"); | ||
// const bufferSize = 1024; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dead code
encoding/hex.ts
Outdated
|
||
/** | ||
* Encode encodes `src` into `encodedLen(src.length)` bytes of `dst`. | ||
* As a convenience, it returns the number of bytes written to `dst`, but this value is always `encodedLen(src.length)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap at 80 columns
for (let i = 0; i < src.length; i++) { | ||
const v = src[i]; | ||
dst[i * 2] = hextable[v >> 4]; | ||
dst[i * 2 + 1] = hextable[v & 0x0f]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this reading a Int16 ?
Consider using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
encoding/hex.ts
Outdated
|
||
// return n; | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove dead code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
ref: https://golang.org/pkg/encoding/hex , #431