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

Feat/decode simple java class and base data type #18

Conversation

ChangedenCZD
Copy link

What type of PR is this?

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

Copy link
Collaborator

@jasondeng1997 jasondeng1997 left a comment

Choose a reason for hiding this comment

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

LGTM

@jasondeng1997
Copy link
Collaborator

pls fix the ci

@bytedance-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ChangedenCZD, jasondeng1997

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jasondeng1997
Copy link
Collaborator

pls fix the ci

@YangruiEmma
Copy link
Contributor

run gofumpt -l -extra -w . local


- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the -race flag

@@ -1,23 +0,0 @@
name: Action Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deleting action.yml and main.yml?

@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v3

- name: Check License Header
uses: apache/skywalking-eyes/header@main
Copy link
Contributor

Choose a reason for hiding this comment

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

why changing to the v0.4.0?

typos.toml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Why renaming this file? Better keep the files generated from the template (cloudwego/.github) as is.

decoder.go Outdated
)

const (
ReadSize = 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Please add comments for all exported symbols.
  2. It seems this constant could be a non-exported symbol.

case tag == BC_FALSE:
return false

// direct integer
Copy link
Contributor

@felix021 felix021 Jun 7, 2023

Choose a reason for hiding this comment

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

看起来这块的实现和 readInt、readDouble 里都有大量的重复,建议这样重构一下:

  1. readField() 方法先读取 tag,然后解析该字段的值
  2. read<Type>() 调用 readField() 然后再分发处理

例如:

func (d *Decoder) readField() (tp fieldType, value interface{}) {
  tag = d.readTag()
  switch (tag) {
    case BC_TRUE:
      return TYPE_BOOL, d.parseBool()
    case BC_DATE:
      return TYPE_DATE, d.parseLong()
    // all the rest tag cases
  }
}

func (d *Decoder) readBool() bool {
  tp, value := d.readField()
  switch(tp) {
    case BC_BOOL:
      return value.(bool)
    // deal with other types
      ...
  }
}

Copy link
Contributor

@felix021 felix021 Jun 7, 2023

Choose a reason for hiding this comment

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

我看到后面有 readObject(),和我前面说的 readField() 类似,但考虑到不同的 hessian2 类型可能会返回相同的基础数据类型(例如 UTCDate 也返回 int64),readField除了返回value,还应该返回一个 hessian 类型

return d.read() != 0

// INT_BYTE != 0
case (tag >= BYTE_INT && tag <= BYTE_INT_MAX) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

对于 readBool 函数,为什么要把其他类型也当成 bool 来处理呢?有具体的场景需求吗

if tag == BC_DATE {
return d.parseLong()
} else if tag == BC_DATE_MINUTE {
return int64(d.parseInt())
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. 这里是不是应该 * 60 * 1000 ? 否则调用者可能无法区分单位是 ms 还是 minute 。
  2. 返回类型为什么不是 time.Time? (和注释不一致)

@jasondeng1997
Copy link
Collaborator

I will rewrite this part of the code

decoder.go Outdated
case tag >= DIRECT_INT && tag <= DIRECT_INT_MAX:
return int(tag) - BC_INT_ZERO

/* byte int */

Choose a reason for hiding this comment

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

Is there any difference between the comment with // and one with /**/?

case tag >= SHORT_INT && tag <= SHORT_INT_LIMIT_MAX:
return ((int(tag) - BC_INT_SHORT_ZERO) << 16) + 256*int(d.read()) + int(d.read())

case tag == BC_INT || tag == BC_LONG_INT:

Choose a reason for hiding this comment

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

Why sometimes there's no comment? Maybe you can unify the style for readability.

@jasondeng1997
Copy link
Collaborator

close this pr

@felix021
Copy link
Contributor

We've proposed to implement the encoder/decoder in a more efficient way in #28.

@felix021 felix021 closed this Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants