Skip to content
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

codec: simplify json codec. #3524

Merged
merged 3 commits into from
Jun 23, 2017
Merged

codec: simplify json codec. #3524

merged 3 commits into from
Jun 23, 2017

Conversation

hicqu
Copy link
Contributor

@hicqu hicqu commented Jun 21, 2017

No description provided.

@hicqu hicqu requested review from andelf, AndreMouche and hhkbp2 June 21, 2017 10:06
@hicqu hicqu requested a review from coocood June 22, 2017 04:02
@hanfei1991
Copy link
Member

LGTM

@hanfei1991 hanfei1991 added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 22, 2017
return
}
}
err = errors.New("Invalid JSON bytes")
Copy link
Contributor

@hhkbp2 hhkbp2 Jun 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to return different error message for 1. len(b) == 0, 2. b[0] is invalid ?

@@ -54,15 +54,16 @@ func (s *testJSONSuite) TestSerializeAndDeserialize(c *C) {
j2 := mustParseFromString(`[{"a": 1, "b": true}, 3, 3.5, "hello, world", null, true]`)

var testcses = []struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/testcses/testcases

// PeekBytesAsJSON trys to peek some bytes from b, until
// we can deserialize a JSON from those bytes.
func PeekBytesAsJSON(b []byte) (n int, err error) {
if len(b) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use len(b) <= 0 better?
thus avoiding the indentation

@@ -93,6 +93,43 @@ import (
// lengths up to 16383, and so on...
*/

const (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments for these constants.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant 4 is used somewhere else in this file, we could use a const variable for all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

// we can deserialize a JSON from those bytes.
func PeekBytesAsJSON(b []byte) (n int, err error) {
if len(b) > 0 {
switch c := b[0]; c {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TypeCode(b[0]) available?
If so, may be more readable.

@hhkbp2
Copy link
Contributor

hhkbp2 commented Jun 23, 2017

Rest LGTM

@XuHuaiyu
Copy link
Contributor

LGTM

@@ -97,34 +97,39 @@ const (
typeCodeLen int = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment for these constant?

@hicqu hicqu merged commit b9088c2 into master Jun 23, 2017
@ngaut ngaut deleted the qupeng/json-codec-improve branch October 2, 2017 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants