Skip to content

Commit 668e8fa

Browse files
laurenzfgfacebook-github-bot
authored andcommitted
Add Factories for JSON+SimpleJSON Serializers
Summary: Thrift structs don't neccessarirly always stay within RPC. Programs might be interested in outputting them to a user / saving them to a DB. Here, JSON (DB) SimpleJSON (User) serialization formats may be useful. This Diff adds factories for both serialization formats. Reviewed By: lcpoletto, doranand Differential Revision: D38783343 fbshipit-source-id: cdb635dac21ddb954b09ece28bc1296476a5c862
1 parent b3369c1 commit 668e8fa

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

thrift/lib/go/thrift/serializer.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,6 +61,22 @@ func NewCompactSerializer() *Serializer {
6161
return &Serializer{transport, protocol}
6262
}
6363

64+
// NewJSONSerializer creates a new serializer using the JSON protocol
65+
func NewJSONSerializer() *Serializer {
66+
transport := NewMemoryBufferLen(1024)
67+
protocol := NewJSONProtocolFactory().GetProtocol(transport)
68+
69+
return &Serializer{transport, protocol}
70+
}
71+
72+
// NewSimpleJSONSerializer creates a new serializer using the SimpleJSON protocol
73+
func NewSimpleJSONSerializer() *Serializer {
74+
transport := NewMemoryBufferLen(1024)
75+
protocol := NewSimpleJSONProtocolFactory().GetProtocol(transport)
76+
77+
return &Serializer{transport, protocol}
78+
}
79+
6480
// WriteString writes msg to the serializer and returns it as a string
6581
func (s *Serializer) WriteString(msg Struct) (str string, err error) {
6682
s.Transport.Reset()

0 commit comments

Comments
 (0)