| 154 | } |
| 155 | |
| 156 | func (bj BinaryJSON) marshalTo(buf []byte) ([]byte, error) { |
| 157 | switch bj.TypeCode { |
| 158 | case JSONTypeCodeOpaque: |
| 159 | return jsonMarshalOpaqueTo(buf, bj.GetOpaque()), nil |
| 160 | case JSONTypeCodeString: |
| 161 | return jsonMarshalStringTo(buf, bj.GetString()), nil |
| 162 | case JSONTypeCodeLiteral: |
| 163 | return jsonMarshalLiteralTo(buf, bj.Value[0]), nil |
| 164 | case JSONTypeCodeInt64: |
| 165 | return strconv.AppendInt(buf, bj.GetInt64(), 10), nil |
| 166 | case JSONTypeCodeUint64: |
| 167 | return strconv.AppendUint(buf, bj.GetUint64(), 10), nil |
| 168 | case JSONTypeCodeFloat64: |
| 169 | return bj.marshalFloat64To(buf) |
| 170 | case JSONTypeCodeArray: |
| 171 | return bj.marshalArrayTo(buf) |
| 172 | case JSONTypeCodeObject: |
| 173 | return bj.marshalObjTo(buf) |
| 174 | case JSONTypeCodeDate, JSONTypeCodeDatetime, JSONTypeCodeTimestamp: |
| 175 | return jsonMarshalTimeTo(buf, bj.GetTime()), nil |
| 176 | case JSONTypeCodeDuration: |
| 177 | return jsonMarshalDurationTo(buf, bj.GetDuration()), nil |
| 178 | } |
| 179 | return buf, nil |
| 180 | } |
| 181 | |
| 182 | // IsZero return a boolean indicate whether BinaryJSON is Zero |
| 183 | func (bj BinaryJSON) IsZero() bool { |