in frame.go [1701:1798]
func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload map[string][]byte) error {
if len(customPayload) > 0 {
f.payload()
}
f.writeHeader(f.flags, opBatch, streamID)
f.writeCustomPayload(&customPayload)
f.writeByte(byte(w.typ))
n := len(w.statements)
f.writeShort(uint16(n))
var flags uint32
for i := 0; i < n; i++ {
b := &w.statements[i]
if len(b.preparedID) == 0 {
f.writeByte(0)
f.writeLongString(b.statement)
} else {
f.writeByte(1)
f.writeShortBytes(b.preparedID)
}
f.writeShort(uint16(len(b.values)))
for j := range b.values {
col := b.values[j]
if f.proto > protoVersion2 && col.name != "" {
// TODO: move this check into the caller and set a flag on writeBatchFrame
// to indicate using named values
if f.proto <= protoVersion5 {
return fmt.Errorf("gocql: named query values are not supported in batches, please see https://issues.apache.org/jira/browse/CASSANDRA-10246")
}
flags |= flagWithNameValues
f.writeString(col.name)
}
if col.isUnset {
f.writeUnset()
} else {
f.writeBytes(col.value)
}
}
}
f.writeConsistency(w.consistency)
if f.proto > protoVersion2 {
if w.serialConsistency > 0 {
flags |= flagWithSerialConsistency
}
if w.defaultTimestamp {
flags |= flagDefaultTimestamp
}
}
if w.keyspace != "" {
if f.proto < protoVersion5 {
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
}
flags |= flagWithKeyspace
}
if w.nowInSeconds != nil {
if f.proto < protoVersion5 {
panic(fmt.Errorf("now_in_seconds can only be set with protocol 5 or higher"))
}
flags |= flagWithNowInSeconds
}
if f.proto > protoVersion4 {
f.writeUint(flags)
} else {
f.writeByte(byte(flags))
}
if w.serialConsistency > 0 {
f.writeConsistency(Consistency(w.serialConsistency))
}
if w.defaultTimestamp {
var ts int64
if w.defaultTimestampValue != 0 {
ts = w.defaultTimestampValue
} else {
ts = time.Now().UnixNano() / 1000
}
f.writeLong(ts)
}
if w.keyspace != "" {
f.writeString(w.keyspace)
}
if w.nowInSeconds != nil {
f.writeInt(int32(*w.nowInSeconds))
}
return f.finish()
}