@Override
    public void encode(DecodedInstruction insn, CodeOutput out) {
      PackedSwitchPayloadDecodedInstruction payload = (PackedSwitchPayloadDecodedInstruction) insn;
      int[] targets = payload.getTargets();
      int baseAddress = out.baseAddressForCursor();

      out.write(payload.getOpcodeUnit());
      out.write(asUnsignedUnit(targets.length));
      out.writeInt(payload.getFirstKey());

      for (int target : targets) {
        out.writeInt(target - baseAddress);
      }
    }
Representation of an instruction format, which knows how to decode into and encode from instances
of {@link DecodedInstruction}.
android/android_framework/dex-maker/src/main/java/com/android/dx/io/instructions/InstructionCodec.java