@@ -40,23 +40,31 @@ object SimpleValueOutput {
40
40
*
41
41
* @param consumer consumer of serialized value, which is guaranteed to meet the above rules
42
42
*/
43
- class SimpleValueOutput (consumer : Any => Unit ) extends Output {
43
+ class SimpleValueOutput (
44
+ consumer : Any => Unit ,
45
+ newObjectRepr : => mutable.Builder [(String , Any ), BMap [String , Any ]],
46
+ newListRepr : => mutable.Builder [Any , BSeq [Any ]]
47
+ ) extends Output {
48
+
49
+ def this (consumer : Any => Unit ) =
50
+ this (consumer, new MHashMap [String , Any ], new ListBuffer [Any ])
51
+
44
52
def writeBinary (binary : Array [Byte ]) = consumer(binary)
45
53
def writeString (str : String ) = consumer(str)
46
54
def writeDouble (double : Double ) = consumer(double)
47
55
def writeInt (int : Int ) = consumer(int)
48
56
49
57
def writeList () = new ListOutput {
50
- private val buffer = new ListBuffer [ Any ]
51
- def writeElement () = new SimpleValueOutput (buffer += _)
58
+ private val buffer = newListRepr
59
+ def writeElement () = new SimpleValueOutput (buffer += _, newObjectRepr, newListRepr )
52
60
def finish () = consumer(buffer.result())
53
61
}
54
62
55
63
def writeBoolean (boolean : Boolean ) = consumer(boolean)
56
64
57
65
def writeObject () = new ObjectOutput {
58
- private val result = new mutable. HashMap [ String , Any ]
59
- def writeField (key : String ) = new SimpleValueOutput (v => result += ((key, v)))
66
+ private val result = newObjectRepr
67
+ def writeField (key : String ) = new SimpleValueOutput (v => result += ((key, v)), newObjectRepr, newListRepr )
60
68
def finish () = consumer(result)
61
69
}
62
70
@@ -85,8 +93,8 @@ class SimpleValueInput(value: Any) extends Input {
85
93
86
94
def inputType = value match {
87
95
case null => InputType .Null
88
- case _ : List [Any ] => InputType .List
89
- case _ : Map [_, Any ] => InputType .Object
96
+ case _ : BSeq [Any ] => InputType .List
97
+ case _ : BMap [_, Any ] => InputType .Object
90
98
case _ => InputType .Simple
91
99
}
92
100
@@ -120,4 +128,5 @@ class SimpleValueInput(value: Any) extends Input {
120
128
def skip () = ()
121
129
}
122
130
123
- class SimpleValueFieldInput (val fieldName : String , value : Any ) extends SimpleValueInput (value) with FieldInput
131
+ class SimpleValueFieldInput (val fieldName : String , value : Any )
132
+ extends SimpleValueInput (value) with FieldInput
0 commit comments