func DeaggregateRecords(records []*types.Record) ([]*types.Record, error) {
	var isAggregated bool
	allRecords := make([]*types.Record, 0)
	for _, record := range records {
		isAggregated = true
		var dataMagic string
		var decodedDataNoMagic []byte
		if len(record.Data) >= KplMagicLen {
			dataMagic = fmt.Sprintf("%q", record.Data[:KplMagicLen])
			decodedDataNoMagic = record.Data[KplMagicLen:]
		} else {
			isAggregated = false
		}
		if KplMagicHeader != dataMagic || len(decodedDataNoMagic) <= DigestSize {
			isAggregated = false
		}
		if isAggregated {
			messageDigest := fmt.Sprintf("%x", decodedDataNoMagic[len(decodedDataNoMagic)-DigestSize:])
			messageData := decodedDataNoMagic[:len(decodedDataNoMagic)-DigestSize]
			calculatedDigest := fmt.Sprintf("%x", md5.Sum(messageData))
			if messageDigest != calculatedDigest {
				isAggregated = false
			} else {
				aggRecord := &rec.AggregatedRecord{}
				err := proto.Unmarshal(messageData, aggRecord)
				if err != nil {
					return nil, err
				}
				partitionKeys := aggRecord.PartitionKeyTable
				for _, aggrec := range aggRecord.Records {
					newRecord := createUserRecord(partitionKeys, aggrec, record)
					allRecords = append(allRecords, newRecord)
				}
			}
		}
		if !isAggregated {
			allRecords = append(allRecords, record)
		}
	}
	return allRecords, nil
}
DeaggregateRecords takes an array of Kinesis records and expands any Protobuf
records within that array, returning an array of all records
package deaggregator
import (
	"crypto/md5"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/kinesis/types"
	"github.com/golang/protobuf/proto"
	rec "github.com/awslabs/kinesis-aggregation/go/records"
)
var KplMagicHeader = fmt.Sprintf("%q", []byte("\xf3\x89\x9a\xc2"))
const (
	KplMagicLen = 4   
	DigestSize  = 16  
)