JsonValueSerialize is the recursive serializer for JSON values.
(writer *utils.Writer, value JsonValue)
| 108 | |
| 109 | // JsonValueSerialize is the recursive serializer for JSON values. |
| 110 | func JsonValueSerialize(writer *utils.Writer, value JsonValue) { |
| 111 | switch value := value.(type) { |
| 112 | case JsonValueObject: |
| 113 | writer.Byte(byte(JsonValueType_Object)) |
| 114 | writer.VariableUint(uint64(len(value.Items))) |
| 115 | for _, item := range value.Items { |
| 116 | writer.String(item.Key) |
| 117 | JsonValueSerialize(writer, item.Value) |
| 118 | } |
| 119 | case JsonValueArray: |
| 120 | writer.Byte(byte(JsonValueType_Array)) |
| 121 | writer.VariableUint(uint64(len(value))) |
| 122 | for _, item := range value { |
| 123 | JsonValueSerialize(writer, item) |
| 124 | } |
| 125 | case JsonValueString: |
| 126 | writer.Byte(byte(JsonValueType_String)) |
| 127 | writer.String(string(value)) |
| 128 | case JsonValueNumber: |
| 129 | writer.Byte(byte(JsonValueType_Number)) |
| 130 | // MarshalBinary cannot error, so we can safely ignore it |
| 131 | v := apd.Decimal(value) |
| 132 | bytes, _ := Numeric.SerializationFunc(nil, Numeric, &v) |
| 133 | writer.ByteSlice(bytes) |
| 134 | case JsonValueBoolean: |
| 135 | writer.Byte(byte(JsonValueType_Boolean)) |
| 136 | writer.Bool(bool(value)) |
| 137 | case JsonValueNull: |
| 138 | writer.Byte(byte(JsonValueType_Null)) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // JsonValueDeserialize is the recursive deserializer for JSON values. |
| 143 | func JsonValueDeserialize(reader *utils.Reader) (_ JsonValue, err error) { |
no test coverage detected