encodeProperty method

List<int> encodeProperty({
  1. required String frameID,
  2. required MetadataProperty property,
  3. TagRestrictions? tagRestrictions,
  4. bool fillHeader = false,
  5. bool sizeH0 = true,
})

Encode the content corresponding to frameID. If you set fillHeader: true, the result is all frame frame Header + content bytes.

  • frameID: frame identifier
  • property: encode content, read from EncodeMetadataV2Body's properties
  • fillHeader: whether or not insert frame header in start of the output
  • tagRestrictions: use in v2.4, limit tag size, encoding, etc.
  • sizeH0: It only takes effect when fillHeader is true, indicating whether the high bit of the byte is 0, used to set the calculation method of size

Unless you know what you're encoding the property, don't actively call it

Implementation

List<int> encodeProperty(
    {required String frameID,
    required MetadataProperty property,
    TagRestrictions? tagRestrictions,
    bool fillHeader = false,
    bool sizeH0 = true}) {
  if (property.value == null || property.attached) return [];
  _ContentEncoder? encoder;
  if (frameID == 'TXXX') {
    encoder = _TXXXEncoder(frameID);
  } else if (frameID.startsWith('T')) {
    encoder = _TextInfomationEncoder(frameID);
  } else if (frameID == 'APIC') {
    encoder = _APICEncoder(frameID);
  }
  if (encoder != null) {
    property.attached = true;
    final contentBytes = encoder.encode(property.value, tagRestrictions);
    if (fillHeader) {
      List<int> output = [];
      // wrap frame header(10 bytes)
      final codec = ByteCodec();
      output.addAll(codec.encode(frameID, limitByteLength: 4));
      if (sizeH0) {
        output.addAll(ByteUtil.toH0Bytes(contentBytes.length));
      } else {
        output.addAll(ByteUtil.toH1Bytes(contentBytes.length));
      }
      output.addAll([0x00, 0x00]);
      return output + contentBytes;
    } else {
      return contentBytes;
    }
  }
  return [];
}