Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseMessageWithDataDictionary has an unused arg. #550

Closed
hyunw55 opened this issue Mar 23, 2023 · 0 comments
Closed

ParseMessageWithDataDictionary has an unused arg. #550

hyunw55 opened this issue Mar 23, 2023 · 0 comments

Comments

@hyunw55
Copy link

hyunw55 commented Mar 23, 2023

applicationDataDictionary is received as arg, but it is not used inside the function.

this function is in message.go line 138

// ParseMessageWithDataDictionary constructs a Message from a byte slice wrapping a FIX message using an optional session and application DataDictionary for reference.
func ParseMessageWithDataDictionary(
	msg *Message,
	rawMessage *bytes.Buffer,
	transportDataDictionary *datadictionary.DataDictionary,
	applicationDataDictionary *datadictionary.DataDictionary,
) (err error) {
	msg.Header.Clear()
	msg.Body.Clear()
	msg.Trailer.Clear()
	msg.rawMessage = rawMessage

	rawBytes := rawMessage.Bytes()

	//allocate fields in one chunk
	fieldCount := 0
	for _, b := range rawBytes {
		if b == '\001' {
			fieldCount++
		}
	}

	if fieldCount == 0 {
		return parseError{OrigError: fmt.Sprintf("No Fields detected in %s", string(rawBytes))}
	}

	if cap(msg.fields) < fieldCount {
		msg.fields = make([]TagValue, fieldCount)
	} else {
		msg.fields = msg.fields[0:fieldCount]
	}

	fieldIndex := 0

	//message must start with begin string, body length, msg type
	if rawBytes, err = extractSpecificField(&msg.fields[fieldIndex], tagBeginString, rawBytes); err != nil {
		return
	}

	msg.Header.add(msg.fields[fieldIndex : fieldIndex+1])
	fieldIndex++

	parsedFieldBytes := &msg.fields[fieldIndex]
	if rawBytes, err = extractSpecificField(parsedFieldBytes, tagBodyLength, rawBytes); err != nil {
		return
	}

	msg.Header.add(msg.fields[fieldIndex : fieldIndex+1])
	fieldIndex++

	parsedFieldBytes = &msg.fields[fieldIndex]
	if rawBytes, err = extractSpecificField(parsedFieldBytes, tagMsgType, rawBytes); err != nil {
		return
	}

	msg.Header.add(msg.fields[fieldIndex : fieldIndex+1])
	fieldIndex++

	trailerBytes := []byte{}
	foundBody := false
	for {
		parsedFieldBytes = &msg.fields[fieldIndex]
		rawBytes, err = extractField(parsedFieldBytes, rawBytes)
		if err != nil {
			return
		}

		switch {
		case isHeaderField(parsedFieldBytes.tag, transportDataDictionary):
			msg.Header.add(msg.fields[fieldIndex : fieldIndex+1])
		case isTrailerField(parsedFieldBytes.tag, transportDataDictionary):
			msg.Trailer.add(msg.fields[fieldIndex : fieldIndex+1])
		default:
			foundBody = true
			trailerBytes = rawBytes
			msg.Body.add(msg.fields[fieldIndex : fieldIndex+1])
		}
		if parsedFieldBytes.tag == tagCheckSum {
			break
		}

		if !foundBody {
			msg.bodyBytes = rawBytes
		}

		fieldIndex++
	}

	//body length would only be larger than trailer if fields out of order
	if len(msg.bodyBytes) > len(trailerBytes) {
		msg.bodyBytes = msg.bodyBytes[:len(msg.bodyBytes)-len(trailerBytes)]
	}

	length := 0
	for _, field := range msg.fields {
		switch field.tag {
		case tagBeginString, tagBodyLength, tagCheckSum: //tags do not contribute to length
		default:
			length += field.length()
		}
	}

	bodyLength, err := msg.Header.GetInt(tagBodyLength)
	if err != nil {
		err = parseError{OrigError: err.Error()}
	} else if length != bodyLength {
		err = parseError{OrigError: fmt.Sprintf("Incorrect Message Length, expected %d, got %d", bodyLength, length)}
	}

	return

}
@hyunw55 hyunw55 changed the title applicationDataDictionary is received as arg, but it is not used inside the function. ParseMessageWithDataDictionary has an unused arg. Mar 23, 2023
@ackleymi ackleymi closed this as completed Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants