C# 体长

C# 体长,c#,audio,stream,bit-manipulation,flv,C#,Audio,Stream,Bit Manipulation,Flv,我正在制作自己的FLV音频下载程序,而不使用外部库。 我遵循以下文件: 在FLV标记类型中,有三个有趣的值: BodyLength、Timestamp、StreamId为uint24\u-be类型。如何阅读? 我在这里找到了答案: 但我不明白的是: 如果Timestamp和StreamId都是uint24\u be(也就是uint24\u be?)那么为什么呢 另外,ReadNext3Bytes到底做什么?为什么不读取下面3个字节,如下所示: reader.ReadInt32()+reade

我正在制作自己的FLV音频下载程序,而不使用外部库。 我遵循以下文件:

在FLV标记类型中,有三个有趣的值:

BodyLength、Timestamp、StreamId为
uint24\u-be
类型。如何阅读? 我在这里找到了答案:

但我不明白的是:

如果Timestamp和StreamId都是
uint24\u be
(也就是
uint24\u be
?)那么为什么呢

另外,
ReadNext3Bytes
到底做什么?为什么不读取下面3个字节,如下所示:

reader.ReadInt32()+reader.ReadInt32()+reader.ReadInt32();

您不能使用
reader.ReadInt32()+reader.ReadInt32()+reader.ReadInt32()
,因为一开始它是12个字节而不是3个字节,而第二次它还不够简单,总结这些字节-您应该创建一个24位的值。以下是更可读的
ReadNext3Bytes
函数版本:

int ReadNext3Bytes(System.IO.BinaryReader reader) {
    try {
        byte b0 = reader.ReadByte();
        byte b1 = reader.ReadByte();
        byte b2 = reader.ReadByte();
        return MakeInt(b0, b1, b2);
    }
    catch { return 0; }
}
int MakeInt(byte b0, byte b1, byte b2) {
    return ((b0 << 0x10) | (b1 << 0x08)) | b2;
}
int ReadNext3Bytes(System.IO.BinaryReader){
试一试{
字节b0=读取器.ReadByte();
字节b1=读取器.ReadByte();
字节b2=reader.ReadByte();
返回MakeInt(b0、b1、b2);
}
捕获{返回0;}
}
int MakeInt(字节b0、字节b1、字节b2){
返回((b0
int ReadNext3Bytes(System.IO.BinaryReader reader) {
    try {
        byte b0 = reader.ReadByte();
        byte b1 = reader.ReadByte();
        byte b2 = reader.ReadByte();
        return MakeInt(b0, b1, b2);
    }
    catch { return 0; }
}
int MakeInt(byte b0, byte b1, byte b2) {
    return ((b0 << 0x10) | (b1 << 0x08)) | b2;
}