Flatbuffers:table bool 值设置为 byte 而不是 bool

Flatbuffers: table bool value set with byte instead of bool

My table,当为 go 编译时,最终使用 GetByte 和 PrependByteSlot 而不是 Bool 替代方案(GetBool、PrependBoolSlot)。

我能做些什么来改变它吗? 如果不是,我在哪里可以找到该字节等于 0 或 1 (false/true) 的确认信息?

这里有一个 table 显示了这个确切的行为:

table BooleanContent {
  value:bool = false;
}

这是生成的文件:

// Code generated by the FlatBuffers compiler. DO NOT EDIT.

package GatewayProtocol

import (
    flatbuffers "github.com/google/flatbuffers/go"
)

type BooleanContent struct {
    _tab flatbuffers.Table
}

func GetRootAsBooleanContent(buf []byte, offset flatbuffers.UOffsetT) *BooleanContent {
    n := flatbuffers.GetUOffsetT(buf[offset:])
    x := &BooleanContent{}
    x.Init(buf, n+offset)
    return x
}

func (rcv *BooleanContent) Init(buf []byte, i flatbuffers.UOffsetT) {
    rcv._tab.Bytes = buf
    rcv._tab.Pos = i
}

func (rcv *BooleanContent) Table() flatbuffers.Table {
    return rcv._tab
}

func (rcv *BooleanContent) Value() byte {
    o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
    if o != 0 {
        return rcv._tab.GetByte(o + rcv._tab.Pos)
    }
    return 0
}

func (rcv *BooleanContent) MutateValue(n byte) bool {
    return rcv._tab.MutateByteSlot(4, n)
}

func BooleanContentStart(builder *flatbuffers.Builder) {
    builder.StartObject(1)
}
func BooleanContentAddValue(builder *flatbuffers.Builder, value byte) {
    builder.PrependByteSlot(0, value, 0)
}
func BooleanContentEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
    return builder.EndObject()
}

布尔值当然以 FlatBuffers 二进制格式存储为字节,但没有理由不能像其他语言那样在访问时将其转换为布尔值。

所以这很可能是 Go 代码生成器中的一个错误,我会在 github 上提交一个问题,由 [Go] 标记。