-
Notifications
You must be signed in to change notification settings - Fork 6
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
WIP frame: added remaining request response #24
Conversation
Get rid of boilerplate docs i.e. // AuthChallenge response message type.
type AuthChallenge struct {
Token frame.Bytes
}
// ReadAuthChallenge reads and returns AuthChallenge from the buffer.
func ReadAuthChallenge(b *bytes.Buffer) AuthChallenge {
return AuthChallenge{frame.ReadBytes(b)}
} Should be // AuthChallenge spec https://github.com/apache/cassandra/blob/10c685222fc415586ae28a01e7896063a3f2f0d3/doc/native_protocol_v4.spec#L54.
type AuthChallenge struct {
Token frame.Bytes
}
func ReadAuthChallenge(b *bytes.Buffer) AuthChallenge {
return AuthChallenge{frame.ReadBytes(b)}
} Add this Read function to issues.exclude in golangci-lint file, it supports regular expressions. |
@@ -16,6 +16,16 @@ type ( | |||
StringMap = map[string]string | |||
StringList = []string | |||
|
|||
Value struct { |
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.
It is a bit exaggerated. I'd suggest moving Value, Inet and OpCode to separate type declarations outside of this group.
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.
What is the purpose of Value type?? I looks like it should be just Bytes.
It would me much better to call those functions with |
The code must NOT panic. I suggest we add a buffer wrapper that would be capable of recording errors. func ReadConsistency(b *bytes.Buffer) Short {
c := ReadShort(b)
if c > 10 {
panic(unknownConsistencyErr)
}
return c
} With type Buffer struct {
bytes.Buffer
errors []error
}
func (b *Buffer) RecordError(err error) The above becomes func ReadConsistency(b *Buffer) Short {
c := ReadShort(b)
if c > 10 {
b.RecordError(unknownConsistencyErr)
}
return c
} The ReadConsistency func is still wrong as validation should be handled by Consistency type. |
unknownConsistencyErr = errors.New("unknown consistency") | ||
unknownWriteTypeErr = errors.New("unknown write type") |
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.
s/Invalid
/Unsupported
/g
@@ -27,29 +27,75 @@ func WriteInt(i Int, b *bytes.Buffer) { | |||
}) | |||
} | |||
|
|||
// WriteLong writes single Long to the buffer. |
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.
s/single X
/a X value
/g
Get rid of banners
If you need sth like that most likely those should be put to a separate file. I'd suggest to benchmarks to xxx_bench_test.go and remove the "read write barriers"... |
// ReadValue reads and return Value from the buffer. | ||
// Length equal to -1 represents null. | ||
// Length equal to -2 represents not set. | ||
func ReadValue(b *bytes.Buffer) Value { |
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.
We must talk about it.
Each file shall have it's test file i.e.
should be
https://cs.opensource.google/go/go/+/refs/tags/go1.17.3:src/io/fs/ |
Do not use https://cs.opensource.google/go/go/+/refs/tags/go1.17.3:src/os/ So |
How come |
Let's break comments at 120 lines, no need to break them too early. |
Always use field names when instantiating a struct there should be a linter for that. |
After thinking about it error.go with public error shall be in response because it's about server responding with some errors. |
When in doubt READ then ASK. Linting errors are silenced with https://golangci-lint.run/usage/false-positives/ |
{"Should encode and decode", | ||
[]byte{0xca, 0xfe, 0xba, 0xbe}, | ||
[]byte{0xca, 0xfe, 0xba, 0xbe}, | ||
}, |
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.
Use field names.
Do not prefix test names with anything like here
vs
Shorter is better. |
Also test names can be sentences i.e. |
Please move the mass append tesing harness to |
Maybe it's not needed actually. Say we we have the Buffer wrapper as explained in #24 (comment). Then all the functions can become methods. Then this code
Can become
It could even become
|
I opened some issues please address them first.
|
No description provided.