|
|
|
@ -268,62 +268,66 @@ func (f *Frame) Text() string {
|
|
|
|
|
return util.DecodeText(f.Contents) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func v23FlagsToBytes(v23f FrameFlags) []byte { |
|
|
|
|
var flags = []byte{0, 0} |
|
|
|
|
func frameFlagsToBytes(ff FrameFlags, version string) []byte { |
|
|
|
|
var flagBytes = []byte{0, 0} |
|
|
|
|
|
|
|
|
|
if v23f.TagAlterPreservation { |
|
|
|
|
flags[0] = util.SetBit(flags[0], 8) |
|
|
|
|
} |
|
|
|
|
if v23f.FileAlterPreservation { |
|
|
|
|
flags[0] = util.SetBit(flags[0], 7) |
|
|
|
|
} |
|
|
|
|
if v23f.ReadOnly { |
|
|
|
|
flags[0] = util.SetBit(flags[0], 6) |
|
|
|
|
} |
|
|
|
|
switch version { |
|
|
|
|
case V2_2: |
|
|
|
|
return nil |
|
|
|
|
|
|
|
|
|
if v23f.Compressed { |
|
|
|
|
flags[1] = util.SetBit(flags[1], 8) |
|
|
|
|
} |
|
|
|
|
if v23f.Encrypted { |
|
|
|
|
flags[1] = util.SetBit(flags[1], 7) |
|
|
|
|
} |
|
|
|
|
if v23f.InGroup { |
|
|
|
|
flags[1] = util.SetBit(flags[1], 6) |
|
|
|
|
} |
|
|
|
|
case V2_3: |
|
|
|
|
if ff.TagAlterPreservation { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 8) |
|
|
|
|
} |
|
|
|
|
if ff.FileAlterPreservation { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 7) |
|
|
|
|
} |
|
|
|
|
if ff.ReadOnly { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 6) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return flags |
|
|
|
|
} |
|
|
|
|
if ff.Compressed { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 8) |
|
|
|
|
} |
|
|
|
|
if ff.Encrypted { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 7) |
|
|
|
|
} |
|
|
|
|
if ff.InGroup { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 6) |
|
|
|
|
} |
|
|
|
|
return flagBytes |
|
|
|
|
|
|
|
|
|
func v24FlagsToBytes(v24f FrameFlags) []byte { |
|
|
|
|
var flagBytes = []byte{0, 0} |
|
|
|
|
case V2_4: |
|
|
|
|
if ff.TagAlterPreservation { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 7) |
|
|
|
|
} |
|
|
|
|
if ff.FileAlterPreservation { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 6) |
|
|
|
|
} |
|
|
|
|
if ff.ReadOnly { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 5) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if v24f.TagAlterPreservation { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 7) |
|
|
|
|
} |
|
|
|
|
if v24f.FileAlterPreservation { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 6) |
|
|
|
|
} |
|
|
|
|
if v24f.ReadOnly { |
|
|
|
|
flagBytes[0] = util.SetBit(flagBytes[0], 5) |
|
|
|
|
} |
|
|
|
|
if ff.InGroup { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 7) |
|
|
|
|
} |
|
|
|
|
if ff.Compressed { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 4) |
|
|
|
|
} |
|
|
|
|
if ff.Encrypted { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 3) |
|
|
|
|
} |
|
|
|
|
if ff.Unsyrchronised { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 2) |
|
|
|
|
} |
|
|
|
|
if ff.HasDataLengthIndicator { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 1) |
|
|
|
|
} |
|
|
|
|
return flagBytes |
|
|
|
|
|
|
|
|
|
if v24f.InGroup { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 7) |
|
|
|
|
} |
|
|
|
|
if v24f.Compressed { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 4) |
|
|
|
|
default: |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
if v24f.Encrypted { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 3) |
|
|
|
|
} |
|
|
|
|
if v24f.Unsyrchronised { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 2) |
|
|
|
|
} |
|
|
|
|
if v24f.HasDataLengthIndicator { |
|
|
|
|
flagBytes[1] = util.SetBit(flagBytes[1], 1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return flagBytes |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Converts frame to ready-to-write bytes
|
|
|
|
@ -337,17 +341,13 @@ func (f *Frame) toBytes(version string) []byte {
|
|
|
|
|
buff.Write(util.IntToBytesSynchsafe(f.Header.Size)) |
|
|
|
|
|
|
|
|
|
// flags
|
|
|
|
|
var flagBytes []byte |
|
|
|
|
switch version { |
|
|
|
|
case V2_2: |
|
|
|
|
break |
|
|
|
|
case V2_3: |
|
|
|
|
flagBytes = v23FlagsToBytes(f.Header.Flags) |
|
|
|
|
buff.Write(flagBytes) |
|
|
|
|
case V2_4: |
|
|
|
|
flagBytes = v24FlagsToBytes(f.Header.Flags) |
|
|
|
|
flagBytes := frameFlagsToBytes(f.Header.Flags, version) |
|
|
|
|
if flagBytes != nil { |
|
|
|
|
buff.Write(flagBytes) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// contents
|
|
|
|
|
buff.Write(f.Contents) |
|
|
|
|
|
|
|
|
|
return buff.Bytes() |
|
|
|
|
} |
|
|
|
|