This continas field descriptors for string types as defined by sql/field.h. In particular: Field (abstract) | ... | +--Field_str (abstract) | +--Field_longstr | | +--Field_string | | +--Field_varstring | | +--Field_blob | | +--Field_geom | | | +--Field_null | +--Field_enum | +--F
(metadata []byte)
| 29 | |
| 30 | // This is used for extracting type / length info from string field's metadata. |
| 31 | func parseTypeAndLength(metadata []byte) ( |
| 32 | fieldType mysql_proto.FieldType_Type, |
| 33 | length int, |
| 34 | remaining []byte, |
| 35 | err error) { |
| 36 | |
| 37 | if len(metadata) < 2 { |
| 38 | return mysql_proto.FieldType_STRING, 0, nil, errors.New( |
| 39 | "not enough metadata bytes") |
| 40 | } |
| 41 | |
| 42 | byte1 := int(metadata[0]) |
| 43 | byte2 := int(metadata[1]) |
| 44 | |
| 45 | var realType mysql_proto.FieldType_Type |
| 46 | if (byte1 & 0x30) != 0x30 { // see mysql issue #37426 |
| 47 | realType = mysql_proto.FieldType_Type(byte1 | 0x30) |
| 48 | length = byte2 | (((byte1 & 0x30) ^ 0x30) << 4) |
| 49 | } else { |
| 50 | realType = mysql_proto.FieldType_Type(byte1) |
| 51 | length = byte2 |
| 52 | } |
| 53 | |
| 54 | if realType != mysql_proto.FieldType_SET && |
| 55 | realType != mysql_proto.FieldType_ENUM && |
| 56 | realType != mysql_proto.FieldType_STRING && |
| 57 | realType != mysql_proto.FieldType_VAR_STRING { |
| 58 | |
| 59 | return mysql_proto.FieldType_STRING, 0, nil, errors.Newf( |
| 60 | "Invalid real type: %s (%d)", |
| 61 | realType.String(), |
| 62 | realType) |
| 63 | } |
| 64 | |
| 65 | return realType, length, metadata[2:], nil |
| 66 | } |
| 67 | |
| 68 | // This returns a field descriptor for FieldType_NULL (i.e., Field_null) |
| 69 | func NewNullFieldDescriptor(nullable NullableColumn) FieldDescriptor { |