mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-24 03:16:12 -05:00
Merge remote-tracking branch 'origin/main' into andy/merge-artifacts
This commit is contained in:
@@ -15,7 +15,10 @@
|
||||
package serial
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"unsafe"
|
||||
|
||||
fb "github.com/google/flatbuffers/go"
|
||||
)
|
||||
|
||||
// KEEP THESE IN SYNC WITH .fbs FILES!
|
||||
@@ -33,11 +36,44 @@ const TableSchemaFileID = "DSCH"
|
||||
const ForeignKeyCollectionFileID = "DFKC"
|
||||
const MergeArtifactsFileID = "ARTM"
|
||||
|
||||
const MessageTypesKind int = 27
|
||||
|
||||
const MessagePrefixSz = 4
|
||||
|
||||
type Message []byte
|
||||
|
||||
func GetFileID(bs []byte) string {
|
||||
if len(bs) < 8 {
|
||||
if len(bs) < 8+MessagePrefixSz {
|
||||
return ""
|
||||
}
|
||||
return byteSliceToString(bs[4:8])
|
||||
return byteSliceToString(bs[MessagePrefixSz+4 : MessagePrefixSz+8])
|
||||
}
|
||||
|
||||
func FinishMessage(b *fb.Builder, off fb.UOffsetT, fileID []byte) Message {
|
||||
// We finish the buffer by prefixing it with:
|
||||
// 1) 1 byte NomsKind == SerialMessage.
|
||||
// 2) big endian 3 byte uint representing the size of the message, not
|
||||
// including the kind or size prefix bytes.
|
||||
//
|
||||
// This allows chunks we serialize here to be read by types binary
|
||||
// codec.
|
||||
//
|
||||
// All accessors in this package expect this prefix to be on the front
|
||||
// of the message bytes as well. See |MessagePrefixSz|.
|
||||
|
||||
b.Prep(1, fb.SizeInt32+4+MessagePrefixSz)
|
||||
b.FinishWithFileIdentifier(off, fileID)
|
||||
|
||||
var size [4]byte
|
||||
binary.BigEndian.PutUint32(size[:], uint32(len(b.Bytes)-int(b.Head())))
|
||||
if size[0] != 0 {
|
||||
panic("message is too large to be encoded")
|
||||
}
|
||||
|
||||
bytes := b.Bytes[b.Head()-MessagePrefixSz:]
|
||||
bytes[0] = byte(MessageTypesKind)
|
||||
copy(bytes[1:], size[1:])
|
||||
return bytes
|
||||
}
|
||||
|
||||
// byteSliceToString converts a []byte to string without a heap allocation.
|
||||
|
||||
@@ -22,7 +22,6 @@ table RootValue {
|
||||
tables:[ubyte]; // Serialized AddressMap.
|
||||
|
||||
foreign_key_addr:[ubyte];
|
||||
super_schemas_addr:[ubyte];
|
||||
}
|
||||
|
||||
// KEEP THIS IN SYNC WITH fileidentifiers.go
|
||||
|
||||
Reference in New Issue
Block a user