Port FrameHeader codec implementation from Java to Scala