Skip to content

Commit

Permalink
hud: remove EmitDefault from all json serializers (#4530)
Browse files Browse the repository at this point in the history
I think this is a holdover from the pre-typescript days
when we weren't able to remove props safely.
  • Loading branch information
nicks committed May 7, 2021
1 parent acdf0f5 commit 4121744
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/cloud/snapshot_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s snapshotUploader) TakeAndUpload(state store.EngineState) (SnapshotID, er

func (s snapshotUploader) Upload(token token.Token, teamID string, snapshot *proto_webview.Snapshot) (SnapshotID, error) {
b := &bytes.Buffer{}
jsEncoder := &runtime.JSONPb{OrigName: false, EmitDefaults: true}
jsEncoder := &runtime.JSONPb{}
err := jsEncoder.NewEncoder(b).Encode(snapshot)
if err != nil {
return "", errors.Wrap(err, "encoding snapshot")
Expand Down
2 changes: 1 addition & 1 deletion internal/hud/server/logs_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newWebsocketReaderForLogs(conn WebsocketConn, persistent bool, resources []
func newWebsocketReader(conn WebsocketConn, persistent bool, handler ViewHandler) *WebsocketReader {
return &WebsocketReader{
conn: conn,
marshaller: jsonpb.Marshaler{OrigName: false, EmitDefaults: true},
marshaller: jsonpb.Marshaler{},
unmarshaller: jsonpb.Unmarshaler{},
persistent: persistent,
handler: handler,
Expand Down
4 changes: 2 additions & 2 deletions internal/hud/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *HeadsUpServer) ViewJSON(w http.ResponseWriter, req *http.Request) {
return
}

jsEncoder := &runtime.JSONPb{OrigName: false, EmitDefaults: true}
jsEncoder := &runtime.JSONPb{}

w.Header().Set("Content-Type", "application/json")
err = jsEncoder.NewEncoder(w).Encode(view)
Expand Down Expand Up @@ -347,7 +347,7 @@ func (s *HeadsUpServer) HandleNewSnapshot(w http.ResponseWriter, req *http.Reque
return
}

jspb := &runtime.JSONPb{OrigName: false, EmitDefaults: true}
jspb := &runtime.JSONPb{}
decoder := jspb.NewDecoder(bytes.NewBuffer(b))
var snapshot *proto_webview.Snapshot

Expand Down
2 changes: 1 addition & 1 deletion internal/hud/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestHandleNewSnapshot(t *testing.T) {
lastReq := f.snapshotHTTP.lastReq
if assert.NotNil(t, lastReq) {
var snapshot proto_webview.Snapshot
jspb := &grpcRuntime.JSONPb{OrigName: false, EmitDefaults: true}
jspb := &grpcRuntime.JSONPb{}
decoder := jspb.NewDecoder(lastReq.Body)
err := decoder.Decode(&snapshot)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions internal/hud/server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (ws *WebsocketSubscriber) OnChange(ctx context.Context, s store.RStore, _ s
s.Dispatch(store.AnalyticsNudgeSurfacedAction{})
}

jsEncoder := &runtime.JSONPb{OrigName: false, EmitDefaults: true}
jsEncoder := &runtime.JSONPb{}
w, err := ws.conn.NextWriter(websocket.TextMessage)
if err != nil {
logger.Get(ctx).Verbosef("getting writer: %v", err)
Expand All @@ -172,9 +172,9 @@ func (ws *WebsocketSubscriber) OnChange(ctx context.Context, s store.RStore, _ s
// at this point in the code, we're not) the only thing ws.OnChange blocks
// is subsequent ws.OnChange calls.
//
// In future, we can maybe solve this problem more elegantly by replacing our JSON
// marshaling with jsoniter (would require either working around the lack of an
// `EmitDefaults` option in jsoniter, or writing our own proto marshaling code).
// In future, we can maybe solve this problem more elegantly by replacing our
// JSON marshaling with jsoniter (though changing json marshalers is
// always fraught with peril).
time.Sleep(time.Millisecond * 100)
}

Expand Down

0 comments on commit 4121744

Please sign in to comment.