func()

in datahub/binaryrecord.go [113:151]


func (bRecord *binaryRecord) parseAttributesIfNeed() error {
	if !bRecord.parsedAttr {
		if bRecord.header == nil {
			bRecord.header = &binaryRecordHeader{
				encodeType:    0,
				schemaVersion: int32(bRecord.schemaVersion),
				totalSize:     int32(bRecord.getRecordSize()),
				attrOffset:    int32(bRecord.nextOffset),
			}
		}

		offset := bRecord.header.attrOffset
		attrSize := binary.LittleEndian.Uint32(bRecord.data[offset:])
		if attrSize != 0 && bRecord.attributes == nil {
			bRecord.attributes = make(map[string]string, attrSize)
		}

		if uint32(len(bRecord.data)) < attrSize {
			return fmt.Errorf("check data len failed")
		}

		offset = offset + 4
		for i := uint32(0); i < attrSize; i = i + 1 {
			keyLen := int32(binary.LittleEndian.Uint32(bRecord.data[offset:]))
			offset = offset + 4
			key := string(bRecord.data[offset : offset+keyLen])
			offset = offset + keyLen

			valueLen := int32(binary.LittleEndian.Uint32(bRecord.data[offset:]))
			offset = offset + 4
			value := string(bRecord.data[offset : offset+valueLen])

			bRecord.attributes[key] = value
			offset = offset + valueLen
		}
		bRecord.parsedAttr = true
	}
	return nil
}