encodeJsonDoc encodes the specified |jsonDoc| into MySQL's custom/internal binary encoding so that it can be included in a binlog event. The internal MySQL JSON binary format is documented here: https://dev.mysql.com/doc/dev/mysql-server/latest/json__binary_8h.html And a third-party description is
(jsonDoc sql.JSONWrapper)
| 55 | // |
| 56 | // And a third-party description is here: |
| 57 | // https://lafengnan.gitbooks.io/blog/content/mysql/chapter2.html |
| 58 | func encodeJsonDoc(ctx context.Context, jsonDoc sql.JSONWrapper) (buffer []byte, err error) { |
| 59 | val, err := jsonDoc.ToInterface(ctx) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | typeId, encodedValue, err := encodeJsonValue(val) |
| 64 | if err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | buffer = append(buffer, typeId) |
| 68 | return append(buffer, encodedValue...), nil |
| 69 | } |
| 70 | |
| 71 | // encodeJsonArray encodes the specified |jsonArray| into MySQL's internal JSON encoding and returns |