-
Notifications
You must be signed in to change notification settings - Fork 3
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: Support encoding/emitting nested structures with binary fields #1
base: main
Are you sure you want to change the base?
Changes from all commits
4597211
111a35d
005578a
379e950
b80f54d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,9 +53,9 @@ func _encodeData(data any) any { | |
newData[k] = _encodeData(v) | ||
} | ||
return newData | ||
default: | ||
return data | ||
} | ||
|
||
return data | ||
} | ||
|
||
// Encode packet as string. | ||
|
@@ -79,8 +79,13 @@ func (e *encoder) encodeAsString(packet *Packet) types.BufferInterface { | |
} | ||
// json data | ||
if nil != packet.Data { | ||
if b, err := json.Marshal(_encodeData(packet.Data)); err == nil { | ||
str.Write(b) | ||
if packet.preSerializedData != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to run more test cases to ensure that this request is OK. It may take longer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no rush. I've already taken the encoder from this branch and I'm using it in my project that way via the config.Encoder. |
||
// Already serialized in the DeconstructPacket function | ||
str.WriteString(packet.preSerializedData) | ||
} else { | ||
if b, err := json.Marshal(_encodeData(packet.Data)); err == nil { | ||
str.Write(b) | ||
} | ||
} | ||
} | ||
parser_log.Debug("encoded %v as %v", packet, str) | ||
|
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.
The last update to the standard library was two years ago, and it seems to be out of maintenance.
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.
Yeah, I don't love this fact, but it was the only high-performance json library I could find that supported passing context through each individual serialization versus having to do some horrible thing with finding pointers to all arrays in a first pass, storing them in a global lookup, and then using that to back-calculate the "current stream" from inside the custom marshal functions. It's well-regarded across the internet though, has 13k stars, etc., so I'm not that worried, but your call about how worried you are about this.
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.
For a rapidly developing network, stopping updates means many security risks.